6cf6f95f58
CodeQL / Analyze (push) Has been cancelled
Sync to Gitee / Run (push) Has been cancelled
Go / build & test (1.25.x) (push) Has been cancelled
Go / build & test (1.26.x) (push) Has been cancelled
Lint / resolve module (push) Has been cancelled
Lint / lint module (push) Has been cancelled
22 lines
485 B
Go
22 lines
485 B
Go
package middleware
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
// Handler defines the handler invoked by Middleware.
|
|
type Handler func(ctx context.Context, req any) (any, error)
|
|
|
|
// Middleware is HTTP/gRPC transport middleware.
|
|
type Middleware func(Handler) Handler
|
|
|
|
// Chain returns a Middleware that specifies the chained handler for endpoint.
|
|
func Chain(m ...Middleware) Middleware {
|
|
return func(next Handler) Handler {
|
|
for i := len(m) - 1; i >= 0; i-- {
|
|
next = m[i](next)
|
|
}
|
|
return next
|
|
}
|
|
}
|