forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin_rpcwrap.go
40 lines (32 loc) · 995 Bytes
/
plugin_rpcwrap.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
package callinfo
import (
"fmt"
"html/template"
"github.com/youtube/vitess/go/rpcwrap/proto"
"golang.org/x/net/context"
)
// RPCWrapCallInfo takes a context generated by rpcwrap, and
// returns one that has CallInfo filled in.
func RPCWrapCallInfo(ctx context.Context) context.Context {
remoteAddr, _ := proto.RemoteAddr(ctx)
username, _ := proto.Username(ctx)
return NewContext(ctx, &rpcWrapCallInfoImpl{
remoteAddr: remoteAddr,
username: username,
})
}
type rpcWrapCallInfoImpl struct {
remoteAddr, username string
}
func (rwci *rpcWrapCallInfoImpl) RemoteAddr() string {
return rwci.remoteAddr
}
func (rwci *rpcWrapCallInfoImpl) Username() string {
return rwci.username
}
func (rwci *rpcWrapCallInfoImpl) Text() string {
return fmt.Sprintf("%s@%s", rwci.username, rwci.remoteAddr)
}
func (rwci *rpcWrapCallInfoImpl) HTML() template.HTML {
return template.HTML("<b>RemoteAddr:</b> " + rwci.remoteAddr + "</br>\n" + "<b>Username:</b> " + rwci.username + "</br>\n")
}