Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何将config配置文件的默认值保存为一个默认配置文件? #187

Open
M09Ic opened this issue Feb 11, 2024 · 0 comments
Open
Labels
enhancement New feature or request question Further information is requested

Comments

@M09Ic
Copy link

M09Ic commented Feb 11, 2024

type Option struct {
	Test            string `config:"test"`
}

func TestConfig(t *testing.T) {
	var opt Option
	opt.Test = "test"
	con := config.New("test", func(opt *config.Options) {
		opt.DecoderConfig.TagName = "config"
		opt.ParseDefault = true
	})

	con.AddDriver(yaml.Driver)
	err := con.BindStruct("", &opt)
	var buf bytes.Buffer
	_, err = con.DumpTo(&buf, config.Yaml)
	if err != nil {
		return
	}
	fmt.Println(buf.String())
}

这段代码不生效, buf中没有任何数据.

如果可以, 是否可以提供一组更方便的api, 例如:

  • 允许设置defualt config 文件, 如果不存在则创建, 如果存在则自动加载
  • 允许将defualt的值自动填入default config 文件中
@inhere inhere added enhancement New feature or request question Further information is requested labels Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants