Documentation ¶
Index ¶
- Constants
- type Resource
- func (rs *Resource) Authenticator() func(http.Handler) http.Handler
- func (rs *Resource) AuthorizeResolver(act string) func(next http.Handler) http.Handler
- func (rs *Resource) GraphQueryReader(whitelistFunctions []string) func(http.Handler) http.Handler
- func (rs *Resource) SessionCtx(next http.Handler) http.Handler
- func (rs *Resource) Timeout(timeout time.Duration) func(next http.Handler) http.Handler
Constants ¶
View Source
const ( // SessionKey is the context key to store JWT private claims which is captured from the request SessionKey = "session" PublicFunctionKey = "public-function" RequestFunctionNameKey = "function-name" )
View Source
const (
RequestId = "X-Request-Id"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Resource ¶
type Resource struct {
// contains filtered or unexported fields
}
func NewMiddleware ¶
func NewMiddleware(utility utility, session session) *Resource
NewMiddleware creates a new middleware
func (*Resource) Authenticator ¶
func (*Resource) AuthorizeResolver ¶
AuthorizeResolver is a middleware to manage resolver function's access control based on the captured session
this method should be called after SessionCtx()
func (*Resource) GraphQueryReader ¶
func (*Resource) SessionCtx ¶
SessionCtx authorizes session credential
func (*Resource) Timeout ¶
Timeout is a middleware that cancels ctx after a given timeout and return a 504 Gateway Timeout error to the client.
It's required that you select the ctx.Done() channel to check for the signal if the context has reached its deadline and return, otherwise the timeout signal will be just ignored.
i.e. a route/handler may look like:
r.Get("/long", func(w http.ResponseWriter, r *http.Request) { ctx := r.Context() processTime := time.Duration(rand.Intn(4)+1) * time.Second select { case <-ctx.Done(): return case <-time.After(processTime): // The above channel simulates some hard work. } w.Write([]byte("done")) })
FYI: it adopted: https://github.com/go-chi/chi/blob/master/middleware/timeout.go
Source Files ¶
Click to show internal directories.
Click to hide internal directories.