2018-07-07 20:10:56 +00:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Scope represents a list of scope processed by middlewares
|
|
|
|
// and used by the router to block/allow some uris
|
|
|
|
// it is also passed to controllers
|
2018-09-28 08:54:13 +00:00
|
|
|
//
|
|
|
|
// DISCLAIMER: it is used to help developers but for compatibility
|
|
|
|
// purposes, the type is always used as its definition ([]string)
|
2018-07-07 20:10:56 +00:00
|
|
|
type Scope []string
|
|
|
|
|
2018-09-28 08:54:13 +00:00
|
|
|
type MiddlewareFunc func(http.Request, *[]string)
|
|
|
|
|
|
|
|
// Middleware updates the @Scope passed to it according to
|
2018-07-07 20:10:56 +00:00
|
|
|
// the @http.Request
|
2018-09-28 08:54:13 +00:00
|
|
|
type Middleware interface {
|
|
|
|
Inspect(http.Request, *[]string)
|
|
|
|
}
|
2018-07-07 20:10:56 +00:00
|
|
|
|
2018-09-28 08:54:13 +00:00
|
|
|
// Wrapper is a struct that stores middleware Inspect() method
|
|
|
|
type Wrapper struct {
|
|
|
|
Inspect func(http.Request, *[]string)
|
2018-07-07 20:10:56 +00:00
|
|
|
}
|
|
|
|
|
2018-07-08 23:34:21 +00:00
|
|
|
// Registry represents a registry containing all registered
|
2018-07-07 20:10:56 +00:00
|
|
|
// middlewares to be processed before routing any request
|
2018-07-08 23:34:21 +00:00
|
|
|
type Registry struct {
|
2018-09-28 08:54:13 +00:00
|
|
|
Middlewares []*Wrapper
|
2018-07-07 20:10:56 +00:00
|
|
|
}
|