/
get_account_example.go
66 lines (54 loc) · 1.48 KB
/
get_account_example.go
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
64
65
66
package main
import (
"log"
slapi "github.com/sudorandom/softlayer-go/slapi"
types "github.com/sudorandom/softlayer-go/slapi/types"
)
func main() {
client := slapi.Client{
Endpoint: "https://api.softlayer.com/rest/v3.1/",
Username: "INSERT_USERNAME",
APIKey: "INSERT_API_KEY",
}
makeBasicAPICall(client)
makeCustomAPICall(client)
}
// makeBasicAPICall demonstrates using a basic type
func makeBasicAPICall(client slapi.Client) {
req := slapi.Request{
Service: "SoftLayer_Account",
Method: "getObject",
Mask: `mask[id,companyName]`,
}
// Make API call with basic account type
basicAccount := &types.SoftLayer_Account{}
err := client.Call(req, basicAccount)
if err != nil {
log.Fatal(err)
}
log.Println("Basic:")
log.Println(basicAccount.Id)
log.Println(basicAccount.CompanyName)
}
type CustomAccount struct {
types.SoftLayer_Account
VirtualGuests []*types.SoftLayer_Virtual_Guest `json:"virtualGuests"`
}
// makeCustomAPICall demonstrates using a user-defined type
func makeCustomAPICall(client slapi.Client) {
req := slapi.Request{
Service: "SoftLayer_Account",
Method: "getObject",
Mask: `mask[id,virtualGuests,companyName]`,
}
// Make API call with custom type based on the basic account type
customAccount := &CustomAccount{}
err := client.Call(req, customAccount)
if err != nil {
log.Fatal(err)
}
log.Println("Custom Extended:")
log.Println(customAccount.Id)
log.Println(customAccount.CompanyName)
log.Println(customAccount.VirtualGuests)
}