github.com/akamai/AkamaiOPEN-edgegrid-golang@v1.2.2/configgtm-v1_5/common.go (about) 1 package configgtm 2 3 import ( 4 "fmt" 5 "net/http" 6 ) 7 8 // 9 // Common data types and methods 10 // Based on 1.5 schemas 11 // 12 13 // Append url args to req 14 func appendReqArgs(req *http.Request, queryArgs map[string]string) { 15 16 // Look for optional args 17 if len(queryArgs) > 0 { 18 q := req.URL.Query() 19 for argName, argVal := range queryArgs { 20 q.Add(argName, argVal) 21 } 22 req.URL.RawQuery = q.Encode() 23 } 24 25 } 26 27 // default schema version 28 // TODO: retrieve from environment or elsewhere in Service Init 29 var schemaVersion string = "1.5" 30 31 // internal method to set version. passed in as string 32 func setVersionHeader(req *http.Request, version string) { 33 34 req.Header.Set("Accept", fmt.Sprintf("application/vnd.config-gtm.v%s+json", version)) 35 36 if req.Method != "GET" { 37 req.Header.Set("Content-Type", fmt.Sprintf("application/vnd.config-gtm.v%s+json", version)) 38 } 39 40 return 41 42 } 43 44 // response Status is returned on Create, Update or Delete operations for all entity types 45 type ResponseStatus struct { 46 ChangeId string `json:"changeId,omitempty"` 47 Links *[]Link `json:"links,omitempty"` 48 Message string `json:"message,omitempty"` 49 PassingValidation bool `json:"passingValidation,omitempty"` 50 PropagationStatus string `json:"propagationStatus,omitempty"` 51 PropagationStatusDate string `json:"propagationStatusDate,omitempty"` 52 } 53 54 // NewResponseStatus returns a new ResponseStatus struct 55 func NewResponseStatus() *ResponseStatus { 56 57 return &ResponseStatus{} 58 59 } 60 61 // Generic response structs 62 type ResponseBody struct { 63 Resource interface{} `json:"resource"` 64 Status *ResponseStatus `json:"status"` 65 } 66 67 // Response structs by Entity Type 68 type DomainResponse struct { 69 Resource *Domain `json:"resource"` 70 Status *ResponseStatus `json:"status"` 71 } 72 73 type DatacenterResponse struct { 74 Status *ResponseStatus `json:"status"` 75 Resource *Datacenter `json:"resource"` 76 } 77 78 type PropertyResponse struct { 79 Resource *Property `json:"resource"` 80 Status *ResponseStatus `json:"status"` 81 } 82 83 type ResourceResponse struct { 84 Resource *Resource `json:"resource"` 85 Status *ResponseStatus `json:"status"` 86 } 87 88 type CidrMapResponse struct { 89 Resource *CidrMap `json:"resource"` 90 Status *ResponseStatus `json:"status"` 91 } 92 93 type GeoMapResponse struct { 94 Resource *GeoMap `json:"resource"` 95 Status *ResponseStatus `json:"status"` 96 } 97 98 type AsMapResponse struct { 99 Resource *AsMap `json:"resource"` 100 Status *ResponseStatus `json:"status"` 101 } 102 103 // Probably THE most common type 104 type Link struct { 105 Rel string `json:"rel"` 106 Href string `json:"href"` 107 } 108 109 // 110 type LoadObject struct { 111 LoadObject string `json:"loadObject,omitempty"` 112 LoadObjectPort int `json:"loadObjectPort,omitempty"` 113 LoadServers []string `json:"loadServers,omitempty"` 114 } 115 116 // NewLoadObject returns a new LoadObject structure 117 func NewLoadObject() *LoadObject { 118 return &LoadObject{} 119 } 120 121 type DatacenterBase struct { 122 Nickname string `json:"nickname,omitempty"` 123 DatacenterId int `json:"datacenterId"` 124 } 125 126 // NewDatacenterBase returns a new DatacenterBase structure 127 func NewDatacenterBase() *DatacenterBase { 128 return &DatacenterBase{} 129 }