- update
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details

master v1.0.10
李光春 2 years ago
parent d05037f530
commit befe2e327e

@ -12,4 +12,4 @@ const (
logTable = "wikeyun"
)
const Version = "1.0.9"
const Version = "1.0.10"

@ -3,9 +3,9 @@ module go.dtapp.net/wikeyun
go 1.19
require (
go.dtapp.net/dorm v1.0.17
go.dtapp.net/dorm v1.0.19
go.dtapp.net/goip v1.0.25
go.dtapp.net/golog v1.0.24
go.dtapp.net/golog v1.0.26
go.dtapp.net/gorequest v1.0.26
go.dtapp.net/gostring v1.0.6
gorm.io/gorm v1.23.8
@ -66,7 +66,7 @@ require (
go.dtapp.net/gojson v1.0.1 // indirect
go.dtapp.net/gorandom v1.0.1 // indirect
go.dtapp.net/gotime v1.0.5 // indirect
go.dtapp.net/gotrace_id v1.0.0 // indirect
go.dtapp.net/gotrace_id v1.0.2 // indirect
go.dtapp.net/gourl v1.0.0 // indirect
go.dtapp.net/goxml v1.0.1 // indirect
go.mongodb.org/mongo-driver v1.10.1 // indirect

@ -499,14 +499,14 @@ github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a/go.mod h1:ul22v+Nro/
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0=
go.dtapp.net/dorm v1.0.17 h1:3VQKUl05CDxFg3T1c/M8wYf2I+H+oVGBDh4NCV30nn0=
go.dtapp.net/dorm v1.0.17/go.mod h1:bHG7BmgeLaAlc56myYF63lwZAIuMeWRAqHBb/L84dLM=
go.dtapp.net/dorm v1.0.19 h1:3uH4tYZ5zH4knx9o6BJlE3rFiWNWTyMxlpt0Cwoq7zE=
go.dtapp.net/dorm v1.0.19/go.mod h1:bHG7BmgeLaAlc56myYF63lwZAIuMeWRAqHBb/L84dLM=
go.dtapp.net/goip v1.0.25 h1:GSgQkR7dc28TX8E1mF3wAy+EEGZ++tgqc8Q85OKZPEY=
go.dtapp.net/goip v1.0.25/go.mod h1:dKeNuWJttH4AvvYVHV0FagB6BVvFM1HGDKFxLKr+hkQ=
go.dtapp.net/gojson v1.0.1 h1:MHeSGlq1KxzL7rCkm18fhwW4GNORHohdDMmxY5PupKY=
go.dtapp.net/gojson v1.0.1/go.mod h1:TkkpTNxHBKxul0e7gC5MrL1K4ICFB9mQ7wHzjBah3/k=
go.dtapp.net/golog v1.0.24 h1:A26GN2fEJOsMWRb+jqG2LKRmB8aEuWFYNNXGT23VNbc=
go.dtapp.net/golog v1.0.24/go.mod h1:P1CFwGZ6xm2nLXCi0DTwO8aHNfT2dkdjz+9b2ph1TNQ=
go.dtapp.net/golog v1.0.26 h1:EmUA/QwtQcX57tyTL73H92zJeObJDuTcUqE01MI3v1A=
go.dtapp.net/golog v1.0.26/go.mod h1:Ey15AuwDiRyaTXieM3f4Ukzkbmm6+jVb/VYpW00p840=
go.dtapp.net/gorandom v1.0.1 h1:IWfMClh1ECPvyUjlqD7MwLq4mZdUusD1qAwAdsvEJBs=
go.dtapp.net/gorandom v1.0.1/go.mod h1:ZPdgalKpvFV/ATQqR0k4ns/F/IpITAZpx6WkWirr5Y8=
go.dtapp.net/gorequest v1.0.26 h1:t+rMW7liLHz1RgY60ztWIghSkTeQePKWM0EsDG1IqMI=
@ -515,8 +515,8 @@ go.dtapp.net/gostring v1.0.6 h1:XqNaThEfHpweLofru5sBqm1UUzc9JWsXyB/M/rTk29w=
go.dtapp.net/gostring v1.0.6/go.mod h1:AMnnLjyNxH+cphxyASJGYCzWpVrkP5RncuVo8xL8s3E=
go.dtapp.net/gotime v1.0.5 h1:12aNgB2ULpP6QgQHEUkLilZ4ASvhpFxMFQkBwn0par8=
go.dtapp.net/gotime v1.0.5/go.mod h1:Gq7eNLr2iMLP18UNWONRq4V3Uhf/ADp4bIrS+Tc6ktY=
go.dtapp.net/gotrace_id v1.0.0 h1:nlI8KEEf2l394SCzmJxffEIiOBfR4kIOuobBhpRSV3g=
go.dtapp.net/gotrace_id v1.0.0/go.mod h1:HDwMY1vLoC759z6VGKVgCpIqwKQTDYV9DNdxiyN1OeQ=
go.dtapp.net/gotrace_id v1.0.2 h1:wSc7dYzkAwSz3MbPu2Io4XqHe0l0dIaJe3vlpDAZrXY=
go.dtapp.net/gotrace_id v1.0.2/go.mod h1:476T5KMJw9c6DM/rJn7y6d28hcNDv4+wew4sd+powes=
go.dtapp.net/gourl v1.0.0 h1:Zbe0GiMFyyRy2+bjbVsYulakH5d58w3CDZkUPonlMoQ=
go.dtapp.net/gourl v1.0.0/go.mod h1:x9A/pJ3iKDTb6Gu2RtJy2iHg56IowXIcIGQdogqpGjs=
go.dtapp.net/goxml v1.0.1 h1:WODsjNpmHTtoeLsXgOjC81qRbu4aXZ3LKBHApNGaPjY=

@ -8,4 +8,3 @@
*.txt
*.text
gomod.sh
/vendor/

@ -1,3 +1,3 @@
package dorm
const Version = "1.0.17"
const Version = "1.0.19"

@ -6,32 +6,39 @@ import (
"time"
)
// GttStringFunc String缓存结构
type GttStringFunc func() string
// GttInterfaceFunc Interface缓存结构
type GttInterfaceFunc func() interface{}
// RedisCacheConfig 配置
type RedisCacheConfig struct {
DefaultExpiration time.Duration // 过期时间
Expiration time.Duration // 过期时间
}
// RedisClientCache https://github.com/go-redis/redis
type RedisClientCache struct {
config *RedisCacheConfig
operation *RedisClient // 操作
GetterString func() string // 不存在的操作
GetterInterface func() interface{} // 不存在的操作
defaultExpiration time.Duration // 过期时间
operation *RedisClient // 操作
GetterString GttStringFunc // 不存在的操作
GetterInterface GttInterfaceFunc // 不存在的操作
}
// NewCache 实例化
func (c *RedisClient) NewCache(config *RedisCacheConfig) *RedisClientCache {
cc := &RedisClientCache{config: config}
cc.operation = c
return cc
func (r *RedisClient) NewCache(config *RedisCacheConfig) *RedisClientCache {
return &RedisClientCache{
defaultExpiration: config.Expiration,
operation: r,
}
}
// NewCacheDefaultExpiration 实例化
func (c *RedisClient) NewCacheDefaultExpiration() *RedisClientCache {
cc := &RedisClientCache{}
cc.config.DefaultExpiration = time.Minute * 30 // 默认过期时间
cc.operation = c
return cc
func (r *RedisClient) NewCacheDefaultExpiration() *RedisClientCache {
return &RedisClientCache{
defaultExpiration: time.Minute * 30,
operation: r,
}
}
// GetString 缓存操作
@ -44,7 +51,7 @@ func (rc *RedisClientCache) GetString(ctx context.Context, key string) (ret stri
// 如果不存在则调用GetterString
ret, err := rc.operation.Get(ctx, key).Result()
if err != nil {
rc.operation.Set(ctx, key, f(), rc.config.DefaultExpiration)
rc.operation.Set(ctx, key, f(), rc.defaultExpiration)
ret, _ = rc.operation.Get(ctx, key).Result()
}
@ -63,7 +70,7 @@ func (rc *RedisClientCache) GetInterface(ctx context.Context, key string, result
ret, err := rc.operation.Get(ctx, key).Result()
if err != nil {
rc.operation.Set(ctx, key, f(), rc.config.DefaultExpiration)
rc.operation.Set(ctx, key, f(), rc.defaultExpiration)
ret, _ = rc.operation.Get(ctx, key).Result()
}
@ -71,3 +78,19 @@ func (rc *RedisClientCache) GetInterface(ctx context.Context, key string, result
return
}
// GetInterfaceKey 获取key值
func (rc *RedisClientCache) GetInterfaceKey(ctx context.Context, key string, result interface{}) error {
ret, err := rc.operation.Get(ctx, key).Result()
if err != nil {
return err
}
err = json.Unmarshal([]byte(ret), result)
return nil
}
// SetInterfaceKey 设置key值
func (rc *RedisClientCache) SetInterfaceKey(ctx context.Context, key string, value interface{}) (string, error) {
marshal, _ := json.Marshal(value)
return rc.operation.Set(ctx, key, marshal, rc.defaultExpiration).Result()
}

@ -7,64 +7,64 @@ import (
)
// Set 设置一个key的值
func (c *RedisClient) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.StatusCmd {
return c.Db.Set(ctx, key, value, expiration)
func (r *RedisClient) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.StatusCmd {
return r.Db.Set(ctx, key, value, expiration)
}
// Get 查询key的值
func (c *RedisClient) Get(ctx context.Context, key string) *redis.StringCmd {
return c.Db.Get(ctx, key)
func (r *RedisClient) Get(ctx context.Context, key string) *redis.StringCmd {
return r.Db.Get(ctx, key)
}
// GetSet 设置一个key的值并返回这个key的旧值
func (c *RedisClient) GetSet(ctx context.Context, key string, value interface{}) *redis.StringCmd {
return c.Db.GetSet(ctx, key, value)
func (r *RedisClient) GetSet(ctx context.Context, key string, value interface{}) *redis.StringCmd {
return r.Db.GetSet(ctx, key, value)
}
// SetNX 如果key不存在则设置这个key的值
func (c *RedisClient) SetNX(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.BoolCmd {
return c.Db.SetNX(ctx, key, value, expiration)
func (r *RedisClient) SetNX(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.BoolCmd {
return r.Db.SetNX(ctx, key, value, expiration)
}
// MGet 批量查询key的值
func (c *RedisClient) MGet(ctx context.Context, keys ...string) *redis.SliceCmd {
return c.Db.MGet(ctx, keys...)
func (r *RedisClient) MGet(ctx context.Context, keys ...string) *redis.SliceCmd {
return r.Db.MGet(ctx, keys...)
}
// MSet 批量设置key的值
// MSet(map[string]interface{}{"key1": "value1", "key2": "value2"})
func (c *RedisClient) MSet(ctx context.Context, values map[string]interface{}) *redis.StatusCmd {
return c.Db.MSet(ctx, values)
func (r *RedisClient) MSet(ctx context.Context, values map[string]interface{}) *redis.StatusCmd {
return r.Db.MSet(ctx, values)
}
// Incr 针对一个key的数值进行递增操作
func (c *RedisClient) Incr(ctx context.Context, key string) *redis.IntCmd {
return c.Db.Incr(ctx, key)
func (r *RedisClient) Incr(ctx context.Context, key string) *redis.IntCmd {
return r.Db.Incr(ctx, key)
}
// IncrBy 针对一个key的数值进行递增操作指定每次递增多少
func (c *RedisClient) IncrBy(ctx context.Context, key string, value int64) *redis.IntCmd {
return c.Db.IncrBy(ctx, key, value)
func (r *RedisClient) IncrBy(ctx context.Context, key string, value int64) *redis.IntCmd {
return r.Db.IncrBy(ctx, key, value)
}
// Decr 针对一个key的数值进行递减操作
func (c *RedisClient) Decr(ctx context.Context, key string) *redis.IntCmd {
return c.Db.Decr(ctx, key)
func (r *RedisClient) Decr(ctx context.Context, key string) *redis.IntCmd {
return r.Db.Decr(ctx, key)
}
// DecrBy 针对一个key的数值进行递减操作指定每次递减多少
func (c *RedisClient) DecrBy(ctx context.Context, key string, value int64) *redis.IntCmd {
return c.Db.DecrBy(ctx, key, value)
func (r *RedisClient) DecrBy(ctx context.Context, key string, value int64) *redis.IntCmd {
return r.Db.DecrBy(ctx, key, value)
}
// Del 删除key操作支持批量删除
func (c *RedisClient) Del(ctx context.Context, keys ...string) *redis.IntCmd {
return c.Db.Del(ctx, keys...)
func (r *RedisClient) Del(ctx context.Context, keys ...string) *redis.IntCmd {
return r.Db.Del(ctx, keys...)
}
// Keys 按前缀获取所有 key
func (c *RedisClient) Keys(ctx context.Context, prefix string) *redis.SliceCmd {
values, _ := c.Db.Keys(ctx, prefix).Result()
func (r *RedisClient) Keys(ctx context.Context, prefix string) *redis.SliceCmd {
values, _ := r.Db.Keys(ctx, prefix).Result()
if len(values) <= 0 {
return &redis.SliceCmd{}
}
@ -72,5 +72,5 @@ func (c *RedisClient) Keys(ctx context.Context, prefix string) *redis.SliceCmd {
for _, value := range values {
keys = append(keys, value)
}
return c.MGet(ctx, keys...)
return r.MGet(ctx, keys...)
}

@ -6,26 +6,26 @@ import (
)
// Subscribe 订阅channel
func (c *RedisClient) Subscribe(ctx context.Context, channels ...string) *redis.PubSub {
return c.Db.Subscribe(ctx, channels...)
func (r *RedisClient) Subscribe(ctx context.Context, channels ...string) *redis.PubSub {
return r.Db.Subscribe(ctx, channels...)
}
// PSubscribe 订阅channel支持通配符匹配
func (c *RedisClient) PSubscribe(ctx context.Context, channels ...string) *redis.PubSub {
return c.Db.PSubscribe(ctx, channels...)
func (r *RedisClient) PSubscribe(ctx context.Context, channels ...string) *redis.PubSub {
return r.Db.PSubscribe(ctx, channels...)
}
// Publish 将信息发送到指定的channel
func (c *RedisClient) Publish(ctx context.Context, channel string, message interface{}) *redis.IntCmd {
return c.Db.Publish(ctx, channel, message)
func (r *RedisClient) Publish(ctx context.Context, channel string, message interface{}) *redis.IntCmd {
return r.Db.Publish(ctx, channel, message)
}
// PubSubChannels 查询活跃的channel
func (c *RedisClient) PubSubChannels(ctx context.Context, pattern string) *redis.StringSliceCmd {
return c.Db.PubSubChannels(ctx, pattern)
func (r *RedisClient) PubSubChannels(ctx context.Context, pattern string) *redis.StringSliceCmd {
return r.Db.PubSubChannels(ctx, pattern)
}
// PubSubNumSub 查询指定的channel有多少个订阅者
func (c *RedisClient) PubSubNumSub(ctx context.Context, channels ...string) *redis.StringIntMapCmd {
return c.Db.PubSubNumSub(ctx, channels...)
func (r *RedisClient) PubSubNumSub(ctx context.Context, channels ...string) *redis.StringIntMapCmd {
return r.Db.PubSubNumSub(ctx, channels...)
}

@ -3,6 +3,6 @@ package dorm
import "github.com/go-redis/redis/v9"
// GetDb 获取驱动
func (c *RedisClient) GetDb() *redis.Client {
return c.Db
func (r *RedisClient) GetDb() *redis.Client {
return r.Db
}

@ -11,8 +11,8 @@ type ListOperation struct {
}
// NewListOperation 列表(list)类型数据操作 https://www.tizi365.com/archives/299.html
func (c *RedisClient) NewListOperation() *ListOperation {
return &ListOperation{db: c.Db, ctx: context.Background()}
func (r *RedisClient) NewListOperation() *ListOperation {
return &ListOperation{db: r.Db, ctx: context.Background()}
}
// LPush 从列表左边插入数据

@ -24,7 +24,7 @@ type SimpleCache struct {
}
// NewSimpleCache 构造函数
func (c *RedisClient) NewSimpleCache(operation *StringOperation, expire time.Duration, serializer string) *SimpleCache {
func (r *RedisClient) NewSimpleCache(operation *StringOperation, expire time.Duration, serializer string) *SimpleCache {
return &SimpleCache{
Operation: operation, // 操作类
Expire: expire, // 过去时间

@ -15,7 +15,7 @@ type SimpleInterfaceCache struct {
}
// NewSimpleInterfaceCache 构造函数
func (c *RedisClient) NewSimpleInterfaceCache(operation *SimpleOperation, expire time.Duration) *SimpleInterfaceCache {
func (r *RedisClient) NewSimpleInterfaceCache(operation *SimpleOperation, expire time.Duration) *SimpleInterfaceCache {
return &SimpleInterfaceCache{
Operation: operation, // 操作类
Expire: expire, // 过期时间

@ -15,7 +15,7 @@ type SimpleJsonCache struct {
}
// NewSimpleJsonCache 构造函数
func (c *RedisClient) NewSimpleJsonCache(operation *StringOperation, expire time.Duration) *SimpleJsonCache {
func (r *RedisClient) NewSimpleJsonCache(operation *StringOperation, expire time.Duration) *SimpleJsonCache {
return &SimpleJsonCache{
Operation: operation, // 操作类
Expire: expire, // 过期时间

@ -11,9 +11,9 @@ type SimpleOperation struct {
ctx context.Context
}
func (c *RedisClient) NewSimpleOperation() *SimpleOperation {
func (r *RedisClient) NewSimpleOperation() *SimpleOperation {
return &SimpleOperation{
db: c.Db,
db: r.Db,
ctx: context.Background(),
}
}

@ -14,7 +14,7 @@ type SimpleStringCache struct {
}
// NewSimpleStringCache 构造函数
func (c *RedisClient) NewSimpleStringCache(operation *StringOperation, expire time.Duration) *SimpleStringCache {
func (r *RedisClient) NewSimpleStringCache(operation *StringOperation, expire time.Duration) *SimpleStringCache {
return &SimpleStringCache{
Operation: operation, // 操作类
Expire: expire, // 过期时间

@ -11,9 +11,9 @@ type StringOperation struct {
ctx context.Context
}
func (c *RedisClient) NewStringOperation() *StringOperation {
func (r *RedisClient) NewStringOperation() *StringOperation {
return &StringOperation{
db: c.Db,
db: r.Db,
ctx: context.Background(),
}
}

3
vendor/go.dtapp.net/golog/api.go generated vendored

@ -1,6 +1,7 @@
package golog
import (
"context"
"errors"
"go.dtapp.net/dorm"
"go.dtapp.net/goip"
@ -87,7 +88,7 @@ func NewApiClient(attrs ...*OperationAttr) (*ApiClient, error) {
hostname, _ := os.Hostname()
c.config.hostname = hostname
c.config.insideIp = goip.GetInsideIp()
c.config.insideIp = goip.GetInsideIp(context.Background())
c.config.goVersion = runtime.Version()
return c, nil

@ -9,6 +9,7 @@ import (
"go.dtapp.net/gourl"
"gorm.io/datatypes"
"gorm.io/gorm"
"log"
"time"
"unicode/utf8"
)
@ -63,7 +64,7 @@ func (c *ApiClient) GormMiddleware(ctx context.Context, request gorequest.Respon
if request.ResponseHeader.Get("Content-Type") == "image/jpeg" || request.ResponseHeader.Get("Content-Type") == "image/png" {
return
}
c.gormRecord(ctx, apiPostgresqlLog{
err := c.gormRecord(ctx, apiPostgresqlLog{
RequestTime: request.RequestTime, //【请求】时间
RequestUri: request.RequestUri, //【请求】链接
RequestUrl: gourl.UriParse(request.RequestUri).Url, //【请求】链接
@ -78,11 +79,14 @@ func (c *ApiClient) GormMiddleware(ctx context.Context, request gorequest.Respon
ResponseTime: request.ResponseTime, //【返回】时间
SdkVersion: sdkVersion, //【程序】Sdk版本
})
if err != nil {
log.Println("log.GormMiddleware", err.Error())
}
}
// GormMiddlewareXml 中间件
func (c *ApiClient) GormMiddlewareXml(ctx context.Context, request gorequest.Response, sdkVersion string) {
c.gormRecord(ctx, apiPostgresqlLog{
err := c.gormRecord(ctx, apiPostgresqlLog{
RequestTime: request.RequestTime, //【请求】时间
RequestUri: request.RequestUri, //【请求】链接
RequestUrl: gourl.UriParse(request.RequestUri).Url, //【请求】链接
@ -97,11 +101,14 @@ func (c *ApiClient) GormMiddlewareXml(ctx context.Context, request gorequest.Res
ResponseTime: request.ResponseTime, //【返回】时间
SdkVersion: sdkVersion, //【程序】Sdk版本
})
if err != nil {
log.Println("log.GormMiddlewareXml", err.Error())
}
}
// GormMiddlewareCustom 中间件
func (c *ApiClient) GormMiddlewareCustom(ctx context.Context, api string, request gorequest.Response, sdkVersion string) {
c.gormRecord(ctx, apiPostgresqlLog{
err := c.gormRecord(ctx, apiPostgresqlLog{
RequestTime: request.RequestTime, //【请求】时间
RequestUri: request.RequestUri, //【请求】链接
RequestUrl: gourl.UriParse(request.RequestUri).Url, //【请求】链接
@ -116,4 +123,7 @@ func (c *ApiClient) GormMiddlewareCustom(ctx context.Context, api string, reques
ResponseTime: request.ResponseTime, //【返回】时间
SdkVersion: sdkVersion, //【程序】Sdk版本
})
if err != nil {
log.Println("log.GormMiddlewareCustom", err.Error())
}
}

@ -1,3 +1,3 @@
package golog
const Version = "1.0.24"
const Version = "1.0.26"

3
vendor/go.dtapp.net/golog/gin.go generated vendored

@ -2,6 +2,7 @@ package golog
import (
"bytes"
"context"
"encoding/json"
"errors"
"github.com/gin-gonic/gin"
@ -94,7 +95,7 @@ func NewGinClient(attrs ...*OperationAttr) (*GinClient, error) {
hostname, _ := os.Hostname()
c.config.hostname = hostname
c.config.insideIp = goip.GetInsideIp()
c.config.insideIp = goip.GetInsideIp(context.Background())
c.config.goVersion = runtime.Version()
return c, nil

@ -12,6 +12,7 @@ import (
"gorm.io/datatypes"
"gorm.io/gorm"
"io/ioutil"
"log"
"net"
"time"
)
@ -132,7 +133,7 @@ func (c *GinClient) GormMiddleware() gin.HandlerFunc {
host = "https://" + ginCtx.Request.Host
}
if len(jsonBody) > 0 {
c.gormRecord(ginPostgresqlLog{
err := c.gormRecord(ginPostgresqlLog{
TraceId: gotrace_id.GetGinTraceId(ginCtx), //【系统】链编号
RequestTime: requestTime, //【请求】时间
RequestUri: host + ginCtx.Request.RequestURI, //【请求】请求链接
@ -156,8 +157,11 @@ func (c *GinClient) GormMiddleware() gin.HandlerFunc {
ResponseData: datatypes.JSON(responseBody), //【返回】数据
CostTime: endTime - startTime, //【系统】花费时间
})
if err != nil {
log.Println("log.gormRecord", err.Error())
}
} else {
c.gormRecord(ginPostgresqlLog{
err := c.gormRecord(ginPostgresqlLog{
TraceId: gotrace_id.GetGinTraceId(ginCtx), //【系统】链编号
RequestTime: requestTime, //【请求】时间
RequestUri: host + ginCtx.Request.RequestURI, //【请求】请求链接
@ -181,6 +185,9 @@ func (c *GinClient) GormMiddleware() gin.HandlerFunc {
ResponseData: datatypes.JSON(responseBody), //【返回】数据
CostTime: endTime - startTime, //【系统】花费时间
})
if err != nil {
log.Println("log.gormRecord", err.Error())
}
}
}
}()

@ -1,3 +1,3 @@
package gotrace_id
const Version = "1.0.0"
const Version = "1.0.2"

@ -19,5 +19,9 @@ func SetGinTraceIdContext(c *gin.Context) context.Context {
// GetTraceIdContext 通过上下文获取跟踪编号
func GetTraceIdContext(ctx context.Context) string {
return fmt.Sprintf("%s", ctx.Value("trace_id"))
traceId := fmt.Sprintf("%v", ctx.Value("trace_id"))
if len(traceId) <= 0 {
return ""
}
return traceId
}

@ -21,5 +21,9 @@ func SetGinTraceId() gin.HandlerFunc {
// GetGinTraceId 通过gin中间件获取跟踪编号
func GetGinTraceId(c *gin.Context) string {
return fmt.Sprintf("%s", c.MustGet("trace_id"))
traceId := fmt.Sprintf("%v", c.MustGet("trace_id"))
if len(traceId) <= 0 {
return ""
}
return traceId
}

@ -223,7 +223,7 @@ github.com/xdg-go/stringprep
# github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a
## explicit; go 1.12
github.com/youmark/pkcs8
# go.dtapp.net/dorm v1.0.17
# go.dtapp.net/dorm v1.0.19
## explicit; go 1.19
go.dtapp.net/dorm
# go.dtapp.net/goip v1.0.25
@ -235,7 +235,7 @@ go.dtapp.net/goip/v6
# go.dtapp.net/gojson v1.0.1
## explicit; go 1.18
go.dtapp.net/gojson
# go.dtapp.net/golog v1.0.24
# go.dtapp.net/golog v1.0.26
## explicit; go 1.19
go.dtapp.net/golog
# go.dtapp.net/gorandom v1.0.1
@ -250,7 +250,7 @@ go.dtapp.net/gostring
# go.dtapp.net/gotime v1.0.5
## explicit; go 1.18
go.dtapp.net/gotime
# go.dtapp.net/gotrace_id v1.0.0
# go.dtapp.net/gotrace_id v1.0.2
## explicit; go 1.19
go.dtapp.net/gotrace_id
# go.dtapp.net/gourl v1.0.0

Loading…
Cancel
Save