Documentation ¶
Index ¶
- Variables
- func ACL(authorizer Authorizer) func(http.Handler) http.Handler
- func AccessLog(opts AccessLogOptions) func(next http.Handler) http.Handler
- func Authentication(next http.Handler) http.Handler
- func Authorized(next http.Handler) http.Handler
- func ContextLogger(factory logger.Factory) func(http.Handler) http.Handler
- func Newrelic(app newrelic.Application) func(http.Handler) http.Handler
- func OnlyRoles(roles ...string) func(http.Handler) http.Handler
- func Prometheus() func(http.Handler) http.Handler
- func Recoverer(handler PanicHandler) func(http.Handler) http.Handler
- func RequestID(prefix string) func(http.Handler) http.Handler
- type AccessCheck
- type AccessCheckerFn
- type AccessLogOptions
- type Authorizer
- type PanicHandler
- type PanicHandlerFunc
- type PanicRecoveredError
Constants ¶
This section is empty.
Variables ¶
var ( // AccessGranted successful authorization AccessGranted = AccessCheck{} AccessUnauthorized = AccessCheck{http.StatusUnauthorized} // AccessForbidden users doesn't have required missing role AccessForbidden = AccessCheck{http.StatusForbidden} )
Functions ¶
func ACL ¶
func ACL(authorizer Authorizer) func(http.Handler) http.Handler
ACL grants access for custom rules
func AccessLog ¶
func AccessLog(opts AccessLogOptions) func(next http.Handler) http.Handler
AccessLog records all requests processed by the server.
func Authentication ¶
Authentication looking for user in headers and inject user to context
func Authorized ¶
Authorized grants access for non-guest users
func ContextLogger ¶
ContextLogger initialize logger entry for request context
Required for all routers as first middleware! At that moment we don't see reason pass loggerFactory to the each middleware - therefore all middlewares uses logger from context, otherwise will be used global logger and information could be incomplete.
Types ¶
type AccessCheck ¶
type AccessCheck struct {
// contains filtered or unexported fields
}
AccessCheck result of access check
type AccessCheckerFn ¶
type AccessCheckerFn func(*userclient.User, *http.Request) AccessCheck
AuthorizerFn functional implementation of AccessChecker
func (AccessCheckerFn) Authorize ¶
func (fn AccessCheckerFn) Authorize(user *userclient.User, r *http.Request) AccessCheck
type AccessLogOptions ¶
AccessLogOptions for request or response body
type Authorizer ¶
type Authorizer interface { // Authorize request // FYI: don't need to parse request path. // Request already has information about matched route chi.RouteContext(r.Context()) Authorize(user *userclient.User, r *http.Request) AccessCheck }
AccessChecker checks that's user has rights for access
type PanicHandler ¶
type PanicHandler interface {
ServeHTTP(w http.ResponseWriter, req *http.Request, err PanicRecoveredError)
}
PanicHandler interface Triggered on application panic and passing as last argument (rvr) value from recover()
type PanicHandlerFunc ¶
type PanicHandlerFunc func(http.ResponseWriter, *http.Request, PanicRecoveredError)
PanicHandlerFunc implements PanicHandler interface
func (PanicHandlerFunc) ServeHTTP ¶
func (f PanicHandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request, err PanicRecoveredError)
ServeHTTP implements PanicHandler interface
type PanicRecoveredError ¶
type PanicRecoveredError struct { Rvr interface{} Stack []byte }
func (PanicRecoveredError) Error ¶
func (err PanicRecoveredError) Error() string