// Client is middleware client-side metrics.
Client is middleware client-side metrics.
// Client is middleware client - side metrics .
func Client(opts ...Option) middleware.Middleware {
	op := options{}
	for _, o := range opts {
		o(&op)
	}
	return func(handler middleware.Handler) middleware.Handler {
		return func(ctx context.Context, req interface{}) (interface{}, error) {
			var (
				code      int
				reason    string
				kind      string
				operation string
			)
			startTime := time.Now()
			if info, ok := transport.FromClientContext(ctx); ok {
				kind = info.Kind().String()
				operation = info.Operation()
			}
			reply, err := handler(ctx, req)
			if se := errors.FromError(err); se != nil {
				code = int(se.Code)
				reason = se.Reason
			}
			if op.requests != nil {
				op.requests.With(kind, operation, strconv.Itoa(code), reason).Inc()
			}
			if op.seconds != nil {
				op.seconds.With(kind, operation).Observe(time.Since(startTime).Seconds())
			}
			return reply, err
		}
	}
}
func Client ( opts ... Option ) middleware . Middleware { op := options { } for _ , o := range opts { o ( & op ) } return func ( handler middleware . Handler ) middleware . Handler { return func ( ctx context . Context , req interface { } ) ( interface { } , error ) { var ( code int reason string kind string operation string ) startTime := time . Now ( ) if info , ok := transport . FromClientContext ( ctx ) ; ok { kind = info . Kind ( ) . String ( ) operation = info . Operation ( ) } reply , err := handler ( ctx , req ) if se := errors . FromError ( err ) ; se != nil { code = int ( se . Code ) reason = se . Reason } if op . requests != nil { op . requests . With ( kind , operation , strconv . Itoa ( code ) , reason ) . Inc ( ) } if op . seconds != nil { op . seconds . With ( kind , operation ) . Observe ( time . Since ( startTime ) . Seconds ( ) ) } return reply , err } } }
Client is middleware client-side metrics.
Client is middleware client - side metrics .