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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
package configgtm
import (
"fmt"
"net/http"
)
//
// Common data types and methods
// Based on 1.3 schemas
//
// Append url args to req
func appendReqArgs(req *http.Request, queryArgs map[string]string) {
// Look for optional args
if len(queryArgs) > 0 {
q := req.URL.Query()
for argName, argVal := range queryArgs {
q.Add(argName, argVal)
}
req.URL.RawQuery = q.Encode()
}
}
// default schema version
// TODO: retrieve from environment or elsewhere in Service Init
var schemaVersion string = "1.3"
// internal method to set version. passed in as string
func setVersionHeader(req *http.Request, version string) {
req.Header.Set("Accept", fmt.Sprintf("application/vnd.config-gtm.v%s+json", version))
if req.Method != "GET" {
req.Header.Set("Content-Type", fmt.Sprintf("application/vnd.config-gtm.v%s+json", version))
}
return
}
// response Status is returned on Create, Update or Delete operations for all entity types
type ResponseStatus struct {
ChangeId string `json:"changeId,omitempty"`
Links *[]Link `json:"links,omitempty"`
Message string `json:"message,omitempty"`
PassingValidation bool `json:"passingValidation,omitempty"`
PropagationStatus string `json:"propagationStatus,omitempty"`
PropagationStatusDate string `json:"propagationStatusDate,omitempty"`
}
// NewResponseStatus returns a new ResponseStatus struct
func NewResponseStatus() *ResponseStatus {
return &ResponseStatus{}
}
// Generic response structs
type ResponseBody struct {
Resource interface{} `json:"resource"`
Status *ResponseStatus `json:"status"`
}
// Response structs by Entity Type
type DomainResponse struct {
Resource *Domain `json:"resource"`
Status *ResponseStatus `json:"status"`
}
type DatacenterResponse struct {
Status *ResponseStatus `json:"status"`
Resource *Datacenter `json:"resource"`
}
type PropertyResponse struct {
Resource *Property `json:"resource"`
Status *ResponseStatus `json:"status"`
}
type ResourceResponse struct {
Resource *Resource `json:"resource"`
Status *ResponseStatus `json:"status"`
}
type CidrMapResponse struct {
Resource *CidrMap `json:"resource"`
Status *ResponseStatus `json:"status"`
}
type GeoMapResponse struct {
Resource *GeoMap `json:"resource"`
Status *ResponseStatus `json:"status"`
}
type AsMapResponse struct {
Resource *AsMap `json:"resource"`
Status *ResponseStatus `json:"status"`
}
// Probably THE most common type
type Link struct {
Rel string `json:"rel"`
Href string `json:"href"`
}
//
type LoadObject struct {
LoadObject string `json:"loadObject,omitempty"`
LoadObjectPort int `json:"loadObjectPort,omitempty"`
LoadServers []string `json:"loadServers,omitempty"`
}
// NewLoadObject returns a new LoadObject structure
func NewLoadObject() *LoadObject {
return &LoadObject{}
}
type DatacenterBase struct {
Nickname string `json:"nickname"`
DatacenterId int `json:"datacenterId"`
}
// NewDatacenterBase returns a new DatacenterBase structure
func NewDatacenterBase() *DatacenterBase {
return &DatacenterBase{}
}
|