github.com/Finnhub-Stock-API/finnhub-go@v1.2.1/response.go (about)

     1  /*
     2   * Finnhub API
     3   *
     4   * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
     5   *
     6   * API version: 1.0.0
     7   * Generated by: OpenAPI Generator (https://openapi-generator.tech)
     8   */
     9  
    10  package finnhub
    11  
    12  import (
    13  	"net/http"
    14  )
    15  
    16  // APIResponse stores the API response returned by the server.
    17  type APIResponse struct {
    18  	*http.Response `json:"-"`
    19  	Message        string `json:"message,omitempty"`
    20  	// Operation is the name of the OpenAPI operation.
    21  	Operation string `json:"operation,omitempty"`
    22  	// RequestURL is the request URL. This value is always available, even if the
    23  	// embedded *http.Response is nil.
    24  	RequestURL string `json:"url,omitempty"`
    25  	// Method is the HTTP method used for the request.  This value is always
    26  	// available, even if the embedded *http.Response is nil.
    27  	Method string `json:"method,omitempty"`
    28  	// Payload holds the contents of the response body (which may be nil or empty).
    29  	// This is provided here as the raw response.Body() reader will have already
    30  	// been drained.
    31  	Payload []byte `json:"-"`
    32  }
    33  
    34  // NewAPIResponse returns a new APIResonse object.
    35  func NewAPIResponse(r *http.Response) *APIResponse {
    36  
    37  	response := &APIResponse{Response: r}
    38  	return response
    39  }
    40  
    41  // NewAPIResponseWithError returns a new APIResponse object with the provided error message.
    42  func NewAPIResponseWithError(errorMessage string) *APIResponse {
    43  
    44  	response := &APIResponse{Message: errorMessage}
    45  	return response
    46  }