mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Merge branch 'middleware-update' into 'master'
Allow setting values in middleware context like gin context. See merge request !99
This commit is contained in:
@@ -43,6 +43,23 @@ type middlewareContextImpl struct {
|
|||||||
middlewares []Middleware
|
middlewares []Middleware
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set is used to store a new key/value pair exclusively for this context.
|
||||||
|
// This is different than WithValue(), as it does not make a copy of the context with the new value, it will be available up the chain as well.
|
||||||
|
func (c *middlewareContextImpl) Set(key string, value interface{}) {
|
||||||
|
c.ginContext.Set(key, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get returns the value for the given key, ie: (value, true).
|
||||||
|
// If the value does not exists it returns (nil, false)
|
||||||
|
func (c *middlewareContextImpl) Get(key string) (value interface{}, exists bool) {
|
||||||
|
return c.ginContext.Get(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MustGet returns the value for the given key if it exists, otherwise it panics.
|
||||||
|
func (c *middlewareContextImpl) MustGet(key string) interface{} {
|
||||||
|
return c.ginContext.MustGet(key)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *middlewareContextImpl) Next() {
|
func (c *middlewareContextImpl) Next() {
|
||||||
c.nextCalled = true
|
c.nextCalled = true
|
||||||
c.index++
|
c.index++
|
||||||
@@ -91,12 +108,12 @@ func (s *Server) middlewareWrapperFunc(ctx context.Context) gin.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddAppEndpoint adds an endpoints to /v1/apps/:app/x
|
// AddMiddleware add middleware
|
||||||
func (s *Server) AddMiddleware(m Middleware) {
|
func (s *Server) AddMiddleware(m Middleware) {
|
||||||
s.middlewares = append(s.middlewares, m)
|
s.middlewares = append(s.middlewares, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddAppEndpoint adds an endpoints to /v1/apps/:app/x
|
// AddMiddlewareFunc adds middleware function
|
||||||
func (s *Server) AddMiddlewareFunc(m func(ctx MiddlewareContext, w http.ResponseWriter, r *http.Request, app *models.App) error) {
|
func (s *Server) AddMiddlewareFunc(m func(ctx MiddlewareContext, w http.ResponseWriter, r *http.Request, app *models.App) error) {
|
||||||
s.AddMiddleware(MiddlewareFunc(m))
|
s.AddMiddleware(MiddlewareFunc(m))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
functionsDockerImage = "treeder/functions"
|
functionsDockerImage = "funcy/functions"
|
||||||
minRequiredDockerVersion = "17.5.0"
|
minRequiredDockerVersion = "17.5.0"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import:
|
|||||||
subpackages:
|
subpackages:
|
||||||
- models
|
- models
|
||||||
- package: github.com/Sirupsen/logrus
|
- package: github.com/Sirupsen/logrus
|
||||||
repo: https://github.com/sirupsen/logrus
|
repo: https://github.com/sirupsen/logrus.git
|
||||||
vcs: git
|
vcs: git
|
||||||
version: ^v0.11.5
|
version: ^v0.11.5
|
||||||
subpackages:
|
subpackages:
|
||||||
|
|||||||
Reference in New Issue
Block a user