Documentation ¶
Index ¶
- func HandleError(err error, w http.ResponseWriter, r *http.Request)
- func HandlerFunc(fn APIHandler) http.HandlerFunc
- func OptEnableCORS(r *chiWrapper)
- func Recoverer(w http.ResponseWriter, r *http.Request, next http.Handler)
- func SendJSON(w http.ResponseWriter, status int, obj interface{}) error
- type APIHandler
- type HTTPError
- func BadRequestError(fmtString string, args ...interface{}) *HTTPError
- func InternalServerError(fmtString string, args ...interface{}) *HTTPError
- func NotFoundError(fmtString string, args ...interface{}) *HTTPError
- func UnauthorizedError(fmtString string, args ...interface{}) *HTTPError
- func UnavailableServiceError(fmtString string, args ...interface{}) *HTTPError
- type Middleware
- type Option
- type Router
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HandleError ¶
func HandleError(err error, w http.ResponseWriter, r *http.Request)
HandleError will handle an error
func HandlerFunc ¶
func HandlerFunc(fn APIHandler) http.HandlerFunc
func OptEnableCORS ¶
func OptEnableCORS(r *chiWrapper)
Types ¶
type APIHandler ¶
type APIHandler func(w http.ResponseWriter, r *http.Request) *HTTPError
type HTTPError ¶
type HTTPError struct { Code int `json:"code"` Message string `json:"msg"` JSON interface{} `json:"json"` InternalError error `json:"-"` InternalMessage string `json:"-"` ErrorID string `json:"error_id,omitempty"` }
HTTPError is an error with a message and an HTTP status code.
func BadRequestError ¶
BadRequestError creates a 400 HTTP error
func InternalServerError ¶
InternalServerError creates a 500 HTTP error
func NotFoundError ¶
NotFoundError creates a 404 HTTP error
func UnauthorizedError ¶
UnauthorizedError creates a 401 HTTP error
func UnavailableServiceError ¶
UnavailableServiceError creates a 503 HTTP error
func (*HTTPError) WithInternalError ¶
WithInternalError will add internal error information to an error
func (*HTTPError) WithInternalMessage ¶
WithInternalMessage will add and internal message to an error
func (*HTTPError) WithJSONError ¶
WithJSONError will add json details to the error
type Middleware ¶
func CheckAuth ¶
func CheckAuth(secret string) Middleware
func HealthCheck ¶
func HealthCheck(route string, f APIHandler) Middleware
func MiddlewareFunc ¶
func MiddlewareFunc(f func(w http.ResponseWriter, r *http.Request, next http.Handler)) Middleware
func VersionHeader ¶
func VersionHeader(serviceName, version string) Middleware
type Option ¶
type Option func(r *chiWrapper)
func OptHealthCheck ¶
func OptHealthCheck(path string, checker APIHandler) Option
func OptTracingMiddleware ¶
func OptTracingMiddleware(log logrus.FieldLogger, svcName string) Option
func OptVersionHeader ¶
type Router ¶
type Router interface { // Use appends one middleware onto the Router stack. Use(fn Middleware) // With adds an inline middleware for an endpoint handler. With(fn Middleware) Router // Route mounts a sub-Router along a `pattern“ string. Route(pattern string, fn func(r Router)) // Method adds a routes for a `pattern` that matches the `method` HTTP method. Method(method, pattern string, h APIHandler) // HTTP-method routing along `pattern` Delete(pattern string, h APIHandler) Get(pattern string, h APIHandler) Post(pattern string, h APIHandler) Put(pattern string, h APIHandler) // Mount attaches another http.Handler along ./pattern/* Mount(pattern string, h http.Handler) ServeHTTP(http.ResponseWriter, *http.Request) }
Router wraps the chi router to make it slightly more accessible
Click to show internal directories.
Click to hide internal directories.