package codedeploydashboard /** * Generated by API Builder - https://www.apibuilder.io * Service version: 0.0.1-dev * User agent: apibuilder app.apibuilder.io/grhodes/code-deploy-dashboard/0.0.1-dev/go_1_5_client */ import ( "bytes" "encoding/json" "errors" "fmt" "io" "net/http" "strconv" ) const BaseUrl = "http://code-deploy-dashboard.tools.gilt.com" const UserAgent = "apibuilder app.apibuilder.io/grhodes/code-deploy-dashboard/0.0.1-dev/go_1_5_client" const Version = "0.0.1-dev" const VersionMajor = 0 type Client struct { HttpClient *http.Client Username string Password string BaseUrl string Headers http.Header } type Application struct { Name string `json:"name"` DeploymentGroups []DeploymentGroup `json:"deploymentGroups"` } func ApplicationFromMap(data interface{}) Application { b, err := json.Marshal(data) if err == nil { return ApplicationFromJson(bytes.NewReader(b)) } else { panic(err) } } func ApplicationFromJson(bytes io.Reader) Application { var application Application json.NewDecoder(bytes).Decode(&application) return application } type Deployment struct { Id string `json:"id"` Created string `json:"created"` Started string `json:"started"` Completed string `json:"completed"` Creator string `json:"creator"` DeploymentGroupName string `json:"deployment_group_name"` Failed int32 `json:"failed"` Skipped int32 `json:"skipped"` InProgress int32 `json:"in_progress"` Pending int32 `json:"pending"` Succeeded int32 `json:"succeeded"` Status string `json:"status"` ErrorMessage string `json:"error_message,omitempty"` RevisionLocation string `json:"revision_location"` Instances []DeploymentInstance `json:"instances"` } func DeploymentFromMap(data interface{}) Deployment { b, err := json.Marshal(data) if err == nil { return DeploymentFromJson(bytes.NewReader(b)) } else { panic(err) } } func DeploymentFromJson(bytes io.Reader) Deployment { var deployment Deployment json.NewDecoder(bytes).Decode(&deployment) return deployment } type DeploymentGroup struct { Name string `json:"name"` AutoScalingGroupNames []string `json:"autoScalingGroupNames"` } func DeploymentGroupFromMap(data interface{}) DeploymentGroup { b, err := json.Marshal(data) if err == nil { return DeploymentGroupFromJson(bytes.NewReader(b)) } else { panic(err) } } func DeploymentGroupFromJson(bytes io.Reader) DeploymentGroup { var deploymentGroup DeploymentGroup json.NewDecoder(bytes).Decode(&deploymentGroup) return deploymentGroup } type DeploymentInstance struct { Id string `json:"id"` Status string `json:"status"` LastUpdatedAt string `json:"last_updated_at"` LifecycleEvents []DeploymentLifecycleEvent `json:"lifecycle_events"` } func DeploymentInstanceFromMap(data interface{}) DeploymentInstance { b, err := json.Marshal(data) if err == nil { return DeploymentInstanceFromJson(bytes.NewReader(b)) } else { panic(err) } } func DeploymentInstanceFromJson(bytes io.Reader) DeploymentInstance { var deploymentInstance DeploymentInstance json.NewDecoder(bytes).Decode(&deploymentInstance) return deploymentInstance } type DeploymentLifecycleEvent struct { Name string `json:"name"` StartTime string `json:"start_time"` EndTime string `json:"end_time"` Status string `json:"status"` ErrorLogTail string `json:"error_log_tail,omitempty"` ErrorMessage string `json:"error_message,omitempty"` ScriptName string `json:"script_name,omitempty"` } func DeploymentLifecycleEventFromMap(data interface{}) DeploymentLifecycleEvent { b, err := json.Marshal(data) if err == nil { return DeploymentLifecycleEventFromJson(bytes.NewReader(b)) } else { panic(err) } } func DeploymentLifecycleEventFromJson(bytes io.Reader) DeploymentLifecycleEvent { var deploymentLifecycleEvent DeploymentLifecycleEvent json.NewDecoder(bytes).Decode(&deploymentLifecycleEvent) return deploymentLifecycleEvent } type Info struct { Name string `json:"name"` Version string `json:"version"` ScalaVersion string `json:"scala_version"` SbtVersion string `json:"sbt_version"` BuildTime string `json:"build_time"` } func InfoFromMap(data interface{}) Info { b, err := json.Marshal(data) if err == nil { return InfoFromJson(bytes.NewReader(b)) } else { panic(err) } } func InfoFromJson(bytes io.Reader) Info { var info Info json.NewDecoder(bytes).Decode(&info) return info } type ApplicationsGetResponse struct { StatusCode int Response *http.Response Error error Applications []Application } func ApplicationsGet(client Client) ApplicationsGetResponse { requestUrl := fmt.Sprintf("%s/application", client.BaseUrl) request, err := buildRequest(client, "GET", requestUrl) if err != nil { return ApplicationsGetResponse{Error: err} } resp, err := client.HttpClient.Do(request) if err != nil { return ApplicationsGetResponse{Error: err} } defer resp.Body.Close() switch resp.StatusCode { case 200: return ApplicationsGetResponse{StatusCode: resp.StatusCode, Response: resp, Applications: func() []Application { var tmp []interface{} json.NewDecoder(resp.Body).Decode(&tmp) var all []Application for _, el := range tmp { all = append(all, ApplicationFromMap(el)) } return all }()} default: return ApplicationsGetResponse{StatusCode: resp.StatusCode, Response: resp, Error: errors.New(resp.Status)} } } type InfoGetResponse struct { StatusCode int Response *http.Response Error error Info Info } func InfoGet(client Client) InfoGetResponse { requestUrl := fmt.Sprintf("%s/info", client.BaseUrl) request, err := buildRequest(client, "GET", requestUrl) if err != nil { return InfoGetResponse{Error: err} } resp, err := client.HttpClient.Do(request) if err != nil { return InfoGetResponse{Error: err} } defer resp.Body.Close() switch resp.StatusCode { case 200: return InfoGetResponse{StatusCode: resp.StatusCode, Response: resp, Info: InfoFromJson(resp.Body)} default: return InfoGetResponse{StatusCode: resp.StatusCode, Response: resp, Error: errors.New(resp.Status)} } } func buildRequest(client Client, method, urlStr string) (*http.Request, error) { request, err := http.NewRequest(method, urlStr, nil) if err != nil { return nil, err } request.Header.Add("User-Agent", UserAgent) request.Header.Add("X-Apidoc-Version", Version) request.Header.Add("X-Apidoc-Version-Major", strconv.Itoa(VersionMajor)) if client.Headers != nil { for key, values := range client.Headers { for _, value := range values { request.Header.Add(key, value) } } } if client.Username != "" { request.SetBasicAuth(client.Username, client.Password) } return request, nil }