-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
40 lines (30 loc) · 818 Bytes
/
main.go
File metadata and controls
40 lines (30 loc) · 818 Bytes
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
package main
import (
"context"
"fmt"
"os"
"time"
slicer "github.com/slicervm/sdk"
)
func main() {
baseURL := os.Getenv("SLICER_URL")
token := os.Getenv("SLICER_TOKEN")
if baseURL == "" {
fmt.Println("SLICER_URL is required")
os.Exit(1)
}
if token == "" {
fmt.Println("SLICER_TOKEN is required")
os.Exit(1)
}
client := slicer.NewSlicerClient(baseURL, token, "slicer-sdk-go-example/1.0", nil)
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()
req := slicer.SlicerCreateNodeRequest{}
resp, err := client.CreateVM(ctx, "vm", req)
if err != nil {
fmt.Printf("create vm failed: %v\n", err)
os.Exit(1)
}
fmt.Printf("Created VM: hostname=%s ip=%s created_at=%s arch=%s\n", resp.Hostname, resp.IP, resp.CreatedAt.Format(time.RFC3339), resp.Arch)
}