MCPcopy Create free account
hub / github.com/bricks-cloud/BricksLLM / getAdminLoggerMiddleware

Function getAdminLoggerMiddleware

internal/server/web/admin/middleware.go:11–40  ·  view source on GitHub ↗
(log *zap.Logger, prefix string, prod bool, adminPass string)

Source from the content-addressed store, hash-verified

9)
10
11func getAdminLoggerMiddleware(log *zap.Logger, prefix string, prod bool, adminPass string) gin.HandlerFunc {
12 return func(c *gin.Context) {
13 if len(adminPass) != 0 && c.Request.Header.Get("X-API-KEY") != adminPass {
14 c.Status(200)
15 c.Abort()
16 return
17 }
18
19 cid := util.NewUuid()
20 c.Set(util.STRING_CORRELATION_ID, cid)
21 logWithCid := log.With(zap.String(util.STRING_CORRELATION_ID, cid))
22 util.SetLogToCtx(c, logWithCid)
23
24 start := time.Now()
25 c.Next()
26 latency := time.Since(start).Milliseconds()
27 if !prod {
28 logWithCid.Sugar().Infof("%s | %d | %s | %s | %dms", prefix, c.Writer.Status(), c.Request.Method, c.FullPath(), latency)
29 }
30
31 if prod {
32 logWithCid.Info("request to admin management api",
33 zap.Int("code", c.Writer.Status()),
34 zap.String("method", c.Request.Method),
35 zap.String("path", c.FullPath()),
36 zap.Int64("lantecyInMs", latency),
37 )
38 }
39 }
40}

Callers 1

NewAdminServerFunction · 0.85

Calls 6

NewUuidFunction · 0.92
SetLogToCtxFunction · 0.92
InfofMethod · 0.80
InfoMethod · 0.80
GetMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected