- 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 ab5bb603c9
commit 2150d671be

@ -8,4 +8,4 @@ const (
logTable = "wechatopen" logTable = "wechatopen"
) )
const Version = "1.0.9" const Version = "1.0.10"

@ -4,8 +4,8 @@ go 1.19
require ( require (
github.com/mitchellh/mapstructure v1.5.0 github.com/mitchellh/mapstructure v1.5.0
go.dtapp.net/dorm v1.0.17 go.dtapp.net/dorm v1.0.19
go.dtapp.net/golog v1.0.24 go.dtapp.net/golog v1.0.26
go.dtapp.net/gorequest v1.0.26 go.dtapp.net/gorequest v1.0.26
gorm.io/gorm v1.23.8 gorm.io/gorm v1.23.8
) )
@ -63,12 +63,12 @@ require (
github.com/xdg-go/scram v1.1.1 // indirect github.com/xdg-go/scram v1.1.1 // indirect
github.com/xdg-go/stringprep v1.0.3 // indirect github.com/xdg-go/stringprep v1.0.3 // indirect
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
go.dtapp.net/goip v1.0.24 // indirect go.dtapp.net/goip v1.0.25 // indirect
go.dtapp.net/gojson v1.0.1 // indirect go.dtapp.net/gojson v1.0.1 // indirect
go.dtapp.net/gorandom v1.0.1 // indirect go.dtapp.net/gorandom v1.0.1 // indirect
go.dtapp.net/gostring v1.0.6 // indirect go.dtapp.net/gostring v1.0.6 // indirect
go.dtapp.net/gotime v1.0.5 // 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/gourl v1.0.0 // indirect
go.dtapp.net/goxml v1.0.1 // indirect go.dtapp.net/goxml v1.0.1 // indirect
go.mongodb.org/mongo-driver v1.10.1 // indirect go.mongodb.org/mongo-driver v1.10.1 // indirect

@ -502,14 +502,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/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q= 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= 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.19 h1:3uH4tYZ5zH4knx9o6BJlE3rFiWNWTyMxlpt0Cwoq7zE=
go.dtapp.net/dorm v1.0.17/go.mod h1:bHG7BmgeLaAlc56myYF63lwZAIuMeWRAqHBb/L84dLM= go.dtapp.net/dorm v1.0.19/go.mod h1:bHG7BmgeLaAlc56myYF63lwZAIuMeWRAqHBb/L84dLM=
go.dtapp.net/goip v1.0.24 h1:62k3xt9I/YLUwA5tLp7YC8XPskkswc4RJrvxRRxjwIY= go.dtapp.net/goip v1.0.25 h1:GSgQkR7dc28TX8E1mF3wAy+EEGZ++tgqc8Q85OKZPEY=
go.dtapp.net/goip v1.0.24/go.mod h1:tps0yoq5kSykLGDb01vuai47hzAQ6nYUPFWLdlQA2Oo= 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 h1:MHeSGlq1KxzL7rCkm18fhwW4GNORHohdDMmxY5PupKY=
go.dtapp.net/gojson v1.0.1/go.mod h1:TkkpTNxHBKxul0e7gC5MrL1K4ICFB9mQ7wHzjBah3/k= 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.26 h1:EmUA/QwtQcX57tyTL73H92zJeObJDuTcUqE01MI3v1A=
go.dtapp.net/golog v1.0.24/go.mod h1:P1CFwGZ6xm2nLXCi0DTwO8aHNfT2dkdjz+9b2ph1TNQ= 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 h1:IWfMClh1ECPvyUjlqD7MwLq4mZdUusD1qAwAdsvEJBs=
go.dtapp.net/gorandom v1.0.1/go.mod h1:ZPdgalKpvFV/ATQqR0k4ns/F/IpITAZpx6WkWirr5Y8= go.dtapp.net/gorandom v1.0.1/go.mod h1:ZPdgalKpvFV/ATQqR0k4ns/F/IpITAZpx6WkWirr5Y8=
go.dtapp.net/gorequest v1.0.26 h1:t+rMW7liLHz1RgY60ztWIghSkTeQePKWM0EsDG1IqMI= go.dtapp.net/gorequest v1.0.26 h1:t+rMW7liLHz1RgY60ztWIghSkTeQePKWM0EsDG1IqMI=
@ -518,8 +518,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/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 h1:12aNgB2ULpP6QgQHEUkLilZ4ASvhpFxMFQkBwn0par8=
go.dtapp.net/gotime v1.0.5/go.mod h1:Gq7eNLr2iMLP18UNWONRq4V3Uhf/ADp4bIrS+Tc6ktY= 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.2 h1:wSc7dYzkAwSz3MbPu2Io4XqHe0l0dIaJe3vlpDAZrXY=
go.dtapp.net/gotrace_id v1.0.0/go.mod h1:HDwMY1vLoC759z6VGKVgCpIqwKQTDYV9DNdxiyN1OeQ= 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 h1:Zbe0GiMFyyRy2+bjbVsYulakH5d58w3CDZkUPonlMoQ=
go.dtapp.net/gourl v1.0.0/go.mod h1:x9A/pJ3iKDTb6Gu2RtJy2iHg56IowXIcIGQdogqpGjs= go.dtapp.net/gourl v1.0.0/go.mod h1:x9A/pJ3iKDTb6Gu2RtJy2iHg56IowXIcIGQdogqpGjs=
go.dtapp.net/goxml v1.0.1 h1:WODsjNpmHTtoeLsXgOjC81qRbu4aXZ3LKBHApNGaPjY= go.dtapp.net/goxml v1.0.1 h1:WODsjNpmHTtoeLsXgOjC81qRbu4aXZ3LKBHApNGaPjY=

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

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

@ -6,32 +6,39 @@ import (
"time" "time"
) )
// GttStringFunc String缓存结构
type GttStringFunc func() string
// GttInterfaceFunc Interface缓存结构
type GttInterfaceFunc func() interface{}
// RedisCacheConfig 配置 // RedisCacheConfig 配置
type RedisCacheConfig struct { type RedisCacheConfig struct {
DefaultExpiration time.Duration // 过期时间 Expiration time.Duration // 过期时间
} }
// RedisClientCache https://github.com/go-redis/redis // RedisClientCache https://github.com/go-redis/redis
type RedisClientCache struct { type RedisClientCache struct {
config *RedisCacheConfig defaultExpiration time.Duration // 过期时间
operation *RedisClient // 操作 operation *RedisClient // 操作
GetterString func() string // 不存在的操作 GetterString GttStringFunc // 不存在的操作
GetterInterface func() interface{} // 不存在的操作 GetterInterface GttInterfaceFunc // 不存在的操作
} }
// NewCache 实例化 // NewCache 实例化
func (c *RedisClient) NewCache(config *RedisCacheConfig) *RedisClientCache { func (r *RedisClient) NewCache(config *RedisCacheConfig) *RedisClientCache {
cc := &RedisClientCache{config: config} return &RedisClientCache{
cc.operation = c defaultExpiration: config.Expiration,
return cc operation: r,
}
} }
// NewCacheDefaultExpiration 实例化 // NewCacheDefaultExpiration 实例化
func (c *RedisClient) NewCacheDefaultExpiration() *RedisClientCache { func (r *RedisClient) NewCacheDefaultExpiration() *RedisClientCache {
cc := &RedisClientCache{} return &RedisClientCache{
cc.config.DefaultExpiration = time.Minute * 30 // 默认过期时间 defaultExpiration: time.Minute * 30,
cc.operation = c operation: r,
return cc }
} }
// GetString 缓存操作 // GetString 缓存操作
@ -44,7 +51,7 @@ func (rc *RedisClientCache) GetString(ctx context.Context, key string) (ret stri
// 如果不存在则调用GetterString // 如果不存在则调用GetterString
ret, err := rc.operation.Get(ctx, key).Result() ret, err := rc.operation.Get(ctx, key).Result()
if err != nil { 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() 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() ret, err := rc.operation.Get(ctx, key).Result()
if err != nil { 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() ret, _ = rc.operation.Get(ctx, key).Result()
} }
@ -71,3 +78,19 @@ func (rc *RedisClientCache) GetInterface(ctx context.Context, key string, result
return 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的值 // Set 设置一个key的值
func (c *RedisClient) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.StatusCmd { func (r *RedisClient) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.StatusCmd {
return c.Db.Set(ctx, key, value, expiration) return r.Db.Set(ctx, key, value, expiration)
} }
// Get 查询key的值 // Get 查询key的值
func (c *RedisClient) Get(ctx context.Context, key string) *redis.StringCmd { func (r *RedisClient) Get(ctx context.Context, key string) *redis.StringCmd {
return c.Db.Get(ctx, key) return r.Db.Get(ctx, key)
} }
// GetSet 设置一个key的值并返回这个key的旧值 // GetSet 设置一个key的值并返回这个key的旧值
func (c *RedisClient) GetSet(ctx context.Context, key string, value interface{}) *redis.StringCmd { func (r *RedisClient) GetSet(ctx context.Context, key string, value interface{}) *redis.StringCmd {
return c.Db.GetSet(ctx, key, value) return r.Db.GetSet(ctx, key, value)
} }
// SetNX 如果key不存在则设置这个key的值 // SetNX 如果key不存在则设置这个key的值
func (c *RedisClient) SetNX(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.BoolCmd { func (r *RedisClient) SetNX(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.BoolCmd {
return c.Db.SetNX(ctx, key, value, expiration) return r.Db.SetNX(ctx, key, value, expiration)
} }
// MGet 批量查询key的值 // MGet 批量查询key的值
func (c *RedisClient) MGet(ctx context.Context, keys ...string) *redis.SliceCmd { func (r *RedisClient) MGet(ctx context.Context, keys ...string) *redis.SliceCmd {
return c.Db.MGet(ctx, keys...) return r.Db.MGet(ctx, keys...)
} }
// MSet 批量设置key的值 // MSet 批量设置key的值
// MSet(map[string]interface{}{"key1": "value1", "key2": "value2"}) // MSet(map[string]interface{}{"key1": "value1", "key2": "value2"})
func (c *RedisClient) MSet(ctx context.Context, values map[string]interface{}) *redis.StatusCmd { func (r *RedisClient) MSet(ctx context.Context, values map[string]interface{}) *redis.StatusCmd {
return c.Db.MSet(ctx, values) return r.Db.MSet(ctx, values)
} }
// Incr 针对一个key的数值进行递增操作 // Incr 针对一个key的数值进行递增操作
func (c *RedisClient) Incr(ctx context.Context, key string) *redis.IntCmd { func (r *RedisClient) Incr(ctx context.Context, key string) *redis.IntCmd {
return c.Db.Incr(ctx, key) return r.Db.Incr(ctx, key)
} }
// IncrBy 针对一个key的数值进行递增操作指定每次递增多少 // IncrBy 针对一个key的数值进行递增操作指定每次递增多少
func (c *RedisClient) IncrBy(ctx context.Context, key string, value int64) *redis.IntCmd { func (r *RedisClient) IncrBy(ctx context.Context, key string, value int64) *redis.IntCmd {
return c.Db.IncrBy(ctx, key, value) return r.Db.IncrBy(ctx, key, value)
} }
// Decr 针对一个key的数值进行递减操作 // Decr 针对一个key的数值进行递减操作
func (c *RedisClient) Decr(ctx context.Context, key string) *redis.IntCmd { func (r *RedisClient) Decr(ctx context.Context, key string) *redis.IntCmd {
return c.Db.Decr(ctx, key) return r.Db.Decr(ctx, key)
} }
// DecrBy 针对一个key的数值进行递减操作指定每次递减多少 // DecrBy 针对一个key的数值进行递减操作指定每次递减多少
func (c *RedisClient) DecrBy(ctx context.Context, key string, value int64) *redis.IntCmd { func (r *RedisClient) DecrBy(ctx context.Context, key string, value int64) *redis.IntCmd {
return c.Db.DecrBy(ctx, key, value) return r.Db.DecrBy(ctx, key, value)
} }
// Del 删除key操作支持批量删除 // Del 删除key操作支持批量删除
func (c *RedisClient) Del(ctx context.Context, keys ...string) *redis.IntCmd { func (r *RedisClient) Del(ctx context.Context, keys ...string) *redis.IntCmd {
return c.Db.Del(ctx, keys...) return r.Db.Del(ctx, keys...)
} }
// Keys 按前缀获取所有 key // Keys 按前缀获取所有 key
func (c *RedisClient) Keys(ctx context.Context, prefix string) *redis.SliceCmd { func (r *RedisClient) Keys(ctx context.Context, prefix string) *redis.SliceCmd {
values, _ := c.Db.Keys(ctx, prefix).Result() values, _ := r.Db.Keys(ctx, prefix).Result()
if len(values) <= 0 { if len(values) <= 0 {
return &redis.SliceCmd{} return &redis.SliceCmd{}
} }
@ -72,5 +72,5 @@ func (c *RedisClient) Keys(ctx context.Context, prefix string) *redis.SliceCmd {
for _, value := range values { for _, value := range values {
keys = append(keys, value) keys = append(keys, value)
} }
return c.MGet(ctx, keys...) return r.MGet(ctx, keys...)
} }

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

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

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

@ -24,7 +24,7 @@ type SimpleCache struct {
} }
// NewSimpleCache 构造函数 // 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{ return &SimpleCache{
Operation: operation, // 操作类 Operation: operation, // 操作类
Expire: expire, // 过去时间 Expire: expire, // 过去时间

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

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

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

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

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

@ -5,5 +5,4 @@
.vscode .vscode
*.log *.log
gomod.sh gomod.sh
/vendor/
download_test.go download_test.go

@ -2,7 +2,7 @@
<a href="https://www.dtapp.net/">Golang Ip</a> <a href="https://www.dtapp.net/">Golang Ip</a>
</h1> </h1>
📦 Golang Ip 📦 Golang Ip
[comment]: <> (go) [comment]: <> (go)
[![godoc](https://pkg.go.dev/badge/go.dtapp.net/goip?status.svg)](https://pkg.go.dev/go.dtapp.net/goip) [![godoc](https://pkg.go.dev/badge/go.dtapp.net/goip?status.svg)](https://pkg.go.dev/go.dtapp.net/goip)
@ -22,17 +22,18 @@ go get -v -u go.dtapp.net/goip
package main package main
import ( import (
"context"
"go.dtapp.net/goip" "go.dtapp.net/goip"
"testing" "testing"
) )
func TestGoIp(t *testing.T) { func TestGoIp(t *testing.T) {
// 获取Mac地址 // 获取Mac地址
t.Log(goip.GetMacAddr()) t.Log(goip.GetMacAddr(context.Background()))
// 内网ip // 内网ip
t.Log(goip.GetInsideIp()) t.Log(goip.GetInsideIp(context.Background()))
// 外网ip // 外网ip
t.Log(goip.GetOutsideIp()) t.Log(goip.GetOutsideIp(context.Background()))
} }
``` ```

@ -1,3 +1,3 @@
package goip package goip
const Version = "1.0.24" const Version = "1.0.25"

11
vendor/go.dtapp.net/goip/ip.go generated vendored

@ -1,13 +1,14 @@
package goip package goip
import ( import (
"context"
"encoding/json" "encoding/json"
"go.dtapp.net/gorequest" "go.dtapp.net/gorequest"
"net" "net"
) )
// GetInsideIp 内网ip // GetInsideIp 内网ip
func GetInsideIp() string { func GetInsideIp(ctx context.Context) string {
conn, err := net.Dial("udp", "8.8.8.8:80") conn, err := net.Dial("udp", "8.8.8.8:80")
if err != nil { if err != nil {
panic(err) panic(err)
@ -19,7 +20,7 @@ func GetInsideIp() string {
} }
// Ips 获取全部网卡的全部IP // Ips 获取全部网卡的全部IP
func Ips() (map[string]string, error) { func Ips(ctx context.Context) (map[string]string, error) {
ips := make(map[string]string) ips := make(map[string]string)
@ -53,11 +54,11 @@ var respGetOutsideIp struct {
} }
// GetOutsideIp 外网ip // GetOutsideIp 外网ip
func GetOutsideIp() (ip string) { func GetOutsideIp(ctx context.Context) (ip string) {
ip = "0.0.0.0" ip = "0.0.0.0"
get := gorequest.NewHttp() get := gorequest.NewHttp()
get.SetUri("https://api.dtapp.net/ip") get.SetUri("https://api.dtapp.net/ip")
response, err := get.Get() response, err := get.Get(ctx)
if err != nil { if err != nil {
return return
} }
@ -73,7 +74,7 @@ func GetOutsideIp() (ip string) {
} }
// GetMacAddr 获取Mac地址 // GetMacAddr 获取Mac地址
func GetMacAddr() (arrays []string) { func GetMacAddr(ctx context.Context) (arrays []string) {
netInterfaces, err := net.Interfaces() netInterfaces, err := net.Interfaces()
if err != nil { if err != nil {
return arrays return arrays

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

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

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

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

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

@ -1,3 +1,3 @@
package gotrace_id 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 通过上下文获取跟踪编号 // GetTraceIdContext 通过上下文获取跟踪编号
func GetTraceIdContext(ctx context.Context) string { 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中间件获取跟踪编号 // GetGinTraceId 通过gin中间件获取跟踪编号
func GetGinTraceId(c *gin.Context) string { 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
} }

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

Loading…
Cancel
Save