Closed bynil closed 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)
encoding.TextUnmarshaler
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.
Setter
How about trying encoding.TextUnmarshaler if we cannot find a proper unmarshal way?
Seems that custom types will be ignored when read env-default.
env-default
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 becauseSetter
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?