github.com/treeverse/lakefs@v1.24.1-0.20240520134607-95648127bfb0/pkg/httputil/endpoints.go (about) 1 package httputil 2 3 import ( 4 "io" 5 "net/http" 6 "net/http/pprof" 7 "strings" 8 ) 9 10 var healthInfo string 11 12 func SetHealthHandlerInfo(info string) { 13 healthInfo = info 14 } 15 16 func ServeHealth() http.Handler { 17 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 18 _, _ = io.WriteString(w, "alive!") 19 if healthInfo != "" { 20 _, _ = io.WriteString(w, " "+healthInfo) 21 } 22 }) 23 } 24 25 func ServePPROF(pprofPrefix string) http.Handler { 26 return http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) { 27 endpoint := strings.TrimPrefix(request.URL.Path, pprofPrefix) 28 switch endpoint { 29 case "": 30 http.HandlerFunc(pprof.Index).ServeHTTP(writer, request) 31 case "cmdline": 32 http.HandlerFunc(pprof.Cmdline).ServeHTTP(writer, request) 33 case "profile": 34 http.HandlerFunc(pprof.Profile).ServeHTTP(writer, request) 35 case "symbol": 36 http.HandlerFunc(pprof.Symbol).ServeHTTP(writer, request) 37 case "trace": 38 http.HandlerFunc(pprof.Trace).ServeHTTP(writer, request) 39 case "allocs", "block", "goroutine", "heap", "mutex", "threadcreate": 40 pprof.Handler(endpoint).ServeHTTP(writer, request) 41 default: 42 writer.WriteHeader(http.StatusNotFound) 43 } 44 }) 45 }