ExampleUsage demonstrates how to use the reusable API package.
()
| 60 | |
| 61 | // ExampleUsage demonstrates how to use the reusable API package. |
| 62 | func ExampleUsage() { |
| 63 | // Create configuration |
| 64 | config := NewExampleConfig( |
| 65 | "https://proxmox.example.com:8006", |
| 66 | "root", |
| 67 | "password", |
| 68 | "pam", |
| 69 | true, // insecure |
| 70 | ) |
| 71 | |
| 72 | // Create logger |
| 73 | logger := &ExampleLogger{} |
| 74 | |
| 75 | // Create client with custom logger (cache will use NoOpCache by default) |
| 76 | client, err := NewClient(config, WithLogger(logger)) |
| 77 | if err != nil { |
| 78 | log.Fatalf("Failed to create client: %v", err) |
| 79 | } |
| 80 | |
| 81 | // Use the client |
| 82 | version, err := client.Version(context.Background()) |
| 83 | if err != nil { |
| 84 | log.Fatalf("Failed to get version: %v", err) |
| 85 | } |
| 86 | |
| 87 | logger.Info("Proxmox version: %.1f", version) |
| 88 | |
| 89 | // Get VM list |
| 90 | vms, err := client.GetVmList(context.Background()) |
| 91 | if err != nil { |
| 92 | log.Fatalf("Failed to get VMs: %v", err) |
| 93 | } |
| 94 | |
| 95 | logger.Info("Found %d VMs", len(vms)) |
| 96 | } |
nothing calls this directly
no test coverage detected