add user middleware chain function (#1913)
* add user middleware chain function * fix staticcheck SA4006 * chang code Implementation style Co-authored-by: kemq1 <kemq1@spdb.com.cn>
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"path"
|
||||
"time"
|
||||
|
||||
"github.com/justinas/alice"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/handler"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
@@ -242,6 +243,17 @@ func WithTLSConfig(cfg *tls.Config) RunOption {
|
||||
}
|
||||
}
|
||||
|
||||
// WithChain returns a RunOption that with given chain config.
|
||||
func WithChain(middlewares ...func(http.Handler) http.Handler) RunOption {
|
||||
return func(svr *Server) {
|
||||
chain := alice.New()
|
||||
for _, middleware := range middlewares {
|
||||
chain = chain.Append(middleware)
|
||||
}
|
||||
svr.ngin.setChainConfig(&chain)
|
||||
}
|
||||
}
|
||||
|
||||
// WithUnauthorizedCallback returns a RunOption that with given unauthorized callback set.
|
||||
func WithUnauthorizedCallback(callback handler.UnauthorizedCallback) RunOption {
|
||||
return func(svr *Server) {
|
||||
|
||||
Reference in New Issue
Block a user