Skip to content

Latest commit

 

History

History
70 lines (54 loc) · 1.39 KB

digioceandns.md

File metadata and controls

70 lines (54 loc) · 1.39 KB

gocloud compute - DigitalOcean

Configure DigitalOcean credentials.

Create digioceancloudconfig.json in your HOME/.gocloud directory as follows:

{
  "DigiOceanAccessToken": "xxxxxxxxxxxx"
}

You can also set the credentials as environment variables:

export DigiOceanAccessToken =  "xxxxxxxxxxxx"

Initialize library

import "github.com/cloudlibz/gocloud/gocloud"

digioceancloud, _ := gocloud.CloudProvider(gocloud.Digioceanprovider)

Create DNS record

  create := map[string]interface{}{
    "DomainName": "example.com",
    "Type":       "A",
    "Name":       "www",
    "Data":       "162.10.66.0",
    "Priority":   nil,
    "Port":       nil,
    "TimeToLive": 1800,
    "Weight":     nil,
    "Flags":      nil,
    "Tag":        nil,
  }

 resp, err := digioceancloud.CreateDns(create)
 response := resp.(map[string]interface{})
 fmt.Println(response["body"])

Delete DNS record

  delete1 := map[string]string{
    "DomainName": "example.com",
    "RecordID":   "28448433",
  }

  resp, err := digioceancloud.DeleteDns(delete1)
  response := resp.(map[string]interface{})
  fmt.Println(response["body"])

List DNS records

  listRecords := map[string]string{
    "DomainName": "example.com",
  }

  resp, err := digioceancloud.ListDns(listRecords)
  response := resp.(map[string]interface{})
  fmt.Println(response["body"])