mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-23 09:18:51 +02:00
[BREAKING] added entrypoint middleware support and config, config schema update
This commit is contained in:
@@ -23,7 +23,7 @@ type (
|
||||
|
||||
BeforeFunc func(next http.HandlerFunc, w ResponseWriter, r *Request)
|
||||
RewriteFunc func(req *Request)
|
||||
ModifyResponseFunc func(resp *Response) error
|
||||
ModifyResponseFunc = gphttp.ModifyResponseFunc
|
||||
CloneWithOptFunc func(opts OptionsRaw) (*Middleware, E.Error)
|
||||
|
||||
OptionsRaw = map[string]any
|
||||
@@ -114,6 +114,17 @@ func (m *Middleware) ModifyResponse(resp *Response) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Middleware) ServeHTTP(next http.HandlerFunc, w ResponseWriter, r *Request) {
|
||||
if m.modifyResponse != nil {
|
||||
w = gphttp.NewModifyResponseWriter(w, r, m.modifyResponse)
|
||||
}
|
||||
if m.before != nil {
|
||||
m.before(next, w, r)
|
||||
} else {
|
||||
next(w, r)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: check conflict or duplicates.
|
||||
func createMiddlewares(middlewaresMap map[string]OptionsRaw) ([]*Middleware, E.Error) {
|
||||
middlewares := make([]*Middleware, 0, len(middlewaresMap))
|
||||
|
||||
Reference in New Issue
Block a user