Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

mapstructure fails to unmarshal when the type is string slice #289

Open
pantelis-karamolegkos opened this issue May 29, 2022 · 0 comments
Open

Comments

@pantelis-karamolegkos
Copy link

pantelis-karamolegkos commented May 29, 2022

Although came across this when using viper, I believe this is a mapstructure issue

I am defining a slice flag as follows

fs.StringArray(name, sliceValue, help)

where sliceValue: = []string{"PUT", "POST"}

The corresponding Config struct field is the following

CORSAllowMethods []string `mapstructure:"CORS_ALLOW_METHODS" name:"cors-allow-methods" long:"cors-allow-methods" defaultValue:"PUT POST" help:"List of CORS methods that are allowed"`

After performing a v.Unmarshal(&conf) was expecting something like this:

CORSAllowMethods:[PUT POST]

The end result after v.Unmarshal(&conf) is

CORSAllowMethods:[[PUT POST]]

(a nested slice???!!!)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant