Closed arne-cl closed 6 years ago
Hi @arne-cl
Custom type support comes with TOML parser. You just need a duration type that satisfies the encoding.TextUnmarshaler interface:
type Config struct { // sample config struct
Tick duration
}
type duration struct {
time.Duration
}
func (d *duration) UnmarshalText(text []byte) error {
var err error
d.Duration, err = time.ParseDuration(string(text))
return err
}
Hi @cihangir,
thank you for responding so quickly. If I understand you correctly, I would need to add code to make this work with TOML while it works out of the box with ENV or commandline parameters. Is there a reason for this or could I implement it for TOML and make a pull request?
Best regards, Arne
Dear @cihangir, thank you for your help! I'll see if I can get this feature into BurntSushi/toml somehow.
Support for
time.Duration
was added in #28, but its usage is inconsistent between the different loaders. While it is possible to specify a duration as10s
as an ENV variable, the same is not possible e.g. for TOML files. Here, you'd have to set the same duration as10000000000
.