Download your service account credentials file from Google Cloud and save it as googlecloudinfo.json
in your HOME/.gocloud directory.
You can also set the credentials as environment variables:
export PrivateKey = "xxxxxxxxxxxx"
export Type = "xxxxxxxxxxxx"
export ProjectID = "xxxxxxxxxxxx"
export PrivateKeyID = "xxxxxxxxxxxx"
export ClientEmail = "xxxxxxxxxxxx"
export ClientID = "xxxxxxxxxxxx"
export AuthURI = "xxxxxxxxxxxx"
export TokenURI = "xxxxxxxxxxxx"
export AuthProviderX509CertURL = "xxxxxxxxxxxx"
export ClientX509CertURL = "xxxxxxxxxxxx"
import "github.com/cloudlibz/gocloud/gocloud"
googlecloud, _ := gocloud.CloudProvider(gocloud.Googleprovider)
createdisk := map[string]interface{}{
"projectid": "sheltermap-1493101612061",
"Name": "disk-11",
"Type": "pd-standard",
"Zone": "us-east4-c",
}
resp, err := googlecloud.CreateDisk(createdisk)
response := resp.(map[string]interface{})
fmt.Println(response["body"])
attachdisk := map[string]string{
"projectid": "sheltermap-1493101612061",
"instance": "testing-scorelab",
"Zone": "us-east4-c",
"deviceName": "projects/sheltermap-1493101612061/zones/us-east4-c/disks/disk-12",
}
resp, err := googlecloud.AttachDisk(attachdisk)
response := resp.(map[string]interface{})
fmt.Println(response["body"])
deletedisk := map[string]string{
"VolumeId": "vol-05371175f10d2e6a4",
}
resp, err := googlecloud.DeleteDisk(deletedisk)
response := resp.(map[string]interface{})
fmt.Println(response["body"])
detachdisk := map[string]string{
"projectid": "sheltermap-1493101612061",
"instance": "testing-scorelab",
"Zone": "us-east4-c",
"deviceName": "projects/sheltermap-1493101612061/zones/us-east4-c/disks/disk-12",
}
resp, err := googlecloud.DetachDisk(detachdisk)
response := resp.(map[string]interface{})
fmt.Println(response["body"])
createsnapshot := map[string]interface{}{
"projectid": "sheltermap-1493101612061",
"disk": "disk-11",
"Zone": "us-east4-c",
"Name": "disk-12",
}
resp, err := googlecloud.CreateSnapshot(createsnapshot)
response := resp.(map[string]interface{})
fmt.Println(response["body"])
deletesnapshot := map[string]string{
"projectid": "sheltermap-1493101612061",
"snapshot": "disk-12",
}
resp, err := googlecloud.DeleteSnapshot(deletesnapshot)
response := resp.(map[string]interface{})
fmt.Println(response["body"])