update: X-Trace-Id
This commit is contained in:
parent
116d5b13f8
commit
459e3d9c09
14
go.mod
14
go.mod
@ -8,20 +8,18 @@ require (
|
||||
github.com/glebarez/sqlite v1.10.0
|
||||
github.com/go-redis/redis/v8 v8.11.5
|
||||
github.com/golang-jwt/jwt/v5 v5.2.0
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7
|
||||
github.com/jackc/pgtype v1.12.0
|
||||
github.com/jedib0t/go-pretty/v6 v6.5.9
|
||||
github.com/loveuer/esgo2dump v0.3.3
|
||||
github.com/loveuer/nf v0.2.4
|
||||
github.com/loveuer/nf v0.2.7
|
||||
github.com/loveuer/ngorm/v2 v2.1.1
|
||||
github.com/matoous/go-nanoid/v2 v2.1.0
|
||||
github.com/rabbitmq/amqp091-go v1.10.0
|
||||
github.com/samber/lo v1.39.0
|
||||
github.com/sirupsen/logrus v1.9.2
|
||||
github.com/spf13/cast v1.6.0
|
||||
github.com/tdewolff/minify/v2 v2.20.16
|
||||
golang.org/x/crypto v0.14.0
|
||||
golang.org/x/crypto v0.23.0
|
||||
google.golang.org/grpc v1.50.0
|
||||
gorm.io/driver/mysql v1.4.5
|
||||
gorm.io/driver/postgres v1.4.4
|
||||
@ -37,6 +35,7 @@ require (
|
||||
github.com/glebarez/go-sqlite v1.21.2 // indirect
|
||||
github.com/go-sql-driver/mysql v1.7.0 // indirect
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
|
||||
github.com/jackc/pgconn v1.13.0 // indirect
|
||||
github.com/jackc/pgio v1.0.0 // indirect
|
||||
@ -52,12 +51,13 @@ require (
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||
github.com/rivo/uniseg v0.2.0 // indirect
|
||||
github.com/stretchr/testify v1.9.0 // indirect
|
||||
github.com/tdewolff/parse/v2 v2.7.11 // indirect
|
||||
github.com/vesoft-inc/nebula-go/v3 v3.5.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirect
|
||||
golang.org/x/net v0.17.0 // indirect
|
||||
golang.org/x/sys v0.18.0 // indirect
|
||||
golang.org/x/text v0.13.0 // indirect
|
||||
golang.org/x/net v0.25.0 // indirect
|
||||
golang.org/x/sys v0.20.0 // indirect
|
||||
golang.org/x/text v0.15.0 // indirect
|
||||
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect
|
||||
google.golang.org/protobuf v1.30.0 // indirect
|
||||
modernc.org/libc v1.22.5 // indirect
|
||||
|
23
go.sum
23
go.sum
@ -146,12 +146,10 @@ github.com/lib/pq v1.10.2 h1:AqzbZs4ZoCBp+GtejcpCpcxM3zlSMx29dXbUSeVtJb8=
|
||||
github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
github.com/loveuer/esgo2dump v0.3.3 h1:/AidoaFV7bDRyT1ycyBKs4XGmyVs2ShaUKrpEBiUWkM=
|
||||
github.com/loveuer/esgo2dump v0.3.3/go.mod h1:thZvfsO0kd7Ck3TA0jc9rRc4CuIa4Iuiq6tF3tCqXEY=
|
||||
github.com/loveuer/nf v0.2.4 h1:2xoGLXCf9Yfp7MndHtxwjy97c21rDIdLiOEWxrL2FJ4=
|
||||
github.com/loveuer/nf v0.2.4/go.mod h1:mR3Hc3j6kivKS+QwaYULYuiZOLQCfcaRPTtK260pBaw=
|
||||
github.com/loveuer/nf v0.2.7 h1:p17Y2yvO6u1qnSvYawQsMzBb2Xw7EzkV87r6BZzhdfA=
|
||||
github.com/loveuer/nf v0.2.7/go.mod h1:M6reF17/kJBis30H4DxR5hrtgo/oJL4AV4cBe4HzJLw=
|
||||
github.com/loveuer/ngorm/v2 v2.1.1 h1:v+ut5BjeSBFU87o800pI8Q3fXEOUAkvk5+btMw2oOEc=
|
||||
github.com/loveuer/ngorm/v2 v2.1.1/go.mod h1:BVhFGQsRMdcf08MtmwwRihwCR/x7wDd0Fzy8Xj+edM0=
|
||||
github.com/matoous/go-nanoid/v2 v2.1.0 h1:P64+dmq21hhWdtvZfEAofnvJULaRR1Yib0+PnU669bE=
|
||||
github.com/matoous/go-nanoid/v2 v2.1.0/go.mod h1:KlbGNQ+FhrUNIHUxZdL63t7tl4LaPkZNpUULS8H4uVM=
|
||||
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
|
||||
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
@ -209,6 +207,7 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/tdewolff/minify/v2 v2.20.16 h1:/C8dtRkxLTIyUlKlBz46gDiktCrE8a6+c1gTrnPFz+U=
|
||||
github.com/tdewolff/minify/v2 v2.20.16/go.mod h1:/FvxV9KaTrFu35J9I2FhRvWSBxcHj8sDSdwBFh5voxM=
|
||||
github.com/tdewolff/parse/v2 v2.7.11 h1:v+W45LnzmjndVlfqPCT5gGjAAZKd1GJGOPJveTIkBY8=
|
||||
@ -241,8 +240,8 @@ golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c/go.mod h1:jdWPYTVW3xRLrWP
|
||||
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
|
||||
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
|
||||
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 h1:3MTrJm4PyNL9NBqvYDSj3DHl46qQakyfqfWo4jgfaEM=
|
||||
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=
|
||||
@ -264,8 +263,8 @@ golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLL
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
|
||||
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
|
||||
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
|
||||
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
@ -290,8 +289,8 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
|
||||
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
|
||||
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
@ -301,8 +300,8 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
|
||||
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
|
||||
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||
|
@ -2,7 +2,9 @@ package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/loveuer/nf"
|
||||
"github.com/loveuer/nf/nft/resp"
|
||||
"time"
|
||||
"ultone/internal/handler"
|
||||
"ultone/internal/middleware/auth"
|
||||
@ -21,9 +23,13 @@ func initApp(ctx context.Context) *nf.App {
|
||||
// todo: add project prefix, if you need
|
||||
// for example: app := engine.Group("/api/{project}")
|
||||
app := engine.Group("/api")
|
||||
app.Get("/available", func(c *nf.Ctx) error {
|
||||
return c.JSON(nf.Map{"status": 200, "ok": true, "time": time.Now()})
|
||||
})
|
||||
app.Get("/available", func() nf.HandlerFunc {
|
||||
start := time.Now()
|
||||
return func(c *nf.Ctx) error {
|
||||
now := time.Now()
|
||||
return resp.Resp200(c, nf.Map{"ok": true, "start": start, "now": now, "duration": fmt.Sprint(now.Sub(start))})
|
||||
}
|
||||
}())
|
||||
|
||||
{
|
||||
api := app.Group("/user")
|
||||
|
@ -41,12 +41,12 @@ func (u uc) GetUser(c *nf.Ctx, id uint64) (*model.User, error) {
|
||||
|
||||
if opt.EnableUserCache {
|
||||
if bs, err = cache.Client.Get(tool.Timeout(3), key); err != nil {
|
||||
log.Warn(c, "controller.GetUser: get user by cache key=%s err=%v", key, err)
|
||||
log.Warn(c.Context(), "controller.GetUser: get user by cache key=%s err=%v", key, err)
|
||||
goto ByDB
|
||||
}
|
||||
|
||||
if err = json.Unmarshal(bs, target); err != nil {
|
||||
log.Warn(c, "controller.GetUser: json unmarshal key=%s by=%s err=%v", key, string(bs), err)
|
||||
log.Warn(c.Context(), "controller.GetUser: json unmarshal key=%s by=%s err=%v", key, string(bs), err)
|
||||
goto ByDB
|
||||
}
|
||||
|
||||
@ -69,7 +69,7 @@ ByDB:
|
||||
|
||||
if opt.EnableUserCache {
|
||||
if err = u.CacheUser(c, target); err != nil {
|
||||
log.Warn(c, "controller.GetUser: cache user key=%s err=%v", key, err)
|
||||
log.Warn(c.Context(), "controller.GetUser: cache user key=%s err=%v", key, err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ func (u uc) GetUserByToken(c *nf.Ctx, token string) (*model.User, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Debug(c, "controller.GetUserByToken: key=%s cache bytes=%s", key, string(bs))
|
||||
log.Debug(c.Context(), "controller.GetUserByToken: key=%s cache bytes=%s", key, string(bs))
|
||||
|
||||
userId := cast.ToUint64(string(bs))
|
||||
if userId == 0 {
|
||||
@ -146,7 +146,7 @@ func (u uc) DeleteUser(c *nf.Ctx, id uint64) error {
|
||||
|
||||
if opt.EnableUserCache {
|
||||
if err = u.RmUserCache(c, id); err != nil {
|
||||
log.Warn(c, "controller.DeleteUser: rm user=%d cache err=%v", id, err)
|
||||
log.Warn(c.Context(), "controller.DeleteUser: rm user=%d cache err=%v", id, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,16 +86,16 @@ func LogList(c *nf.Ctx) error {
|
||||
for _, logItem := range list {
|
||||
m := make(map[string]any)
|
||||
if err = logItem.Content.Bind(&m); err != nil {
|
||||
log.Warn(c, "handler.LogList: log=%d content=%v bind map[string]any err=%v", logItem.Id, logItem.Content, err)
|
||||
log.Warn(c.Context(), "handler.LogList: log=%d content=%v bind map[string]any err=%v", logItem.Id, logItem.Content, err)
|
||||
continue
|
||||
}
|
||||
|
||||
if logItem.HTML, err = logItem.Type.Render(m); err != nil {
|
||||
log.Warn(c, "handler.LogList: log=%d template=%s render map=%+v err=%v", logItem.Id, logItem.Type.Template(), m, err)
|
||||
log.Warn(c.Context(), "handler.LogList: log=%d template=%s render map=%+v err=%v", logItem.Id, logItem.Type.Template(), m, err)
|
||||
continue
|
||||
}
|
||||
|
||||
log.Debug(c, "handler.LogList: log=%d render map=%+v string=%s", logItem.Id, m, logItem.HTML)
|
||||
log.Debug(c.Context(), "handler.LogList: log=%d render map=%+v string=%s", logItem.Id, m, logItem.HTML)
|
||||
}
|
||||
|
||||
return resp.Resp200(c, nf.Map{"list": list, "total": total})
|
||||
|
@ -1,40 +1,40 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/loveuer/nf"
|
||||
ulog "github.com/loveuer/nf/nft/log"
|
||||
"ultone/internal/opt"
|
||||
)
|
||||
|
||||
func _mix(c *nf.Ctx, msg string) string {
|
||||
if c == nil {
|
||||
func _mix(ctx context.Context, msg string) string {
|
||||
if ctx == nil {
|
||||
return msg
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%v | %s", c.Locals(opt.LocalTraceKey), msg)
|
||||
return fmt.Sprintf("%v | %s", ctx.Value(nf.TraceKey), msg)
|
||||
}
|
||||
|
||||
func Debug(c *nf.Ctx, msg string, data ...any) {
|
||||
ulog.Debug(_mix(c, msg), data...)
|
||||
func Debug(ctx context.Context, msg string, data ...any) {
|
||||
ulog.Debug(_mix(ctx, msg), data...)
|
||||
}
|
||||
|
||||
func Info(c *nf.Ctx, msg string, data ...any) {
|
||||
ulog.Info(_mix(c, msg), data...)
|
||||
func Info(ctx context.Context, msg string, data ...any) {
|
||||
ulog.Info(_mix(ctx, msg), data...)
|
||||
}
|
||||
|
||||
func Warn(c *nf.Ctx, msg string, data ...any) {
|
||||
ulog.Warn(_mix(c, msg), data...)
|
||||
func Warn(ctx context.Context, msg string, data ...any) {
|
||||
ulog.Warn(_mix(ctx, msg), data...)
|
||||
}
|
||||
|
||||
func Error(c *nf.Ctx, msg string, data ...any) {
|
||||
ulog.Error(_mix(c, msg), data...)
|
||||
func Error(ctx context.Context, msg string, data ...any) {
|
||||
ulog.Error(_mix(ctx, msg), data...)
|
||||
}
|
||||
|
||||
func Panic(c *nf.Ctx, msg string, data ...any) {
|
||||
ulog.Panic(_mix(c, msg), data...)
|
||||
func Panic(ctx context.Context, msg string, data ...any) {
|
||||
ulog.Panic(_mix(ctx, msg), data...)
|
||||
}
|
||||
|
||||
func Fatal(c *nf.Ctx, msg string, data ...any) {
|
||||
ulog.Fatal(_mix(c, msg), data...)
|
||||
func Fatal(ctx context.Context, msg string, data ...any) {
|
||||
ulog.Fatal(_mix(ctx, msg), data...)
|
||||
}
|
||||
|
@ -31,11 +31,11 @@ func NewAuth() nf.HandlerFunc {
|
||||
return resp.Resp401(c, token)
|
||||
}
|
||||
|
||||
log.Debug(c, "middleware.NewAuth: token=%s", token)
|
||||
log.Debug(c.Context(), "middleware.NewAuth: token=%s", token)
|
||||
|
||||
target, err := controller.UserController.GetUserByToken(c, token)
|
||||
if err != nil {
|
||||
log.Error(c, "middleware.NewAuth: get user by token=%s err=%v", token, err)
|
||||
log.Error(c.Context(), "middleware.NewAuth: get user by token=%s err=%v", token, err)
|
||||
if errors.Is(err, redis.Nil) || errors.Is(err, gredis.ErrKeyNotFound) {
|
||||
return resp.Resp401(c, err)
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ func NewFront(ff *embed.FS, basePath string) nf.HandlerFunc {
|
||||
)
|
||||
|
||||
if bs, err = ff.ReadFile(basePath + path); err != nil {
|
||||
log.Debug(c, "embed read file [%s]%s err: %v", basePath, path, err)
|
||||
log.Debug(c.Context(), "embed read file [%s]%s err: %v", basePath, path, err)
|
||||
c.Set("Content-Type", "text/html")
|
||||
_, err = c.Write(indexBytes)
|
||||
return err
|
||||
|
@ -2,38 +2,25 @@ package logger
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/google/uuid"
|
||||
"github.com/loveuer/esgo2dump/log"
|
||||
"github.com/loveuer/nf"
|
||||
"github.com/loveuer/nf/nft/resp"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
"ultone/internal/opt"
|
||||
"ultone/internal/tool"
|
||||
)
|
||||
|
||||
var (
|
||||
Header = http.CanonicalHeaderKey("X-Trace-Id")
|
||||
)
|
||||
|
||||
func New() nf.HandlerFunc {
|
||||
|
||||
return func(c *nf.Ctx) error {
|
||||
var (
|
||||
now = time.Now()
|
||||
traceId = c.Get(Header)
|
||||
logFn func(msg string, data ...any)
|
||||
ip = c.IP()
|
||||
now = time.Now()
|
||||
logFn func(msg string, data ...any)
|
||||
ip = c.IP()
|
||||
)
|
||||
|
||||
if traceId == "" {
|
||||
traceId = uuid.Must(uuid.NewV7()).String()
|
||||
}
|
||||
|
||||
c.SetHeader(Header, traceId)
|
||||
|
||||
c.Locals(opt.LocalTraceKey, traceId)
|
||||
traceId := c.Context().Value(nf.TraceKey)
|
||||
c.Locals(nf.TraceKey, traceId)
|
||||
|
||||
err := c.Next()
|
||||
status, _ := strconv.Atoi(c.Writer.Header().Get(resp.RealStatusHeader))
|
||||
|
@ -36,7 +36,7 @@ const (
|
||||
// todo: 操作日志 最多延迟多少秒写入(最多缓存多少秒的日志,然后 bulk 写入)
|
||||
OpLogWriteDurationSecond = 5
|
||||
|
||||
LocalTraceKey = "X-Trace"
|
||||
LocalTraceKey = "X-Trace-Id"
|
||||
)
|
||||
|
||||
var (
|
||||
|
Loading…
x
Reference in New Issue
Block a user