ilyakaznacheev / cleanenv

✨Clean and minimalistic environment configuration reader for Golang
MIT License
1.66k stars 115 forks source link

Support encoding.TextUnmarshaler #121

Closed bynil closed 1 year ago

bynil commented 1 year ago

Many struct types in third-party libraries support encoding.TextUnmarshaler interface to fill the value by itself. (eg. https://github.com/shopspring/decimal/blob/f55dd564545cec84cf84f7a53fb3025cdbec1c4f/decimal.go#L1429)

And yaml parser will unmarshal it. https://github.com/go-yaml/yaml/blob/00bbc0947ae889b9e480044dbc3bc3e3216a6a89/decode.go#L591-L609

Setter interface is not perfect because Setter is a custom interface we have to wrap the third-party type.

How about trying encoding.TextUnmarshaler if we cannot find a proper unmarshal way?

bynil commented 1 year ago

Seems that custom types will be ignored when read env-default.