hanayo/vendor/github.com/johnniedoe/contrib/expvar/expvar.go
2019-02-23 13:29:15 +00:00

27 lines
468 B
Go

package expvar
import (
"expvar"
"fmt"
"github.com/gin-gonic/gin"
)
func Handler() gin.HandlerFunc {
return func(c *gin.Context) {
w := c.Writer
c.Header("Content-Type", "application/json; charset=utf-8")
w.Write([]byte("{\n"))
first := true
expvar.Do(func(kv expvar.KeyValue) {
if !first {
w.Write([]byte(",\n"))
}
first = false
fmt.Fprintf(w, "%q: %s", kv.Key, kv.Value)
})
w.Write([]byte("\n}\n"))
c.AbortWithStatus(200)
}
}