1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-01-07 23:02:12 +02:00
kratos/middleware/middleware.go
2021-02-17 17:14:47 +08:00

22 lines
541 B
Go

package middleware
import (
"context"
)
// Handler defines the handler invoked by Middleware.
type Handler func(ctx context.Context, req interface{}) (interface{}, 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(outer Middleware, others ...Middleware) Middleware {
return func(next Handler) Handler {
for i := len(others) - 1; i >= 0; i-- {
next = others[i](next)
}
return outer(next)
}
}