Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultLabels = []Label{ { Label: "service_name", GetValue: func(ctx *gin.Context) string { return app.Name() }, }, { Label: "node", GetValue: func(ctx *gin.Context) string { return app.LocalIP() }, }, { Label: "method", GetValue: func(c *gin.Context) string { return c.Request.Method }, }, { Label: "api", GetValue: func(c *gin.Context) string { return c.Request.URL.Path }, }, { Label: "error_number", GetValue: func(c *gin.Context) string { return strconv.Itoa(len(c.Errors)) }, }, { Label: "http_status", GetValue: func(c *gin.Context) string { return strconv.Itoa(c.Writer.Status()) }, }, { Label: "errno", GetValue: func(c *gin.Context) string { ctx := c.Request.Context() rw := lc.ValueResponseWriter(c.Request.Context()) bw, ok := rw.(*mr.BodyWriter) if !ok { return "-1" } resp := &sr.Response{} if err := json.Unmarshal(bw.Body.Bytes(), resp); err != nil { return "-2" } code := cast.ToString(int(resp.Errno)) logger.AddField(ctx, logger.Reflect(logger.Errno, code)) c.Request = c.Request.WithContext(ctx) return code }, }, }
Functions ¶
func HTTPMetricsMiddleware ¶
func HTTPMetricsMiddleware(opts ...OptionFunc) gin.HandlerFunc
HTTPMetricsMiddleware return a gin.HandlerFunc. Panic and response is executed after c.Next. The code after next takes effect in the reverse order. So must register after PanicMiddleware and LoggerMiddleware.
func WithFilters ¶
func WithLabels ¶
Types ¶
type OptionFunc ¶
type OptionFunc func(*Options)
Click to show internal directories.
Click to hide internal directories.