Create digioceancloudconfig.json
in your HOME/.gocloud directory as follows:
{
"DigiOceanAccessToken": "xxxxxxxxxxxx"
}
You can also set the credentials as environment variables:
export DigiOceanAccessToken = "xxxxxxxxxxxx"
import "github.com/cloudlibz/gocloud/gocloud"
digioceancloud, _ := gocloud.CloudProvider(gocloud.Digioceanprovider)
forwardingrules := []map[string]interface{}{
{
"EntryProtocol": "https",
"EntryPort": 444,
"TargetProtocol": "https",
"TargetPort": 443,
"TLSPassthrough": true,
},
}
healthcheck := map[string]interface{}{
"Protocol": "http",
"Port": 80,
"Path": "/",
"CheckIntervalSeconds": 10,
"ResponseTimeoutSeconds": 5,
"HealthyThreshold": 5,
"UnhealthyThreshold": 3,
}
stickysessions := map[string]interface{}{
"Type": "none",
}
create := map[string]interface{}{
"Name": "example-01",
"Algorithm": "round_robin",
"Region": "nyc3",
"ForwardingRules": forwardingrules,
"HealthCheck": healthcheck,
"StickySessions": stickysessions,
"DropletIDs": []int{3164444, 3164445},
"Tag": nil,
"RedirectHTTPToHTTPS": false,
}
resp, err := digioceancloud.CreateLoadBalancer(create)
response := resp.(map[string]interface{})
fmt.Println(response["body"])
delete1 := map[string]string{
"ID": "86407564",
}
resp, err := digioceancloud.DeleteLoadBalancer(delete1)
response := resp.(map[string]interface{})
fmt.Println(response["body"])
attachnodewithloadbalancer := map[string]interface{}{
"LoadBalancerID": "my-load-balancer",
"DropletIDs": []int{31331, 31313},
}
resp, err := digioceancloud.AttachNodeWithLoadBalancer(attachnodewithloadbalancer)
response := resp.(map[string]interface{})
fmt.Println(response["body"])
detachnodewithloadbalancer := map[string]interface{}{
"LoadBalancerID": "my-load-balancer",
"DropletIDs": []int{31331, 31313},
}
resp, err := digioceancloud.DetachNodeWithLoadBalancer(detachnodewithloadbalancer)
response := resp.(map[string]interface{})
fmt.Println(response["body"])
resp, err := digioceancloud.ListLoadBalancer(nil)
response := resp.(map[string]interface{})
fmt.Println(response["body"])