mitchellh / mapstructure

Go library for decoding generic map values into native Go structures and vice versa.
https://gist.github.com/mitchellh/90029601268e59a29e64e55bab1c5bdc
MIT License
7.93k stars 677 forks source link

feat: squash with prefix #288

Open kamilsk opened 2 years ago

kamilsk commented 2 years ago

Hi! What do you think about the possibility of adding prefix support while squashing structs?

Example:

type Bitbucket struct {
    Token config.Secret `mapstructure:"token"`
}

type GitHub struct {
    Token config.Secret `mapstructure:"token"`
}

type Service struct {
    Bitbucket `mapstructure:"bitbucket,squash"`
    GitHub    `mapstructure:"github,prefix"`
}
BITBUCKET_TOKEN=secret
GITHUB_TOKEN=secret

Now, I'm using the following workaround https://github.com/octomation/maintainer/blob/af46d826f7c070347b26fa46efee6dbdee4f8be3/internal/config/tool.go#L53-L64 but want to contribute to mapstructure the possibility to add prefix if squash it has.