config icon indicating copy to clipboard operation
config copied to clipboard

ParseDeafult does not working with ParseTime

Open b1p0lar-bear opened this issue 10 months ago • 2 comments

System:

  • OS: Windows 11
  • GO Version: 1.24
  • Pkg Version: 2.2.6

Describe the bug

If I have value with type time.Duartion and defined default value from tag in my config, I get parsing error on struct binding. To Reproduce

type TestConfig struct {
	WithDefault time.Duration `default:"10s"`
}

func main() {
	config.WithOptions(
		config.ParseTime,
		config.ParseDefault,
	)
	config.AddDriver(yaml.Driver)
	config.LoadFiles("./test.yaml")
	cfg := TestConfig{}
	if err := config.BindStruct("", &cfg); err != nil {
		fmt.Println(err.Error())
	}
}

Image

b1p0lar-bear avatar Apr 25 '25 11:04 b1p0lar-bear

:( Currently, default does not support automatic parsing of time strings.

inhere avatar Apr 25 '25 12:04 inhere

:( Currently, default does not support automatic parsing of time strings.

Any chance you have plans to add such support in near future? :)

b1p0lar-bear avatar Apr 25 '25 12:04 b1p0lar-bear

@b1p0lar-bear will add support on next version:

Image

inhere avatar Jun 23 '25 02:06 inhere