Documentation ¶
Index ¶
- func CheckForErrors(resp *http.Response) ([]byte, error)
- func GetImageBase64(endpoint, filename, id string) (string, error)
- func GetURLQueryParams(s string) (url.Values, error)
- func JSONResponse(w http.ResponseWriter, bs []byte) error
- func Logger() *zap.SugaredLogger
- func NewHTTPError(err error, status int, detail string) error
- func SendGETRequest(endpoint string, target interface{}) ([]byte, error)
- func SendPOSTRequest(endpoint string, formValues map[string]string, target interface{}) ([]byte, error)
- type ClientError
- type HTTPClient
- type HTTPError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckForErrors ¶
CheckForErrors reads the entire response body and checks the status code of the response. If the status code is not 200, a error is returned. Otherwise, the response body is returned.
func GetImageBase64 ¶
GetImageBase64 implements read-through caching in which the image's base64 string is retrieved from the cache first or the network if not found in the cache.
func GetURLQueryParams ¶
GetURLQueryParams extracts the query parameters from a url string and returns a map of strings.
func JSONResponse ¶
func JSONResponse(w http.ResponseWriter, bs []byte) error
JSONResponse sends a JSON response to the client.
func Logger ¶
func Logger() *zap.SugaredLogger
func NewHTTPError ¶
NewHTTPError returns a new HTTPError.
func SendGETRequest ¶
SendGETRequest makes an HTTP GET request and decodes the JSON response into the provided target interface.
Types ¶
type ClientError ¶
type ClientError interface { Error() string ResponseBody() ([]byte, error) ResponseHeaders() (int, map[string]string) }
ClientError is an error whose details is to be shared with the client.
type HTTPClient ¶
var (
Client HTTPClient = &http.Client{Timeout: 60 * time.Second}
)
type HTTPError ¶
type HTTPError struct { Cause error `json:"-"` Detail string `json:"detail"` Status int `json:"-"` }
HTTPError implements ClientError interface.
func (*HTTPError) ResponseBody ¶
ResponseBody returns JSON response body.