-
Notifications
You must be signed in to change notification settings - Fork 174
/
http.go
66 lines (53 loc) · 2.27 KB
/
http.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package veneur
import (
"net/http"
"net/http/pprof"
"github.com/stripe/veneur/v14/util/build"
"github.com/stripe/veneur/v14/util/config"
"goji.io"
"goji.io/pat"
)
// Handler returns the Handler responsible for routing request processing.
func (s *Server) Handler() http.Handler {
mux := goji.NewMux()
mux.HandleFunc(pat.Get("/healthcheck"), func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("ok\n"))
})
mux.HandleFunc(pat.Get("/builddate"), func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(build.BUILD_DATE))
})
mux.HandleFunc(pat.Get("/version"), func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(build.VERSION))
})
if s.Config.HTTP.Config {
mux.HandleFunc(pat.Get("/config/json"), config.HandleConfigJson(s.Config))
mux.HandleFunc(pat.Get("/config/yaml"), config.HandleConfigYaml(s.Config))
}
if s.httpQuit {
mux.HandleFunc(pat.Post(httpQuitEndpoint), func(w http.ResponseWriter, r *http.Request) {
s.logger.WithField("endpoint", httpQuitEndpoint).
Info("Received shutdown request on HTTP quit endpoint")
w.Write([]byte("Beginning graceful shutdown....\n"))
s.Shutdown()
})
}
// TODO3.0: Maybe remove this endpoint as it is kinda useless now that tracing is always on.
mux.HandleFunc(pat.Get("/healthcheck/tracing"), func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("ok\n"))
})
for endpoint, customHandler := range s.HttpCustomHandlers {
mux.HandleFunc(pat.Get(endpoint), customHandler)
}
mux.Handle(pat.Get("/debug/pprof/"), http.HandlerFunc(pprof.Index))
mux.Handle(pat.Get("/debug/pprof/allocs"), pprof.Handler("allocs"))
mux.Handle(pat.Get("/debug/pprof/block"), pprof.Handler("block"))
mux.Handle(pat.Get("/debug/pprof/cmdline"), http.HandlerFunc(pprof.Cmdline))
mux.Handle(pat.Get("/debug/pprof/goroutine"), pprof.Handler("goroutine"))
mux.Handle(pat.Get("/debug/pprof/heap"), pprof.Handler("heap"))
mux.Handle(pat.Get("/debug/pprof/mutex"), pprof.Handler("mutex"))
mux.Handle(pat.Get("/debug/pprof/profile"), http.HandlerFunc(pprof.Profile))
mux.Handle(pat.Get("/debug/pprof/threadcreate"), pprof.Handler("threadcreate"))
mux.Handle(pat.Get("/debug/pprof/symbol"), http.HandlerFunc(pprof.Symbol))
mux.Handle(pat.Get("/debug/pprof/trace"), http.HandlerFunc(pprof.Trace))
return mux
}