Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
JellyTony committed Mar 14, 2024
1 parent 6e27a53 commit 6a2890d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 13 deletions.
33 changes: 23 additions & 10 deletions api/config/v1/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions api/config/v1/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ message Nacos {
string log_level = 11;
// nacos format, default=yaml
string format = 12;
// not load cache at
bool not_load_cache_at_start = 13;
}

// middleware config
Expand Down
31 changes: 28 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import (
"github.com/nacos-group/nacos-sdk-go/v2/clients"
"github.com/nacos-group/nacos-sdk-go/v2/common/constant"
"github.com/nacos-group/nacos-sdk-go/v2/vo"
"github.com/nextmicro/logger"
"github.com/nextmicro/next/adapter/config/nacos"
"github.com/nextmicro/next/adapter/logger/kratos"
adapterNacos "github.com/nextmicro/next/adapter/logger/nacos"
"github.com/nextmicro/next/api/config/v1"
util "github.com/nextmicro/next/internal/pkg/file"
kUtil "github.com/nextmicro/next/pkg/env"
Expand Down Expand Up @@ -67,9 +70,14 @@ func (c *Config) buildNacosSource() ([]kConfig.Source, error) {
}

if cfg.GetCacheDir() == "" && kUtil.IsDev() {
cfg.CacheDir = fmt.Sprintf("%s/runtime/nacos", kUtil.WorkDir())
cfg.CacheDir = fmt.Sprintf("%s/runtime/nacos/cache", kUtil.WorkDir())
} else if cfg.GetCacheDir() == "" {
cfg.CacheDir = fmt.Sprintf("/data/nacos/%s", cfg.DataId)
cfg.CacheDir = fmt.Sprintf("/data/nacos/%s/cache", cfg.DataId)
}
if cfg.GetLogDir() == "" && kUtil.IsDev() {
cfg.LogDir = fmt.Sprintf("%s/runtime/nacos/log", kUtil.WorkDir())
} else if cfg.GetLogDir() == "" {
cfg.CacheDir = fmt.Sprintf("/data/nacos/%s/log", cfg.DataId)
}

if cfg.CacheDir != "" {
Expand All @@ -84,6 +92,18 @@ func (c *Config) buildNacosSource() ([]kConfig.Source, error) {
}
}
}
if cfg.LogDir != "" {
// 判断备份目录是否存在
exists, err := util.Exists(cfg.LogDir)
if err != nil {
return nil, fmt.Errorf("failed to check log dir path: %s, error: %s", cfg.LogDir, err)
}
if !exists {
if err := os.MkdirAll(cfg.LogDir, 0755); err != nil {
return nil, fmt.Errorf("failed to create log dir path: %s, error: %s", cfg.CacheDir, err)
}
}
}

serverConfigs := make([]constant.ServerConfig, 0)
for _, addr := range cfg.Address {
Expand Down Expand Up @@ -119,8 +139,9 @@ func (c *Config) buildNacosSource() ([]kConfig.Source, error) {
constant.WithTimeoutMs(duration),
constant.WithCacheDir(cfg.GetCacheDir()),
constant.WithNamespaceId(cfg.GetNamespace()),
constant.WithNotLoadCacheAtStart(true),
constant.WithNotLoadCacheAtStart(cfg.NotLoadCacheAtStart),
constant.WithLogLevel(cfg.LogLevel),
constant.WithLogDir(cfg.LogDir),
constant.WithOpenKMS(false),
)
client, err := clients.NewConfigClient(
Expand All @@ -129,6 +150,8 @@ func (c *Config) buildNacosSource() ([]kConfig.Source, error) {
ServerConfigs: serverConfigs,
},
)

adapterNacos.NewNacos(logger.DefaultLogger).SetLogger() // adapter nacos logger
if err != nil {
return nil, fmt.Errorf("failed to create nacos client, error: %s", err)
}
Expand All @@ -145,6 +168,8 @@ func Init(filename string) (kConfig.Config, error) {
filename: filename,
}

kratos.New(logger.DefaultLogger).SetLogger() // adapter kratos logger

// build file source
source := cc.buildFileSource()

Expand Down

0 comments on commit 6a2890d

Please sign in to comment.