-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
43 lines (35 loc) · 1.03 KB
/
main.go
File metadata and controls
43 lines (35 loc) · 1.03 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
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/cachefly/cachefly-sdk-go/pkg/cachefly"
"github.com/joho/godotenv"
)
func main() {
// Load .env file (optional)
if err := godotenv.Load(); err != nil {
log.Printf("⚠️ Warning: unable to load .env file: %v", err)
}
// Ensure API token is set
token := os.Getenv("CACHEFLY_API_TOKEN")
if token == "" {
log.Fatal("❌ CACHEFLY_API_TOKEN environment variable is required")
}
// Read service ID argument
if len(os.Args) < 2 {
log.Fatalf("⚠️ Usage: go run main.go <service_id>")
}
serviceID := os.Args[1]
// Initialize CacheFly client
client := cachefly.NewClient(cachefly.WithToken(token))
// Fetch image optimization configuration
config, err := client.ServiceImageOptimization.GetConfiguration(context.Background(), serviceID)
if err != nil {
log.Fatalf("❌ Failed to fetch configuration for service %s: %v", serviceID, err)
}
// Print the raw configuration (YAML or JSON)
fmt.Println("\n✅ Configuration fetched successfully:")
fmt.Println(config)
}