Implement a custom value setter
masterTo allow a custom type to be populated from an environment variable, implement the Setter interface. The SetValue method should handle the conversion from a string to your custom type.
type MyField string
func (f *MyField) SetValue(s string) error {
if s == "" {
return fmt.Errorf("field value can't be empty")
}
*f = MyField("my field is: " + s)
return nil
}
type Config struct {
Field MyField `env="MY_VALUE"`
}