From 7d6f217f0ba08ee9e045840e46e56e775acc2284 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Sun, 21 Jan 2018 09:24:15 -0800 Subject: [PATCH] cmd/routed: more hacks --- cmd/routed/server.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cmd/routed/server.go b/cmd/routed/server.go index 4bc54ec..7d771e1 100644 --- a/cmd/routed/server.go +++ b/cmd/routed/server.go @@ -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,