forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 1
/
plugin_grpc.go
43 lines (34 loc) · 880 Bytes
/
plugin_grpc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package callinfo
// This file implements the CallInfo interface for gRPC contexts.
import (
"fmt"
"html/template"
"golang.org/x/net/context"
"google.golang.org/grpc/transport"
)
// GRPCCallInfo returns an augmented context with a CallInfo structure,
// only for gRPC contexts.
func GRPCCallInfo(ctx context.Context) context.Context {
stream, ok := transport.StreamFromContext(ctx)
if !ok {
return ctx
}
return NewContext(ctx, &gRPCCallInfoImpl{
method: stream.Method(),
})
}
type gRPCCallInfoImpl struct {
method string
}
func (gci *gRPCCallInfoImpl) RemoteAddr() string {
return "remote"
}
func (gci *gRPCCallInfoImpl) Username() string {
return "gRPC"
}
func (gci *gRPCCallInfoImpl) Text() string {
return fmt.Sprintf("%s(gRPC)", gci.method)
}
func (gci *gRPCCallInfoImpl) HTML() template.HTML {
return template.HTML("<b>Method:</b> " + gci.method)
}