package roadquality /** * Generated by API Builder - https://www.apibuilder.io * Service version: 0.0.13 * User agent: apibuilder app.apibuilder.io/trifectalabs/roadquality/0.0.13/go_1_5_client */ import ( "bytes" "encoding/json" "errors" "fmt" "html" "io" "io/ioutil" "net/http" "net/url" "strconv" "strings" ) const UserAgent = "apibuilder app.apibuilder.io/trifectalabs/roadquality/0.0.13/go_1_5_client" const Version = "0.0.13" const VersionMajor = 0 type Client struct { HttpClient *http.Client Username string Password string BaseUrl string Headers http.Header } type ClientRequestBody struct { contentType string bytes io.Reader } /** * The level of dedication of the segment to cycling */ type PathType string const ( PathTypeShared PathType = "shared" // A shared road for cars and bikes (road shoulder) PathTypeDedicatedLane = "dedicatedLane" // A dedicated bike lane on the road PathTypeBikePath = "bikePath" // A completely isolated bike lane (a natural barrier from road traffic) PathTypeUNDEFINED = "UNDEFINED" ) func PathTypeFromString(value string) PathType { switch strings.TrimSpace(strings.ToLower(value)) { case "shared": return PathTypeShared case "dedicatedlane": return PathTypeDedicatedLane case "bikepath": return PathTypeBikePath default: return PathTypeUNDEFINED } } /** * The surface type of a segment (road type) */ type SurfaceType string const ( SurfaceTypeGravel SurfaceType = "gravel" // Road consisting of small rocks SurfaceTypeAsphalt = "asphalt" // Road consisting of paved asphalt SurfaceTypeDirt = "dirt" // Road consisting of cleared dirt SurfaceTypeUNDEFINED = "UNDEFINED" ) func SurfaceTypeFromString(value string) SurfaceType { switch strings.TrimSpace(strings.ToLower(value)) { case "gravel": return SurfaceTypeGravel case "asphalt": return SurfaceTypeAsphalt case "dirt": return SurfaceTypeDirt default: return SurfaceTypeUNDEFINED } } /** * The type of user (user or admin) */ type UserRole string const ( UserRoleUser UserRole = "user" // A standard consumer of the service UserRoleAdmin = "admin" // An administrator of the application UserRoleUNDEFINED = "UNDEFINED" ) func UserRoleFromString(value string) UserRole { switch strings.TrimSpace(strings.ToLower(value)) { case "user": return UserRoleUser case "admin": return UserRoleAdmin default: return UserRoleUNDEFINED } } /** * A routable path on a map - not necessarily a segment */ type MapRoute struct { Polyline string `json:"polyline"` Distance float64 `json:"distance"` } func MapRouteFromMap(data interface{}) MapRoute { b, err := json.Marshal(data) if err == nil { return MapRouteFromJson(bytes.NewReader(b)) } else { panic(err) } } func MapRouteFromJson(bytes io.Reader) MapRoute { var mapRoute MapRoute json.NewDecoder(bytes).Decode(&mapRoute) return mapRoute } /** * A longitudinal or latitudinal coordatine */ type Point struct { Lat float64 `json:"lat"` Lng float64 `json:"lng"` } func PointFromMap(data interface{}) Point { b, err := json.Marshal(data) if err == nil { return PointFromJson(bytes.NewReader(b)) } else { panic(err) } } func PointFromJson(bytes io.Reader) Point { var point Point json.NewDecoder(bytes).Decode(&point) return point } /** * A segment of road which will be rated and tagged */ type Segment struct { Id string `json:"id"` Name string `json:"name,omitempty"` Description string `json:"description,omitempty"` Polyline string `json:"polyline"` CreatedBy string `json:"created_by"` Hidden string `json:"hidden"` } func SegmentFromMap(data interface{}) Segment { b, err := json.Marshal(data) if err == nil { return SegmentFromJson(bytes.NewReader(b)) } else { panic(err) } } func SegmentFromJson(bytes io.Reader) Segment { var segment Segment json.NewDecoder(bytes).Decode(&segment) return segment } /** * Form the client uses to create a segment */ type SegmentCreateForm struct { Name string `json:"name,omitempty"` Description string `json:"description,omitempty"` Polylines []string `json:"polylines"` SurfaceRating int32 `json:"surfaceRating"` TrafficRating int32 `json:"trafficRating"` SurfaceType SurfaceType `json:"surfaceType"` PathType PathType `json:"pathType"` } func SegmentCreateFormFromMap(data interface{}) SegmentCreateForm { b, err := json.Marshal(data) if err == nil { return SegmentCreateFormFromJson(bytes.NewReader(b)) } else { panic(err) } } func SegmentCreateFormFromJson(bytes io.Reader) SegmentCreateForm { var segmentCreateForm SegmentCreateForm json.NewDecoder(bytes).Decode(&segmentCreateForm) return segmentCreateForm } /** * A rating that is supplied with the segment */ type SegmentRating struct { Id string `json:"id"` SegmentId string `json:"segmentId"` UserId string `json:"userId"` TrafficRating int32 `json:"trafficRating"` SurfaceRating int32 `json:"surfaceRating"` SurfaceType SurfaceType `json:"surfaceType"` PathType PathType `json:"pathType"` CreatedAt string `json:"createdAt"` UpdatedAt string `json:"updatedAt"` DeletedAt string `json:"deletedAt,omitempty"` } func SegmentRatingFromMap(data interface{}) SegmentRating { b, err := json.Marshal(data) if err == nil { return SegmentRatingFromJson(bytes.NewReader(b)) } else { panic(err) } } func SegmentRatingFromJson(bytes io.Reader) SegmentRating { var segmentRating SegmentRating json.NewDecoder(bytes).Decode(&segmentRating) return segmentRating } /** * Form to modify an existing segment */ type SegmentUpdateForm struct { Name string `json:"name,omitempty"` Description string `json:"description,omitempty"` SurfaceRating int32 `json:"surfaceRating,omitempty"` TrafficRating int32 `json:"trafficRating,omitempty"` SurfaceType SurfaceType `json:"surfaceType,omitempty"` PathType PathType `json:"pathType,omitempty"` } func SegmentUpdateFormFromMap(data interface{}) SegmentUpdateForm { b, err := json.Marshal(data) if err == nil { return SegmentUpdateFormFromJson(bytes.NewReader(b)) } else { panic(err) } } func SegmentUpdateFormFromJson(bytes io.Reader) SegmentUpdateForm { var segmentUpdateForm SegmentUpdateForm json.NewDecoder(bytes).Decode(&segmentUpdateForm) return segmentUpdateForm } /** * A user of the service */ type User struct { Id string `json:"id"` FirstName string `json:"firstName"` LastName string `json:"lastName"` Email string `json:"email"` City string `json:"city,omitempty"` Province string `json:"province,omitempty"` Country string `json:"country,omitempty"` Birthdate string `json:"birthdate,omitempty"` Sex string `json:"sex,omitempty"` Role UserRole `json:"role"` StravaToken string `json:"stravaToken"` CreatedAt string `json:"createdAt"` UpdatedAt string `json:"updatedAt"` DeletedAt string `json:"deletedAt,omitempty"` } func UserFromMap(data interface{}) User { b, err := json.Marshal(data) if err == nil { return UserFromJson(bytes.NewReader(b)) } else { panic(err) } } func UserFromJson(bytes io.Reader) User { var user User json.NewDecoder(bytes).Decode(&user) return user } /** * A form to update attributes about a user */ type UserUpdateForm struct { Birthdate string `json:"birthdate,omitempty"` Sex string `json:"sex,omitempty"` } func UserUpdateFormFromMap(data interface{}) UserUpdateForm { b, err := json.Marshal(data) if err == nil { return UserUpdateFormFromJson(bytes.NewReader(b)) } else { panic(err) } } func UserUpdateFormFromJson(bytes io.Reader) UserUpdateForm { var userUpdateForm UserUpdateForm json.NewDecoder(bytes).Decode(&userUpdateForm) return userUpdateForm } type VersionInfo struct { Name string `json:"name"` Version string `json:"version"` ScalaVersion string `json:"scalaVersion"` SbtVersion string `json:"sbtVersion"` } func VersionInfoFromMap(data interface{}) VersionInfo { b, err := json.Marshal(data) if err == nil { return VersionInfoFromJson(bytes.NewReader(b)) } else { panic(err) } } func VersionInfoFromJson(bytes io.Reader) VersionInfo { var versionInfo VersionInfo json.NewDecoder(bytes).Decode(&versionInfo) return versionInfo } type MapRoutesGetSnapParams struct { Lat float64 Lng float64 } type MapRoutesGetSnapResponse struct { StatusCode int Response *http.Response Error error Point Point } func MapRoutesGetSnap(client Client, params MapRoutesGetSnapParams) MapRoutesGetSnapResponse { requestUrl := fmt.Sprintf("%s/mapRoutes/snap", client.BaseUrl) urlValues := url.Values{} if 0 != params.Lat { urlValues.Add("lat", strconv.FormatFloat(params.Lat, 'E', -1, 64)) } if 0 != params.Lng { urlValues.Add("lng", strconv.FormatFloat(params.Lng, 'E', -1, 64)) } encodedValues := urlValues.Encode() if encodedValues != "" { requestUrl += "?" + encodedValues } request, err := buildRequest(client, "GET", requestUrl, ClientRequestBody{}) if err != nil { return MapRoutesGetSnapResponse{Error: err} } resp, err := client.HttpClient.Do(request) if err != nil { return MapRoutesGetSnapResponse{Error: err} } defer resp.Body.Close() switch resp.StatusCode { case 200: return MapRoutesGetSnapResponse{StatusCode: resp.StatusCode, Response: resp, Point: PointFromJson(resp.Body)} default: return MapRoutesGetSnapResponse{StatusCode: resp.StatusCode, Response: resp, Error: errors.New(resp.Status)} } } type MapRoutesGetByPointsResponse struct { StatusCode int Response *http.Response Error error MapRoute MapRoute } func MapRoutesGetByPoints(client Client, points string) MapRoutesGetByPointsResponse { requestUrl := fmt.Sprintf("%s/mapRoutes/%s", client.BaseUrl, html.EscapeString(points)) request, err := buildRequest(client, "GET", requestUrl, ClientRequestBody{}) if err != nil { return MapRoutesGetByPointsResponse{Error: err} } resp, err := client.HttpClient.Do(request) if err != nil { return MapRoutesGetByPointsResponse{Error: err} } defer resp.Body.Close() switch resp.StatusCode { case 200: return MapRoutesGetByPointsResponse{StatusCode: resp.StatusCode, Response: resp, MapRoute: MapRouteFromJson(resp.Body)} default: return MapRoutesGetByPointsResponse{StatusCode: resp.StatusCode, Response: resp, Error: errors.New(resp.Status)} } } type SegmentsGetParams struct { SegmentId string } type SegmentsGetResponse struct { StatusCode int Response *http.Response Error error Segments []Segment } func SegmentsGet(client Client, params SegmentsGetParams) SegmentsGetResponse { requestUrl := fmt.Sprintf("%s/segments", client.BaseUrl) urlValues := url.Values{} if "" != params.SegmentId { urlValues.Add("segmentId", params.SegmentId) } encodedValues := urlValues.Encode() if encodedValues != "" { requestUrl += "?" + encodedValues } request, err := buildRequest(client, "GET", requestUrl, ClientRequestBody{}) if err != nil { return SegmentsGetResponse{Error: err} } resp, err := client.HttpClient.Do(request) if err != nil { return SegmentsGetResponse{Error: err} } defer resp.Body.Close() switch resp.StatusCode { case 200: return SegmentsGetResponse{StatusCode: resp.StatusCode, Response: resp, Segments: func() []Segment { var tmp []interface{} json.NewDecoder(resp.Body).Decode(&tmp) var all []Segment for _, el := range tmp { all = append(all, SegmentFromMap(el)) } return all }()} default: return SegmentsGetResponse{StatusCode: resp.StatusCode, Response: resp, Error: errors.New(resp.Status)} } } type SegmentsGetBoundingboxParams struct { Xmin float64 Ymin float64 Xmax float64 Ymax float64 } type SegmentsGetBoundingboxResponse struct { StatusCode int Response *http.Response Error error Segments []Segment Value string } func SegmentsGetBoundingbox(client Client, params SegmentsGetBoundingboxParams) SegmentsGetBoundingboxResponse { requestUrl := fmt.Sprintf("%s/segments/boundingbox", client.BaseUrl) urlValues := url.Values{} if 0 != params.Xmin { urlValues.Add("xmin", strconv.FormatFloat(params.Xmin, 'E', -1, 64)) } if 0 != params.Ymin { urlValues.Add("ymin", strconv.FormatFloat(params.Ymin, 'E', -1, 64)) } if 0 != params.Xmax { urlValues.Add("xmax", strconv.FormatFloat(params.Xmax, 'E', -1, 64)) } if 0 != params.Ymax { urlValues.Add("ymax", strconv.FormatFloat(params.Ymax, 'E', -1, 64)) } encodedValues := urlValues.Encode() if encodedValues != "" { requestUrl += "?" + encodedValues } request, err := buildRequest(client, "GET", requestUrl, ClientRequestBody{}) if err != nil { return SegmentsGetBoundingboxResponse{Error: err} } resp, err := client.HttpClient.Do(request) if err != nil { return SegmentsGetBoundingboxResponse{Error: err} } defer resp.Body.Close() switch resp.StatusCode { case 200: return SegmentsGetBoundingboxResponse{StatusCode: resp.StatusCode, Response: resp, Segments: func() []Segment { var tmp []interface{} json.NewDecoder(resp.Body).Decode(&tmp) var all []Segment for _, el := range tmp { all = append(all, SegmentFromMap(el)) } return all }()} case 404: return SegmentsGetBoundingboxResponse{StatusCode: resp.StatusCode, Response: resp, Value: func() string { body, _ := ioutil.ReadAll(resp.Body) return string(body) }()} default: return SegmentsGetBoundingboxResponse{StatusCode: resp.StatusCode, Response: resp, Error: errors.New(resp.Status)} } } type SegmentsPostParams struct { CurrentZoomLevel int32 Hidden string } type SegmentsPostResponse struct { StatusCode int Response *http.Response Error error Segment Segment Value string } func SegmentsPost(client Client, params SegmentsPostParams, segmentCreateForm SegmentCreateForm) SegmentsPostResponse { requestUrl := fmt.Sprintf("%s/segments", client.BaseUrl) bodyDocument, err := json.Marshal(segmentCreateForm) if err != nil { return SegmentsPostResponse{Error: err} } body := ClientRequestBody{contentType: "application/json", bytes: bytes.NewReader(bodyDocument)} urlValues := url.Values{} if 0 != params.CurrentZoomLevel { urlValues.Add("currentZoomLevel", strconv.FormatInt(params.CurrentZoomLevel, 10)) } if "" != params.Hidden { urlValues.Add("hidden", params.Hidden) } encodedValues := urlValues.Encode() if encodedValues != "" { requestUrl += "?" + encodedValues } request, err := buildRequest(client, "POST", requestUrl, body) if err != nil { return SegmentsPostResponse{Error: err} } resp, err := client.HttpClient.Do(request) if err != nil { return SegmentsPostResponse{Error: err} } defer resp.Body.Close() switch resp.StatusCode { case 201: return SegmentsPostResponse{StatusCode: resp.StatusCode, Response: resp, Segment: SegmentFromJson(resp.Body)} case 400: return SegmentsPostResponse{StatusCode: resp.StatusCode, Response: resp, Value: func() string { body, _ := ioutil.ReadAll(resp.Body) return string(body) }()} default: return SegmentsPostResponse{StatusCode: resp.StatusCode, Response: resp, Error: errors.New(resp.Status)} } } type SegmentsPutParams struct { SegmentId string } type SegmentsPutResponse struct { StatusCode int Response *http.Response Error error Segment Segment Value string } func SegmentsPut(client Client, params SegmentsPutParams, segmentUpdateForm SegmentUpdateForm) SegmentsPutResponse { requestUrl := fmt.Sprintf("%s/segments", client.BaseUrl) bodyDocument, err := json.Marshal(segmentUpdateForm) if err != nil { return SegmentsPutResponse{Error: err} } body := ClientRequestBody{contentType: "application/json", bytes: bytes.NewReader(bodyDocument)} urlValues := url.Values{} if "" != params.SegmentId { urlValues.Add("segmentId", params.SegmentId) } encodedValues := urlValues.Encode() if encodedValues != "" { requestUrl += "?" + encodedValues } request, err := buildRequest(client, "PUT", requestUrl, body) if err != nil { return SegmentsPutResponse{Error: err} } resp, err := client.HttpClient.Do(request) if err != nil { return SegmentsPutResponse{Error: err} } defer resp.Body.Close() switch resp.StatusCode { case 200: return SegmentsPutResponse{StatusCode: resp.StatusCode, Response: resp, Segment: SegmentFromJson(resp.Body)} case 400: return SegmentsPutResponse{StatusCode: resp.StatusCode, Response: resp, Value: func() string { body, _ := ioutil.ReadAll(resp.Body) return string(body) }()} case 404: return SegmentsPutResponse{StatusCode: resp.StatusCode, Response: resp, Value: func() string { body, _ := ioutil.ReadAll(resp.Body) return string(body) }()} default: return SegmentsPutResponse{StatusCode: resp.StatusCode, Response: resp, Error: errors.New(resp.Status)} } } type SegmentRatingsGetParams struct { Id string } type SegmentRatingsGetResponse struct { StatusCode int Response *http.Response Error error SegmentRating SegmentRating } func SegmentRatingsGet(client Client, params SegmentRatingsGetParams) SegmentRatingsGetResponse { requestUrl := fmt.Sprintf("%s/segmentRatings", client.BaseUrl) urlValues := url.Values{} if "" != params.Id { urlValues.Add("id", params.Id) } encodedValues := urlValues.Encode() if encodedValues != "" { requestUrl += "?" + encodedValues } request, err := buildRequest(client, "GET", requestUrl, ClientRequestBody{}) if err != nil { return SegmentRatingsGetResponse{Error: err} } resp, err := client.HttpClient.Do(request) if err != nil { return SegmentRatingsGetResponse{Error: err} } defer resp.Body.Close() switch resp.StatusCode { case 200: return SegmentRatingsGetResponse{StatusCode: resp.StatusCode, Response: resp, SegmentRating: SegmentRatingFromJson(resp.Body)} default: return SegmentRatingsGetResponse{StatusCode: resp.StatusCode, Response: resp, Error: errors.New(resp.Status)} } } type SegmentRatingsPostParams struct { Id string CurrentZoomLevel int32 } type SegmentRatingsPostResponse struct { StatusCode int Response *http.Response Error error Segment Segment Value string } func SegmentRatingsPost(client Client, params SegmentRatingsPostParams, segmentCreateForm SegmentCreateForm) SegmentRatingsPostResponse { requestUrl := fmt.Sprintf("%s/segmentRatings", client.BaseUrl) bodyDocument, err := json.Marshal(segmentCreateForm) if err != nil { return SegmentRatingsPostResponse{Error: err} } body := ClientRequestBody{contentType: "application/json", bytes: bytes.NewReader(bodyDocument)} urlValues := url.Values{} if "" != params.Id { urlValues.Add("id", params.Id) } if 0 != params.CurrentZoomLevel { urlValues.Add("currentZoomLevel", strconv.FormatInt(params.CurrentZoomLevel, 10)) } encodedValues := urlValues.Encode() if encodedValues != "" { requestUrl += "?" + encodedValues } request, err := buildRequest(client, "POST", requestUrl, body) if err != nil { return SegmentRatingsPostResponse{Error: err} } resp, err := client.HttpClient.Do(request) if err != nil { return SegmentRatingsPostResponse{Error: err} } defer resp.Body.Close() switch resp.StatusCode { case 201: return SegmentRatingsPostResponse{StatusCode: resp.StatusCode, Response: resp, Segment: SegmentFromJson(resp.Body)} case 400: return SegmentRatingsPostResponse{StatusCode: resp.StatusCode, Response: resp, Value: func() string { body, _ := ioutil.ReadAll(resp.Body) return string(body) }()} default: return SegmentRatingsPostResponse{StatusCode: resp.StatusCode, Response: resp, Error: errors.New(resp.Status)} } } type SegmentRatingsDeleteParams struct { Id string } type SegmentRatingsDeleteResponse struct { StatusCode int Response *http.Response Error error Value string } func SegmentRatingsDelete(client Client, params SegmentRatingsDeleteParams) SegmentRatingsDeleteResponse { requestUrl := fmt.Sprintf("%s/segmentRatings", client.BaseUrl) urlValues := url.Values{} if "" != params.Id { urlValues.Add("id", params.Id) } encodedValues := urlValues.Encode() if encodedValues != "" { requestUrl += "?" + encodedValues } request, err := buildRequest(client, "DELETE", requestUrl, ClientRequestBody{}) if err != nil { return SegmentRatingsDeleteResponse{Error: err} } resp, err := client.HttpClient.Do(request) if err != nil { return SegmentRatingsDeleteResponse{Error: err} } defer resp.Body.Close() switch resp.StatusCode { case 202: return SegmentRatingsDeleteResponse{StatusCode: resp.StatusCode, Response: resp, Value: string(resp.Body)} case 404: return SegmentRatingsDeleteResponse{StatusCode: resp.StatusCode, Response: resp, Value: func() string { body, _ := ioutil.ReadAll(resp.Body) return string(body) }()} default: return SegmentRatingsDeleteResponse{StatusCode: resp.StatusCode, Response: resp, Error: errors.New(resp.Status)} } } type UsersGetResponse struct { StatusCode int Response *http.Response Error error Users []User Value string } func UsersGet(client Client) UsersGetResponse { requestUrl := fmt.Sprintf("%s/users", client.BaseUrl) request, err := buildRequest(client, "GET", requestUrl, ClientRequestBody{}) if err != nil { return UsersGetResponse{Error: err} } resp, err := client.HttpClient.Do(request) if err != nil { return UsersGetResponse{Error: err} } defer resp.Body.Close() switch resp.StatusCode { case 200: return UsersGetResponse{StatusCode: resp.StatusCode, Response: resp, Users: func() []User { var tmp []interface{} json.NewDecoder(resp.Body).Decode(&tmp) var all []User for _, el := range tmp { all = append(all, UserFromMap(el)) } return all }()} case 401: return UsersGetResponse{StatusCode: resp.StatusCode, Response: resp, Value: func() string { body, _ := ioutil.ReadAll(resp.Body) return string(body) }()} default: return UsersGetResponse{StatusCode: resp.StatusCode, Response: resp, Error: errors.New(resp.Status)} } } type UsersPutParams struct { UserId string } type UsersPutResponse struct { StatusCode int Response *http.Response Error error User User Value string } func UsersPut(client Client, params UsersPutParams, userUpdateForm UserUpdateForm) UsersPutResponse { requestUrl := fmt.Sprintf("%s/users", client.BaseUrl) bodyDocument, err := json.Marshal(userUpdateForm) if err != nil { return UsersPutResponse{Error: err} } body := ClientRequestBody{contentType: "application/json", bytes: bytes.NewReader(bodyDocument)} urlValues := url.Values{} if "" != params.UserId { urlValues.Add("userId", params.UserId) } encodedValues := urlValues.Encode() if encodedValues != "" { requestUrl += "?" + encodedValues } request, err := buildRequest(client, "PUT", requestUrl, body) if err != nil { return UsersPutResponse{Error: err} } resp, err := client.HttpClient.Do(request) if err != nil { return UsersPutResponse{Error: err} } defer resp.Body.Close() switch resp.StatusCode { case 202: return UsersPutResponse{StatusCode: resp.StatusCode, Response: resp, User: UserFromJson(resp.Body)} case 404: return UsersPutResponse{StatusCode: resp.StatusCode, Response: resp, Value: func() string { body, _ := ioutil.ReadAll(resp.Body) return string(body) }()} default: return UsersPutResponse{StatusCode: resp.StatusCode, Response: resp, Error: errors.New(resp.Status)} } } type UsersDeleteParams struct { UserId string } type UsersDeleteResponse struct { StatusCode int Response *http.Response Error error User User Value string } func UsersDelete(client Client, params UsersDeleteParams) UsersDeleteResponse { requestUrl := fmt.Sprintf("%s/users", client.BaseUrl) urlValues := url.Values{} if "" != params.UserId { urlValues.Add("userId", params.UserId) } encodedValues := urlValues.Encode() if encodedValues != "" { requestUrl += "?" + encodedValues } request, err := buildRequest(client, "DELETE", requestUrl, ClientRequestBody{}) if err != nil { return UsersDeleteResponse{Error: err} } resp, err := client.HttpClient.Do(request) if err != nil { return UsersDeleteResponse{Error: err} } defer resp.Body.Close() switch resp.StatusCode { case 202: return UsersDeleteResponse{StatusCode: resp.StatusCode, Response: resp, User: UserFromJson(resp.Body)} case 404: return UsersDeleteResponse{StatusCode: resp.StatusCode, Response: resp, Value: func() string { body, _ := ioutil.ReadAll(resp.Body) return string(body) }()} default: return UsersDeleteResponse{StatusCode: resp.StatusCode, Response: resp, Error: errors.New(resp.Status)} } } type InfoGetResponse struct { StatusCode int Response *http.Response Error error VersionInfo VersionInfo } func InfoGet(client Client) InfoGetResponse { requestUrl := fmt.Sprintf("%s/info", client.BaseUrl) request, err := buildRequest(client, "GET", requestUrl, ClientRequestBody{}) 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, VersionInfo: VersionInfoFromJson(resp.Body)} default: return InfoGetResponse{StatusCode: resp.StatusCode, Response: resp, Error: errors.New(resp.Status)} } } func buildRequest(client Client, method, urlStr string, body ClientRequestBody) (*http.Request, error) { request, err := http.NewRequest(method, urlStr, body.bytes) 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 body.contentType != "" { request.Header.Add("Content-Type", body.contentType) } if client.Username != "" { request.SetBasicAuth(client.Username, client.Password) } return request, nil }