Documentation
¶
Overview ¶
Package httputil implements http helpers
Index ¶
- func AuthBearer(auth string) string
- func ExpectStatus(want int, got int) error
- func StdErrMsg(code int) string
- func ValidationErrMsg(err validator.FieldError) string
- type Client
- func (c *Client) DelJSON(path string, payload any, destPtr any) (int, error)
- func (c *Client) Get(path string) ([]byte, int, error)
- func (c *Client) GetJSON(path string, destPtr any) (int, error)
- func (c *Client) PostJSON(path string, payload any, destPtr any) (int, error)
- func (c *Client) PutJSON(path string, payload any, destPtr any) (int, error)
- func (c *Client) Req(method string, path string, payload any) (*http.Response, error)
- type Err
- type ErrResponse
- type ValidationErr
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthBearer ¶
AuthBearer extracts bearer token value from Authorization header
func ExpectStatus ¶ added in v1.5.4
ExpectStatus returns error if actual status not equal to expected one
func ValidationErrMsg ¶
func ValidationErrMsg(err validator.FieldError) string
ValidationErrMsg returns validation error message by validate tag
Types ¶
type Client ¶ added in v1.7.0
type Client struct { BaseURL string Header http.Header Cookies []http.Cookie Timeout time.Duration }
Client implements base http client
func (*Client) DelJSON ¶ added in v1.7.0
DelJSON makes delete request and decodes response body as json
func (*Client) GetJSON ¶ added in v1.7.0
GetJSON makes get request and decodes response body as json
func (*Client) PostJSON ¶ added in v1.7.0
PostJSON makes post request and decodes response body as json
type Err ¶
type Err struct { Code int `json:"code"` Msg string `json:"msg"` Items []ValidationErr `json:"items,omitempty"` }
Err represents generic api error
type ErrResponse ¶
type ErrResponse struct {
Error Err `json:"error"`
}
ErrResponse represents json container for error object
func NewErr ¶
func NewErr(code int, msg string) *ErrResponse
NewErr returns new standard api error value
func NewErrFrom ¶
func NewErrFrom(err error) *ErrResponse
NewErrFrom returns new error value from given error
func NewValidationErr ¶
func NewValidationErr(errors validator.ValidationErrors) *ErrResponse
NewValidationErr returns new validation error value
func (*ErrResponse) WriteJSON ¶
func (e *ErrResponse) WriteJSON(w http.ResponseWriter)
WriteJSON responds json error with http.ResponseWriter
type ValidationErr ¶
ValidationErr represents validation error