mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
37 lines
998 B
Go
37 lines
998 B
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"gitlab-odx.oracle.com/odx/functions/api/models"
|
|
)
|
|
|
|
// SpecialHandler verysimilar to a handler but since it is not used as middle ware no way
|
|
// to get context without returning it. So we just return a request which could have newly made
|
|
// contexts.
|
|
type SpecialHandler interface {
|
|
Handle(w http.ResponseWriter, r *http.Request) (*http.Request, error)
|
|
}
|
|
|
|
// AddSpecialHandler adds the SpecialHandler to the specialHandlers list.
|
|
func (s *Server) AddSpecialHandler(handler SpecialHandler) {
|
|
s.specialHandlers = append(s.specialHandlers, handler)
|
|
}
|
|
|
|
// UseSpecialHandlers execute all special handlers
|
|
func (s *Server) UseSpecialHandlers(resp http.ResponseWriter, req *http.Request) (*http.Request, error) {
|
|
if len(s.specialHandlers) == 0 {
|
|
return req, models.ErrNoSpecialHandlerFound
|
|
}
|
|
var r *http.Request
|
|
var err error
|
|
|
|
for _, l := range s.specialHandlers {
|
|
r, err = l.Handle(resp, req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return r, nil
|
|
}
|