Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions config/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ func (g *GlobalConfig) Init() {
slog.Info("config initialized")
}

func NewGlobalConfig() *GlobalConfig {
// defaultGlobalConfig 返回纯代码默认值,不读取配置文件、不解析命令行。
// NewGlobalConfig 在其上叠加 Init()(文件覆盖) 与 ParseFlags()(命令行覆盖)。
func defaultGlobalConfig() *GlobalConfig {
logDir := defaultLogDir()
global := &GlobalConfig{
return &GlobalConfig{

Name: "Raft",
Port: 8080,
Expand All @@ -116,6 +118,10 @@ func NewGlobalConfig() *GlobalConfig {
RaftSnapshotThreshold: 1000, // 默认快照阈值
RaftSnapshotKeepEntries: 100, // 默认保留条目数
}
}

func NewGlobalConfig() *GlobalConfig {
global := defaultGlobalConfig()
global.Init()
global.ParseFlags()
return global
Expand Down
4 changes: 3 additions & 1 deletion config/global_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ func TestParseFlagsPriority(t *testing.T) {
}

func TestDefaultConfigValues(t *testing.T) {
g := NewGlobalConfig()
// 测纯代码默认值:用 defaultGlobalConfig() 而非 NewGlobalConfig(),
// 后者会被 config.json 覆盖,使本测试依赖文件是否存在/内容(非 hermetic)。
g := defaultGlobalConfig()

expectedDefaults := []struct {
name string
Expand Down
Loading