Documentation
¶
Index ¶
- Constants
- func AsErrorResp(err error, target **ErrorResp) bool
- func DefaultErrorHandler(w http.ResponseWriter, r *http.Request, errResp *ErrorResp)
- func HTMLErrorHandler(w http.ResponseWriter, r *http.Request, errResp *ErrorResp)
- func JSONErrorHandler(w http.ResponseWriter, r *http.Request, errResp *ErrorResp)
- func Wrap(h HandlerFunc, onErr ErrorHandlerFunc) http.HandlerFunc
- type ErrorHandlerFunc
- type ErrorResp
- type HandlerFunc
Constants ¶
View Source
const ReqIDKey string = "requestID"
Variables ¶
This section is empty.
Functions ¶
func AsErrorResp ¶ added in v0.3.1
Helper func for checking if error is of type *ErroResp.
func DefaultErrorHandler ¶ added in v0.3.1
func DefaultErrorHandler(w http.ResponseWriter, r *http.Request, errResp *ErrorResp)
Can be used in Wrap func as default one
func HTMLErrorHandler ¶ added in v0.3.1
func HTMLErrorHandler(w http.ResponseWriter, r *http.Request, errResp *ErrorResp)
Default func for html error handling, with examplary html code.
func JSONErrorHandler ¶ added in v0.3.1
func JSONErrorHandler(w http.ResponseWriter, r *http.Request, errResp *ErrorResp)
Default func for json error handling.
func Wrap ¶ added in v0.3.1
func Wrap(h HandlerFunc, onErr ErrorHandlerFunc) http.HandlerFunc
A wrapper func for handling errors from the called handler funcs. Uses custom func which handles error response. Defaults to DefaultErrorHandler if nothing is passed.
Types ¶
type ErrorHandlerFunc ¶ added in v0.3.1
type ErrorHandlerFunc func(http.ResponseWriter, *http.Request, *ErrorResp)
Custom type of error handler func mostly used for custom transport logic.
type ErrorResp ¶
type ErrorResp struct {
Status int `json:"status"` // HTTP status code with a json tag
ClientMsg string `json:"client_message"` // Human-readable message with a json tag
ServerMsg string `json:"-"` // Server side message, for logging purposes
}
Simple error response struct with json notation.
func NewErrorResp ¶
type HandlerFunc ¶ added in v0.3.1
A handler func which accepts context field and returns error response.
Click to show internal directories.
Click to hide internal directories.