mirror of
https://github.com/gfleury/go-bitbucket-v1.git
synced 2025-07-05 05:22:52 -05:00
Adding changes to abstract better
This commit is contained in:
@ -2,37 +2,52 @@
|
||||
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
|
||||
*/
|
||||
|
||||
package swagger
|
||||
package bitbucketv1
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// APIResponse contains generic data from API Response
|
||||
type APIResponse struct {
|
||||
*http.Response `json:"-"`
|
||||
Message string `json:"message,omitempty"`
|
||||
Message string `json:"message,omitempty"`
|
||||
// Operation is the name of the swagger operation.
|
||||
Operation string `json:"operation,omitempty"`
|
||||
Operation string `json:"operation,omitempty"`
|
||||
// RequestURL is the request URL. This value is always available, even if the
|
||||
// embedded *http.Response is nil.
|
||||
RequestURL string `json:"url,omitempty"`
|
||||
RequestURL string `json:"url,omitempty"`
|
||||
// Method is the HTTP method used for the request. This value is always
|
||||
// available, even if the embedded *http.Response is nil.
|
||||
Method string `json:"method,omitempty"`
|
||||
Method string `json:"method,omitempty"`
|
||||
// Payload holds the contents of the response body (which may be nil or empty).
|
||||
// This is provided here as the raw response.Body() reader will have already
|
||||
// been drained.
|
||||
Payload []byte `json:"-"`
|
||||
Values map[string]interface{}
|
||||
}
|
||||
|
||||
// NewAPIResponse create new APIResponse from http.Response
|
||||
func NewAPIResponse(r *http.Response) *APIResponse {
|
||||
|
||||
response := &APIResponse{Response: r}
|
||||
return response
|
||||
}
|
||||
|
||||
func NewAPIResponseWithError(errorMessage string) *APIResponse {
|
||||
// NewAPIResponseWithError create new erroneous API response from http.response and error
|
||||
func NewAPIResponseWithError(r *http.Response, err error) (*APIResponse, error) {
|
||||
|
||||
response := &APIResponse{Message: errorMessage}
|
||||
return response
|
||||
response := &APIResponse{Response: r, Message: err.Error()}
|
||||
return response, err
|
||||
}
|
||||
|
||||
// NewBitbucketAPIResponse create new API response from http.response
|
||||
func NewBitbucketAPIResponse(r *http.Response) (*APIResponse, error) {
|
||||
response := &APIResponse{Response: r}
|
||||
err := json.NewDecoder(r.Body).Decode(&response.Values)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user