优化代码结构,移除未使用的依赖和冗余代码

This commit is contained in:
1
2026-01-26 14:12:12 +00:00
parent c42650145d
commit 1a95ce8c48
6 changed files with 50 additions and 27 deletions

View File

@@ -6,7 +6,6 @@ import (
"github.com/gogf/gf/v2/database/gredis"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/i18n/gi18n"
"github.com/gogf/gf/v2/os/gbuild"
"github.com/gogf/gf/v2/os/gcache"
"github.com/gogf/gf/v2/os/gctx"
"github.com/gogf/gf/v2/os/gtime"
@@ -19,9 +18,9 @@ var (
CacheEPS = gcache.New() // 定义全局缓存对象 供EPS使用
CacheManager = gcache.New() // 定义全局缓存对象 供其他业务使用
ProcessFlag = guid.S() // 定义全局进程标识
RunMode = "dev" // 定义全局运行模式
IsRedisMode = false // 定义全局是否为redis模式
I18n = gi18n.New() // 定义全局国际化对象
// RunMode = "dev" // 定义全局运行模式
IsRedisMode = false // 定义全局是否为redis模式
I18n = gi18n.New() // 定义全局国际化对象
)
func init() {
@@ -34,13 +33,13 @@ func init() {
redisConfig = &gredis.Config{}
)
Logger.Debug(ctx, "module cool init start ...", gtime.Now())
buildData := gbuild.Data()
if _, ok := buildData["mode"]; ok {
RunMode = buildData["mode"].(string)
}
if RunMode == "cool-tools" {
return
}
// buildData := gbuild.Data()
// if _, ok := buildData["mode"]; ok {
// RunMode = buildData["mode"].(string)
// }
// if RunMode == "cool-tools" {
// return
// }
redisVar, err := g.Cfg().Get(ctx, "redis.cool")
if err != nil {
Logger.Error(ctx, "初始化缓存失败,请检查配置文件")
@@ -54,7 +53,7 @@ func init() {
}
CacheManager.SetAdapter(gcache.NewAdapterRedis(redis))
IsRedisMode = true
g.DB().GetCache().SetAdapter(gcache.NewAdapterRedis(redis)) //设置数据库
// g.DB().GetCache().SetAdapter(gcache.NewAdapterRedis(redis)) //设置数据库
}
//Logerebug(ctx, "当前运行模式", RunMode)
Logger.Debug(ctx, "当前实例ID:", ProcessFlag)

View File

@@ -7,7 +7,6 @@ import (
"sync"
"github.com/mhmtszr/concurrent-swiss-map/maphash"
"github.com/panjf2000/ants/v2"
"github.com/mhmtszr/concurrent-swiss-map/swiss"
)
@@ -17,7 +16,7 @@ type CsMap[K comparable, V any] struct {
shards []shard[K, V]
shardCount uint64
size uint64
pool *ants.Pool
//pool *ants.Pool
}
type HashShardPair[K comparable, V any] struct {
@@ -48,7 +47,7 @@ func New[K comparable, V any](options ...OptFunc[K, V]) *CsMap[K, V] {
for i := 0; i < int(m.shardCount); i++ {
m.shards[i] = shard[K, V]{items: swiss.NewMap[K, V](uint32((m.size / m.shardCount) + 1)), RWMutex: &sync.RWMutex{}}
}
m.pool, _ = ants.NewPool(-1)
//m.pool, _ = ants.NewPool(-1)
return &m
}