github.com/akamai/AkamaiOPEN-edgegrid-golang/v2@v2.17.0/pkg/configgtm/common.go (about)

     1  package gtm
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  )
     7  
     8  //
     9  // Common data types and methods
    10  // Based on 1.3 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 = "1.4"
    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  // NewDefaultDatacenter instantiates new Default Datacenter Struct
    45  func (p *gtm) NewDefaultDatacenter(dcid int) *DatacenterBase {
    46  	return &DatacenterBase{DatacenterId: dcid}
    47  }
    48  
    49  // ResponseStatus is returned on Create, Update or Delete operations for all entity types
    50  type ResponseStatus struct {
    51  	ChangeId              string  `json:"changeId,omitempty"`
    52  	Links                 *[]Link `json:"links,omitempty"`
    53  	Message               string  `json:"message,omitempty"`
    54  	PassingValidation     bool    `json:"passingValidation,omitempty"`
    55  	PropagationStatus     string  `json:"propagationStatus,omitempty"`
    56  	PropagationStatusDate string  `json:"propagationStatusDate,omitempty"`
    57  }
    58  
    59  // NewResponseStatus returns a new ResponseStatus struct
    60  func NewResponseStatus() *ResponseStatus {
    61  
    62  	return &ResponseStatus{}
    63  
    64  }
    65  
    66  // ResponseBody is a generic response struct
    67  type ResponseBody struct {
    68  	Resource interface{}     `json:"resource"`
    69  	Status   *ResponseStatus `json:"status"`
    70  }
    71  
    72  // DomainResponse contains a response after creating or updating Domain
    73  type DomainResponse struct {
    74  	Resource *Domain         `json:"resource"`
    75  	Status   *ResponseStatus `json:"status"`
    76  }
    77  
    78  // DatacenterResponse contains a response after creating or updating Datacenter
    79  type DatacenterResponse struct {
    80  	Status   *ResponseStatus `json:"status"`
    81  	Resource *Datacenter     `json:"resource"`
    82  }
    83  
    84  // PropertyResponse contains a response after creating or updating Property
    85  type PropertyResponse struct {
    86  	Resource *Property       `json:"resource"`
    87  	Status   *ResponseStatus `json:"status"`
    88  }
    89  
    90  // ResourceResponse contains a response after creating or updating Resource
    91  type ResourceResponse struct {
    92  	Resource *Resource       `json:"resource"`
    93  	Status   *ResponseStatus `json:"status"`
    94  }
    95  
    96  // CidrMapResponse contains a response after creating or updating CidrMap
    97  type CidrMapResponse struct {
    98  	Resource *CidrMap        `json:"resource"`
    99  	Status   *ResponseStatus `json:"status"`
   100  }
   101  
   102  // GeoMapResponse contains a response after creating or updating GeoMap
   103  type GeoMapResponse struct {
   104  	Resource *GeoMap         `json:"resource"`
   105  	Status   *ResponseStatus `json:"status"`
   106  }
   107  
   108  // AsMapResponse contains a response after creating or updating AsMap
   109  type AsMapResponse struct {
   110  	Resource *AsMap          `json:"resource"`
   111  	Status   *ResponseStatus `json:"status"`
   112  }
   113  
   114  // Link is Probably THE most common type
   115  type Link struct {
   116  	Rel  string `json:"rel"`
   117  	Href string `json:"href"`
   118  }
   119  
   120  // LoadObject contains information about the load reporting interface
   121  type LoadObject struct {
   122  	LoadObject     string   `json:"loadObject,omitempty"`
   123  	LoadObjectPort int      `json:"loadObjectPort,omitempty"`
   124  	LoadServers    []string `json:"loadServers,omitempty"`
   125  }
   126  
   127  // NewLoadObject returns a new LoadObject structure
   128  func NewLoadObject() *LoadObject {
   129  	return &LoadObject{}
   130  }
   131  
   132  // DatacenterBase is a placeholder for default Datacenter
   133  type DatacenterBase struct {
   134  	Nickname     string `json:"nickname,omitempty"`
   135  	DatacenterId int    `json:"datacenterId"`
   136  }
   137  
   138  // NewDatacenterBase returns a new DatacenterBase structure
   139  func NewDatacenterBase() *DatacenterBase {
   140  	return &DatacenterBase{}
   141  }