-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
63 lines (52 loc) · 1.3 KB
/
main.go
File metadata and controls
63 lines (52 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Example demonstrates activating a CacheFly service.
//
// This example shows:
// - Client initialization with API token
// - Activating a service by ID
// - Error handling and response formatting
//
// Usage:
//
// export CACHEFLY_API_TOKEN="your-token"
// go run main.go <service_id>
//
// Example:
//
// go run main.go srv_123456789
package main
import (
"context"
"encoding/json"
"fmt"
"log"
"os"
"github.com/cachefly/cachefly-sdk-go/pkg/cachefly"
"github.com/joho/godotenv"
)
func main() {
if err := godotenv.Load(); err != nil {
log.Printf("⚠️ Warning: unable to load .env file: %v", err)
}
token := os.Getenv("CACHEFLY_API_TOKEN")
if token == "" {
log.Fatal("❌ CACHEFLY_API_TOKEN environment variable is required")
}
if len(os.Args) < 2 {
log.Println("⚠️ Usage: go run main.go <service_id>")
return
}
serviceID := os.Args[1]
client := cachefly.NewClient(
cachefly.WithToken(token),
)
resp, err := client.Services.ActivateServiceByID(context.Background(), serviceID)
if err != nil {
log.Fatalf("❌ Failed to activate service: %v", err)
}
dataJSON, err := json.MarshalIndent(resp, "", " ")
if err != nil {
log.Fatalf("Error formatting MarshalIndent [account]: %v", err)
}
fmt.Println("\n ✅ Service activated successfully.")
fmt.Println(string(dataJSON))
}