Documentation ¶
Index ¶
- Variables
- func APIError(opts ...func(*apiErrCfg)) func(http.Handler) http.Handler
- func APIErrorDefault500(err error) func(*apiErrCfg)
- func APIErrorLoggerOutput(w io.Writer) func(*apiErrCfg)
- func Filter(criteria ...filtering.FilterDecoder) func(*listingConfig)
- func GetListing(ctx context.Context) (*listing.Listing, error)
- func Limit(limit int) func(*listingConfig)
- func Listing(opts ...func(*listingConfig)) func(http.Handler) http.Handler
- func MaxAllowedLimit(maxAllowed int) func(*listingConfig)
- func Recovery(opts ...func(*recoveryCfg)) func(http.Handler) http.Handler
- func RecoveryLoggerOutput(w io.Writer) func(*recoveryCfg)
- func Sort(criteria ...sorting.Sort) func(*listingConfig)
Constants ¶
This section is empty.
Variables ¶
var ErrAPIDefault = errors.New("looks like something went wrong")
ErrAPIDefault default error message response when something happens.
Functions ¶
func APIError ¶
APIError intercept responses to verify their status and handle the error. It gets the response code and if it's >= 500 handlers the error with a default error message and without disclosure internal information. The real error keeps logged.
func APIErrorDefault500 ¶
func APIErrorDefault500(err error) func(*apiErrCfg)
APIErrorDefault500 set default error message to be sent
func APIErrorLoggerOutput ¶
APIErrorLoggerOutput set the output for the logger
func Filter ¶
func Filter(criteria ...filtering.FilterDecoder) func(*listingConfig)
Filter set criteria to filter
func GetListing ¶
GetListing will return the listing reference assigned to the context, or nil if there is any error or there isn't a Listing instance.
func Listing ¶
Listing is a middleware that parses the url from a request and stores a listing.Listing on the context, it can be accessed through middleware.GetListing.
Sample usage.. for the url: `/repositories/1?limit=10&offset=25`
func routes() http.Handler { r := chi.NewRouter() r.Use(middleware.Listing()) r.Get("/repositories/{id}", ListRepositories) return r } func ListRepositories(w http.ResponseWriter, r *http.Request) { list, _ := middleware.GetListing(r.Context()) // do something with listing }
func MaxAllowedLimit ¶
func MaxAllowedLimit(maxAllowed int) func(*listingConfig)
MaxAllowedLimit set the max allowed limit default.
func Recovery ¶
Recovery is a middleware that recovers from panics, logs the panic (and a backtrace), and returns a HTTP 500 (Internal Server Error) status if possible. Recovery prints a request ID if one is provided.
func RecoveryLoggerOutput ¶
RecoveryLoggerOutput set the output for the logger
Types ¶
This section is empty.