Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Add DecodeHooks also to "unmarshaling" env variables" #890

Open
sagikazarmark opened this issue Apr 9, 2020 · 0 comments
Open

"Add DecodeHooks also to "unmarshaling" env variables" #890

sagikazarmark opened this issue Apr 9, 2020 · 0 comments

Comments

@sagikazarmark
Copy link
Collaborator

sagikazarmark commented Apr 9, 2020

Moved here from #772, commented by @stepanselyuk:


I don't know how to formulate a behavior, but an example:
when I use a config file (e.g. YAML) with a key:

blocked_countries:
    eu: [AT,BE,BG,CY,CZ,DE,DK,EE,ES,FI,FR,GB,GR,HU,HR,IE,IT,LT,LU,LV,MT,NL,PL,PT,RO,SE,SI,SK]
    xx: [XX]

it reads that as:

"blocked_countries": map[string]interface {}{
            "xx": []interface {}{
                "XX",
            },
            "eu": []interface {}{
                "AT",
                "BE",
                "BG",
                "CY",
                "CZ",
                "DE",
                "DK",
                "EE",
                "ES",
                "FI",
                "FR",
                "GB",
                "GR",
                "HU",
                "HR",
                "IE",
                "IT",
                "LT",
                "LU",
                "LV",
                "MT",
                "NL",
                "PL",
                "PT",
                "RO",
                "SE",
                "SI",
                "SK",
            },
        },

but I want to rewrite this value using env variable: BLOCKED_COUNTRIES, and by the idea I should specify a json there, like {"eu":["DE","DK"]}, but it won't work, the blocked_countries won't be presented in viper.AllSettings(). I can affect the value only partially by using e.g. export BLOCKED_COUNTRIES_EU=DE,DK.

There is an option (#641) to specify DecodeHook, but only for unmarshaling. But on the step when I want to unmarshal what viper has into a struct, viper already does not have blocked_countries key using AllSettings(), though I can access a raw value of it using viper.Get("blocked_countries").

So my request is to add DecodeHooks also to "unmarshaling" env variables.

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

No branches or pull requests

1 participant