服务端拦截器
接口实现
// UnaryServerInfo contains metadata about a single (unary) RPC call.
// This is passed to interceptors to provide context about the server and method being called.
type UnaryServerInfo struct {
// Server is the underlying service implementation.
Server any
// FullMethod is the path to the RPC (e.g., "/user.UserService/GetUser").
FullMethod string
// Protocol identifies the transport (e.g., "grpc", "rest").
Protocol string
}
// UnaryHandler is the signature of the final business logic or the next step in the chain.
type UnaryHandler func(ctx context.Context, req any) (any, error)
// UnaryServerInterceptor is a middleware function that wraps the request execution.
// It can modify the context/request before execution or the response/error after.
type UnaryServerInterceptor func(ctx context.Context, req any, info *UnaryServerInfo, handler UnaryHandler) (resp any, err error)
// ServerInterceptor is the interface for pluggable middleware components.
type ServerInterceptor interface {
// Name returns the unique identifier for the interceptor (e.g., "logger").
Name() string
// Interceptor returns the actual function that performs the wrapping.
Interceptor() UnaryServerInterceptor
}
已支持的实现
配置
自定义实现
最后更新于