Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ResponseBadRequest = Response{ StatusCode: http.StatusBadRequest, Message: "bad request", }
ResponseBadRequest is a standard way of serving a 400
View Source
var ResponseInternalServerError = Response{ StatusCode: http.StatusInternalServerError, Message: "internal server error", }
ResponseInternalServerError is a standard way of serving a 500
View Source
var ResponseMethodNotAllowed = Response{ StatusCode: http.StatusMethodNotAllowed, Message: "method not allowed", }
ResponseMethodNotAllowed is a standard way of serving a 405
View Source
var ResponseNotFound = Response{ StatusCode: http.StatusNotFound, Message: "not found", }
ResponseNotFound is a standard way of serving a 404
View Source
http.StatusUnauthorized, Message: "unauthorized", }StatusCode:
ResponseUnauthorized is a standard way of serving a 401
Functions ¶
func MiddlewareLogger ¶
MiddlewareLogger is a simple logging middleware
func RegisterRoutes ¶
func RegisterRoutes(mux *http.ServeMux, routes []Route, middlewares []Middleware)
RegisterRoutes for a given mux
func ResponseFunc ¶
func ResponseFunc(s ResponseHandler) http.Handler
ResponseFunc is a shortcut for making sure a ResponseHandler can be used as a http.Handler
Types ¶
type Middleware ¶
Middleware for wrapping http.Handlers
type Response ¶
type Response struct { StatusCode int `json:"-"` State bool `json:"state"` Message string `json:"message"` Data interface{} `json:"data"` ExtraData interface{} `json:"extraData"` }
Response is a standard response format to use for API responses
type ResponseHandler ¶
type ResponseHandler func(w http.ResponseWriter, r *http.Request) Response
ResponseHandler is a simpler than http.HandlerFunc for enforcing the proper usage of Response
Click to show internal directories.
Click to hide internal directories.