MaxCDN Golang API.
import "gopkg.in/MaxCDN/go-maxcdn.v2"
Package maxcdn is the Golang bindings for MaxCDN's REST API.
Developer Notes:
- Custom types can be (somewhat) easily generated by using
maxcurl
(see: https://github.com/MaxCDN/maxcdn-tools/tree/master/maxcurl) to fetch the raw json output and thejson2struct
tool at http://json2struct.mervine.net/ to generate a sample struct. In the resulting struct, I recommend changing afloat64
types toint
types and replacing any resultinginterface{}
types withstring
types.
// Basic Get
max := maxcdn.NewMaxCDN(alias, token, secret)
var got maxcdn.Generic
res, err := max.Get(&got, "/account.json", nil)
if err != nil {
panic(err)
}
fmt.Printf("code: %d\n", res.Code)
fmt.Printf("name: %s\n", got["name"].(string))
// Basic Put
form := url.Values{}
form.Set("name", "new name")
var put maxcdn.Generic
if _, err = max.Put(&put, "/account.json", form); err == nil &&
put["name"].(string) == "new name" {
fmt.Println("name successfully updated")
}
// Basic Delete
if _, err = max.Delete("/zones/pull.json/123456", nil); err == nil {
fmt.Println("zone successfully deleted")
}
// Logs
if logs, err := max.GetLogs(nil); err == nil {
for _, line := range logs.Records {
fmt.Println("%+v\n", line)
}
}