rest

package
v0.0.0-...-15a86da Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 30, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteHandler

func DeleteHandler(r chi.Router, pattern string, handler routeHandler)

DeleteHandler is a DELETE handler using routeHandler

func ErrInternal

func ErrInternal(logger *zap.SugaredLogger, err error) render.Renderer

ErrInternal returns a generic server error to the user

func ErrInvalidRequest

func ErrInvalidRequest(logger *zap.SugaredLogger, errText string, err error) render.Renderer

ErrInvalidRequest is used to indicate an error on user input (with wrapped error)

func ErrNotFound

func ErrNotFound(msg string) render.Renderer

ErrNotFound returns server error with not found status code

func ErrUnauthorized

func ErrUnauthorized(msg string) render.Renderer

ErrUnauthorized returns server error with unathorized status code

func GetHandler

func GetHandler(r chi.Router, pattern string, handler routeHandler)

GetHandler is a GET handler using routeHandler

func JSONStatusOK

func JSONStatusOK(payload interface{}) render.Renderer

JSONStatusOK is a message with JSON payload and 200 http code

func JSONWithStatus

func JSONWithStatus(payload interface{}, code int) render.Renderer

JSONWithStatus is a JSON payload with provided status

func MsgStatusOK

func MsgStatusOK(msg string) render.Renderer

MsgStatusOK is a message with 200 http code

func MsgStatusOKf

func MsgStatusOKf(msg string, a ...interface{}) render.Renderer

MsgStatusOKf is a format specifier version of MsgStatusOK

func MsgWithStatus

func MsgWithStatus(code int, msg string) render.Renderer

MsgWithStatus is a message with provide http code

func MsgWithStatusf

func MsgWithStatusf(code int, msg string, a ...interface{}) render.Renderer

MsgWithStatusf is a format specifier version of MsgStatus

func PostHandler

func PostHandler(r chi.Router, pattern string, handler routeHandler)

PostHandler is a POST handler using routeHandler

func PutHandler

func PutHandler(r chi.Router, pattern string, handler routeHandler)

PutHandler is a PUT handler using routeHandler

Types

type ErrResponse

type ErrResponse struct {
	Logger         *zap.SugaredLogger `json:"-"` // logger to use
	Err            error              `json:"-"` // low-level runtime error
	HTTPStatusCode int                `json:"-"` // http response status code

	StatusText string `json:"status"`          // user-level status message
	AppCode    int64  `json:"code,omitempty"`  // application-specific error code
	ErrorText  string `json:"error,omitempty"` // application-level error message, for debugging
}

ErrResponse is a generic struct for returning a standard error document

func (*ErrResponse) Render

func (e *ErrResponse) Render(w http.ResponseWriter, r *http.Request) error

Render is the Renderer for ErrResponse struct

type JSONResponse

type JSONResponse struct {
	HTTPStatusCode int         `json:"-"`                // http response status code
	Status         string      `json:"status,omitempty"` // http status message
	Payload        interface{} `json:"payload"`          // application-specific JSON payload
}

JSONResponse is json response payload

func (*JSONResponse) Render

func (j *JSONResponse) Render(w http.ResponseWriter, r *http.Request) error

Render is the Renderer for the JSONResponse struct

type MsgResponse

type MsgResponse struct {
	HTTPStatusCode int `json:"-"` // http response status code

	Message string `json:"message"`        // message for user
	AppCode int64  `json:"code,omitempty"` // application-specific message code
}

MsgResponse is a generic message response by the API server

func (*MsgResponse) Render

func (m *MsgResponse) Render(w http.ResponseWriter, r *http.Request) error

Render is the Renderer for the MsgResponse struct

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL