Documentation ¶
Index ¶
- type BaseResponse
- type ErrResponse
- func Err(message string, code int, kvs ...interface{}) *ErrResponse
- func ErrBadRequest(message string, kvs ...interface{}) *ErrResponse
- func ErrForbidden(message string, kvs ...interface{}) *ErrResponse
- func ErrInternalServer(message string, err error, kvs ...interface{}) *ErrResponse
- func ErrNotFound(message string, kvs ...interface{}) *ErrResponse
- func ErrUnauthorized(message string, kvs ...interface{}) *ErrResponse
- type MsgResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseResponse ¶
type BaseResponse struct { // Basic metadata HTTPStatusCode int `json:"code"` RequestID string `json:"request_id,omitempty"` // Message is included in all responses, and is a summary of the server's response Message string `json:"message"` // Err contains additional context in the event of an error Err string `json:"error,omitempty"` // Data contains information the server wants to return Data interface{} `json:"data,omitempty"` }
BaseResponse is the underlying structure of all API responses
func (*BaseResponse) Render ¶
func (b *BaseResponse) Render(w http.ResponseWriter, r *http.Request) error
Render implements chi/render.Render
type ErrResponse ¶
type ErrResponse struct {
*BaseResponse
}
ErrResponse is the template for a typical HTTP response for errors
func Err ¶
func Err(message string, code int, kvs ...interface{}) *ErrResponse
Err is a basic error response constructor
func ErrBadRequest ¶
func ErrBadRequest(message string, kvs ...interface{}) *ErrResponse
ErrBadRequest is a shortcut for bad requests
func ErrForbidden ¶
func ErrForbidden(message string, kvs ...interface{}) *ErrResponse
ErrForbidden is a shortcut for forbidden requests
func ErrInternalServer ¶
func ErrInternalServer(message string, err error, kvs ...interface{}) *ErrResponse
ErrInternalServer is a shortcut for internal server errors. It should be accompanied by an actual error.
func ErrNotFound ¶
func ErrNotFound(message string, kvs ...interface{}) *ErrResponse
ErrNotFound is a shortcut for forbidden requests
func ErrUnauthorized ¶
func ErrUnauthorized(message string, kvs ...interface{}) *ErrResponse
ErrUnauthorized is a shortcut for unauthorized requests
type MsgResponse ¶
type MsgResponse struct {
*BaseResponse
}
MsgResponse is the template for a typical HTTP response for messages
func Msg ¶
func Msg(message string, code int, kvs ...interface{}) *MsgResponse
Msg is a shortcut for non-error statuses
func MsgOK ¶
func MsgOK(message string, kvs ...interface{}) *MsgResponse
MsgOK is a shortcut for an ok-status response