tracker
用于在客户提交类的请求添加跟踪日志,可输出query、body以及params等信息,并可设置正则匹配将关键数据加*处理。
Example
package main
import (
"bytes"
"encoding/json"
"fmt"
"github.com/vicanso/elton"
"github.com/vicanso/elton/middleware"
)
func main() {
e := elton.New()
loginTracker := middleware.NewTracker(middleware.TrackerConfig{
OnTrack: func(info *middleware.TrackerInfo, _ *elton.Context) {
buf, _ := json.Marshal(info)
fmt.Println(string(buf))
},
})
e.Use(func(c *elton.Context) error {
c.RequestBody = []byte(`{
"account": "tree.xie",
"password": "123456"
}`)
return c.Next()
})
e.POST("/user/login", loginTracker, func(c *elton.Context) (err error) {
c.SetHeader(elton.HeaderContentType, elton.MIMEApplicationJSON)
c.BodyBuffer = bytes.NewBuffer(c.RequestBody)
return
})
err := e.ListenAndServe(":3000")
if err != nil {
panic(err)
}
}