...
1 package expvar
2
3 import (
4 "expvar"
5 "fmt"
6
7 "github.com/gin-gonic/gin"
8 )
9
10 func Handler() gin.HandlerFunc {
11 return func(c *gin.Context) {
12 w := c.Writer
13 c.Header("Content-Type", "application/json; charset=utf-8")
14 w.Write([]byte("{\n"))
15 first := true
16 expvar.Do(func(kv expvar.KeyValue) {
17 if !first {
18 w.Write([]byte(",\n"))
19 }
20 first = false
21 fmt.Fprintf(w, "%q: %s", kv.Key, kv.Value)
22 })
23 w.Write([]byte("\n}\n"))
24 c.AbortWithStatus(200)
25 }
26 }
27
View as plain text