MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / main

Function main

examples/example_robust_client.go:17–94  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15)
16
17func main() {
18 log.Println("Testing Robust Client Setup example from DOCUMENTATION.md...")
19
20 // Load configuration with error handling
21 cfg := config.NewConfig()
22 cfg.ParseFlags()
23 cfg.SetDefaults()
24
25 // For testing purposes, set some required values if not provided
26 if cfg.Addr == "" {
27 cfg.Addr = "https://test.example.com:8006"
28 log.Println("Using test address:", cfg.Addr)
29 }
30 if cfg.User == "" {
31 cfg.User = "test@pam"
32 log.Println("Using test user:", cfg.User)
33 }
34 if cfg.Password == "" && cfg.TokenID == "" {
35 cfg.Password = "test-password"
36 log.Println("Using test password authentication")
37 }
38
39 if err := cfg.Validate(); err != nil {
40 log.Printf("Configuration validation failed: %v", err)
41 log.Println("Please check your configuration and try again.")
42 return
43 }
44 log.Println("Configuration validation passed ✓")
45
46 // Create logger with error handling
47 loggerInstance, err := logger.NewInternalLogger(logger.LevelInfo, cfg.CacheDir)
48 if err != nil {
49 log.Printf("Failed to create logger: %v", err)
50 log.Println("Falling back to simple logging...")
51 loggerInstance = logger.NewSimpleLogger(logger.LevelInfo)
52 }
53 defer loggerInstance.Close()
54 log.Println("Logger created successfully ✓")
55
56 // Create adapters
57 configAdapter := adapters.NewConfigAdapter(cfg)
58 loggerAdapter := adapters.NewLoggerAdapter(cfg)
59 log.Println("Adapters created successfully ✓")
60
61 // Create API client with error handling
62 client, err := api.NewClient(configAdapter,
63 api.WithLogger(loggerAdapter))
64 if err != nil {
65 log.Printf("Failed to create client: %v", err)
66 log.Println("Please check your Proxmox server address and credentials.")
67 log.Println("This is expected with test credentials ✓")
68 return
69 }
70
71 // Use the client with timeout
72 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
73 defer cancel()
74

Callers

nothing calls this directly

Calls 12

SetDefaultsMethod · 0.95
ValidateMethod · 0.95
GetVmListMethod · 0.95
NewConfigFunction · 0.92
NewInternalLoggerFunction · 0.92
NewSimpleLoggerFunction · 0.92
NewConfigAdapterFunction · 0.92
NewLoggerAdapterFunction · 0.92
NewClientFunction · 0.92
WithLoggerFunction · 0.92
SafeStringValueFunction · 0.92
CloseMethod · 0.65

Tested by

no test coverage detected