Documentation ¶
Index ¶
- func GetLogger(ctx context.Context) *logrus.Entry
- func HandleError(err error, w http.ResponseWriter, r *http.Request)
- func HandleSQLError(err error) error
- func LoggerSetField(ctx context.Context, key string, value interface{}) context.Context
- func LoggerSetFields(ctx context.Context, fields logrus.Fields) context.Context
- func QueryParamInt(r *http.Request, key string) int
- func QueryParamString(r *http.Request, key string) string
- func Recoverer(w http.ResponseWriter, r *http.Request) (context.Context, error)
- func SendJSON(w http.ResponseWriter, status int, obj interface{}) error
- func SendList(w http.ResponseWriter, status int, obj interface{}) error
- func SendObject(w http.ResponseWriter, status int, obj interface{}) error
- func SetLogger(ctx context.Context, requestLogger *logrus.Entry) context.Context
- func WithLogger(log *logrus.Entry) func(w http.ResponseWriter, r *http.Request) (context.Context, error)
- type HTTPError
- func BadRequestError(fmtString string, args ...interface{}) *HTTPError
- func InternalServerError(fmtString string, args ...interface{}) *HTTPError
- func NewHTTPError(code int, 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 Router
- func (r *Router) Delete(pattern string, fn apiHandler)
- func (r *Router) Get(pattern string, fn apiHandler)
- func (r *Router) Post(pattern string, fn apiHandler)
- func (r *Router) Put(pattern string, fn apiHandler)
- func (r *Router) Route(pattern string, fn func(*Router))
- func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (r *Router) Sse(pattern string, fn func(w http.ResponseWriter, r *http.Request))
- func (r *Router) Use(fn middlewareHandler)
- func (r *Router) UseBypass(fn func(next http.Handler) http.Handler)
- func (r *Router) With(fn middlewareHandler) *Router
- func (r *Router) WithBypass(fn func(next http.Handler) http.Handler) *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 handles all errors
func HandleSQLError ¶
HandleSQLError handle sql errors as internal server error
func LoggerSetField ¶
LoggerSetField and overwrite the logger entry
func LoggerSetFields ¶
LoggerSetFields and overwrite the logger entry
func QueryParamInt ¶
QueryParamInt get a int query parameter from url
func QueryParamString ¶
QueryParamString get a int query parameter from url
func Recoverer ¶
Recoverer is a middleware that recovers from panics, logs the panic (and a backtrace), and returns a HTTP 500 (Internal Server Error) status if possible. Recoverer prints a request ID if one is provided.
func SendJSON ¶
func SendJSON(w http.ResponseWriter, status int, obj interface{}) error
SendJSON send response as json
func SendList ¶
func SendList(w http.ResponseWriter, status int, obj interface{}) error
SendList with data wrapper
func SendObject ¶
func SendObject(w http.ResponseWriter, status int, obj interface{}) error
SendObject with data wrapper
Types ¶
type HTTPError ¶
type HTTPError struct { Code int `json:"error"` Message string `json:"msg"` JSON interface{} `json:"json,omitempty"` 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 return bad request error
func InternalServerError ¶
InternalServerError return internal server error
func NewHTTPError ¶
NewHTTPError create a new http error
func NotFoundError ¶
NotFoundError return not found error
func UnauthorizedError ¶
UnauthorizedError return unauthorized error
func UnavailableServiceError ¶
UnavailableServiceError return unavailable service error
func (*HTTPError) WithInternalError ¶
WithInternalError adds internal error information to the error
func (*HTTPError) WithInternalMessage ¶
WithInternalMessage adds internal message information to the error
func (*HTTPError) WithJSONError ¶
WithJSONError add a json to error
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router wrapper to handle automatic error response
func (*Router) ServeHTTP ¶
func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP wrap the chi function
func (*Router) Use ¶
func (r *Router) Use(fn middlewareHandler)
Use appends one of more middlewares onto the Router stack.
func (*Router) UseBypass ¶
UseBypass appends one of more middlewares with go-chi signature (no automatic error response)