cmd/routed: more hacks

This commit is contained in:
Cadey Ratio 2018-01-21 09:24:15 -08:00
parent 28c3094e40
commit 7d6f217f0b
1 changed files with 9 additions and 3 deletions

View File

@ -148,14 +148,20 @@ func New(cfg Config) (*Server, error) {
go s.listenKCP(context.Background(), cfg.BackendKCPAddr, tc)
go s.listenTCP(context.Background(), cfg.BackendTCPAddr, tc)
withHandler := func(disc string, h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
h.ServeHTTP(w, r.WithContext(ln.WithF(r.Context(), ln.F{"disc": disc})))
})
}
bhdr := proto.NewBackendsServer(&Backend{Server: s}, s.makeTwirpHooks())
rhdr := proto.NewRoutesServer(&Route{Server: s}, s.makeTwirpHooks())
thdr := proto.NewTokensServer(&Token{Server: s}, s.makeTwirpHooks())
mux := http.NewServeMux()
mux.Handle(proto.BackendsPathPrefix, bhdr)
mux.Handle(proto.RoutesPathPrefix, rhdr)
mux.Handle(proto.TokensPathPrefix, thdr)
mux.Handle(proto.BackendsPathPrefix, withHandler("backends", bhdr))
mux.Handle(proto.RoutesPathPrefix, withHandler("routes", rhdr))
mux.Handle(proto.TokensPathPrefix, withHandler("tokens", thdr))
hs := &http.Server{
TLSConfig: tc,