Remove replicated expvar handler (#805)

expvar package exports Handler which can be directly used instead of copying the expvarHandler function.
This commit is contained in:
Cem Ezberci
2018-03-01 01:43:54 +01:00
committed by Reed Allman
parent 0b85e3d520
commit c149588a5b

View File

@@ -2,31 +2,14 @@ package server
import ( import (
"expvar" "expvar"
"fmt"
"net/http"
"net/http/pprof" "net/http/pprof"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
// Replicated from expvar.go as not public.
func expVars(w http.ResponseWriter, r *http.Request) {
first := true
w.Header().Set("Content-Type", "application/json; charset=utf-8")
fmt.Fprintf(w, "{\n")
expvar.Do(func(kv expvar.KeyValue) {
if !first {
fmt.Fprintf(w, ",\n")
}
first = false
fmt.Fprintf(w, "%q: %s", kv.Key, kv.Value)
})
fmt.Fprintf(w, "\n}\n")
}
func profilerSetup(router *gin.Engine, path string) { func profilerSetup(router *gin.Engine, path string) {
engine := router.Group(path) engine := router.Group(path)
engine.Any("/vars", gin.WrapF(expVars)) engine.Any("/vars", gin.WrapF(expvar.Handler().ServeHTTP))
engine.Any("/pprof/", gin.WrapF(pprof.Index)) engine.Any("/pprof/", gin.WrapF(pprof.Index))
engine.Any("/pprof/cmdline", gin.WrapF(pprof.Cmdline)) engine.Any("/pprof/cmdline", gin.WrapF(pprof.Cmdline))
engine.Any("/pprof/profile", gin.WrapF(pprof.Profile)) engine.Any("/pprof/profile", gin.WrapF(pprof.Profile))