Compare commits

..

4 Commits

Author SHA1 Message Date
f70f8d94db fix(with): 修复 memory.go 中的配置初始化错误
将 bigcache.Config 结构体实例改为指针传递,确保配置能够正确初始化和传递。
2025-09-20 11:32:24 +08:00
257f0a6b6e fix(with): 优化 memory cache 配置初始化逻辑
移除未使用的 `encoding/json` 包导入。
调整配置初始化方式,避免不必要的结构体拷贝。
改进日志输出内容,仅显示关键配置项。
2025-09-20 11:21:02 +08:00
5e25e8eccc fix(with/etcd): 修改Etcd配置为空时的处理逻辑
当Etcd配置或端点为空时,将panic改为直接返回,避免程序崩溃
2025-09-20 11:08:47 +08:00
4f584726d6 ```
refactor(with): 调整Memory函数参数顺序

将Memory函数的参数顺序从(opts, cli)调整为(cli, opts),
使函数签名更加符合常规的客户端优先参数排列习惯,
提升代码可读性和一致性。
```
2025-09-20 10:59:45 +08:00
2 changed files with 16 additions and 20 deletions

View File

@@ -13,7 +13,7 @@ import (
func Etcd(cfg *conf.EtcdConf, cli *clientv3.Client) { func Etcd(cfg *conf.EtcdConf, cli *clientv3.Client) {
if cfg == nil || len(cfg.Endpoints) == 0 { if cfg == nil || len(cfg.Endpoints) == 0 {
panic("Etcd endpoints is Empty!") return
} }
etcdCfg := clientv3.Config{ etcdCfg := clientv3.Config{

View File

@@ -2,7 +2,6 @@ package with
import ( import (
"context" "context"
"encoding/json"
"time" "time"
"git.apinb.com/bsm-sdk/core/print" "git.apinb.com/bsm-sdk/core/print"
@@ -10,30 +9,27 @@ import (
"github.com/allegro/bigcache/v3" "github.com/allegro/bigcache/v3"
) )
func Memory(opts *bigcache.Config, cli *bigcache.BigCache) { func Memory(cli *bigcache.BigCache, opts *bigcache.Config) {
config := bigcache.Config{ if opts == nil {
Shards: 1024, opts = &bigcache.Config{
LifeWindow: 10 * time.Minute, Shards: 1024,
CleanWindow: 5 * time.Minute, LifeWindow: 10 * time.Minute,
MaxEntriesInWindow: 1000 * 10 * 60, CleanWindow: 5 * time.Minute,
MaxEntrySize: 500, MaxEntriesInWindow: 1000 * 10 * 60,
Verbose: true, MaxEntrySize: 500,
HardMaxCacheSize: 8192, Verbose: true,
OnRemove: nil, HardMaxCacheSize: 8192,
OnRemoveWithReason: nil, OnRemove: nil,
} OnRemoveWithReason: nil,
}
if opts != nil {
config = *opts
} }
var err error var err error
cli, err = bigcache.New(context.Background(), config) cli, err = bigcache.New(context.Background(), *opts)
if err != nil { if err != nil {
print.Error("Memory Cache Fatal Error") print.Error("Memory Cache Fatal Error")
panic(err) panic(err)
} }
jsonBytes, _ := json.Marshal(config) print.Success("[BSM - %s] Memory Cache: Shards=%d, MaxEntrySize=%d", vars.ServiceKey, opts.Shards, opts.MaxEntrySize)
print.Success("[BSM - %s] Memory Cache: %s", vars.ServiceKey, jsonBytes)
} }