You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
607 B
23 lines
607 B
package middleware
|
|
|
|
import (
|
|
"context"
|
|
"github.com/cloudwego/kitex/pkg/endpoint"
|
|
"github.com/cloudwego/kitex/pkg/klog"
|
|
"github.com/cloudwego/kitex/pkg/rpcinfo"
|
|
)
|
|
|
|
var _ endpoint.Middleware = ServerMiddleware
|
|
|
|
// ServerMiddleware server middleware print client address
|
|
func ServerMiddleware(next endpoint.Endpoint) endpoint.Endpoint {
|
|
return func(ctx context.Context, req, resp interface{}) (err error) {
|
|
ri := rpcinfo.GetRPCInfo(ctx)
|
|
// get client information
|
|
klog.Infof("client address: %v", ri.From().Address())
|
|
if err = next(ctx, req, resp); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
}
|
|
|