stats
HTTP请求的统计中间件,可以根据此中间件将http请求的各类统计信息写入至统计数据库,如:influxdb等,方便根据统计来优化性能以及监控。
Example
package main
import (
"bytes"
"encoding/json"
"fmt"
"github.com/vicanso/elton"
"github.com/vicanso/elton/middleware"
)
func main() {
e := elton.New()
e.Use(middleware.NewStats(middleware.StatsConfig{
OnStats: func(info *middleware.StatsInfo, _ *elton.Context) {
buf, _ := json.Marshal(info)
fmt.Println(string(buf))
},
}))
e.GET("/", func(c *elton.Context) (err error) {
c.BodyBuffer = bytes.NewBufferString("abcd")
return
})
err := e.ListenAndServe(":3000")
if err != nil {
panic(err)
}
}