forked from rantav/go-grpc-channelz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.go
33 lines (27 loc) · 1.07 KB
/
handler.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
package channelz
import (
"net/http"
"path"
"sync"
channelzgrpc "google.golang.org/grpc/channelz/grpc_channelz_v1"
)
// CreateHandler creates an http handler with the routes of channelz mounted to the provided prefix.
// pathPrefix is the prefix to which /channelz will be prepended
// grpcBindAddress is the TCP bind address for the gRPC service you'd like to monitor.
// grpcBindAddress is required since the channelz interface connects to this gRPC service
//
// Typically you'd use the return value of CreateHandler as an argument to http.Handle
// For example:
// http.Handle("/", channelz.CreateHandler("/foo", grpcBindAddress))
func CreateHandler(pathPrefix, grpcServerName, grpcBindAddress string) http.Handler {
prefix := path.Join(pathPrefix, "channelz", grpcServerName) + "/"
handler := &grpcChannelzHandler{bindAddress: grpcBindAddress}
return createRouter(prefix, handler)
}
type grpcChannelzHandler struct {
// the target server's bind address
bindAddress string
// The client connection (lazily initialized)
client channelzgrpc.ChannelzClient
mu sync.Mutex
}