Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    cesco
    @cescoferraro
    is there a way to make flag mandatory? @spf13
    Cameron Moore
    @moorereason
    @cescoferraro, use if.
    cesco
    @cescoferraro
    am doing that @moorereason I was wondering an embedded way
    Steve Francia
    @spf13
    @cescoferraro I don't think there is. It begs the question of why you have a flag that is required though. It seems like a bad design. Flags should modify actions.
    Luis Sebastian Urrutia Fuentes
    @LuisUrrutia
    AddConfigPath doesn't works for me, #192
    cesco
    @cescoferraro
    @spf13 is a hardware project based on the rpi. if it tries to run all the code without the proper hardware, it all crashes. I just want to avoid that by explicitly saying what "guns" it has.Anyway, thanks!
    Steve Francia
    @spf13
    @cescoferraro it's totally doable, but it's not built into Viper. I think it encourages a bad pattern, though there are obviously cases where it's appropriate and it's pretty trivial to add conditionals to handle these.
    Brian Hicks
    @BrianHicks
    hey, is there a recommended workaround for spf13/viper#112 It's biting me ATM and it'd be super handy to not have to deal with.
    Timo Reimann
    @timoreimann
    I'd like to test a piece of code that calls viper.UnmarshalKey(). How would I inject a custom value? I tried using viper.Set() but fail to pass something that viper/mapstructure considers unmarshalable.
    Timo Reimann
    @timoreimann
    nevermind, I got it: the referenced key unmarshals into a slice, so I had to use a slice of interfaces ([]interface{}) at the top.
    hackerman
    @aeneasr
    hey is it possible to tell viper.Unmarshal to use environment variables as well?
    Max Wolter
    @awishformore
    So the channel is kind of dead.
    If anyone is still around, I will try to be responsive here as well.
    Agniva De Sarker
    @agnivade
    Hey there, I am trying to figure out the best way to recover from "config file not found" errors. It seems that the "findConfigFile" function is not exposed, so the ConfigFileNotFound error is gobbled up. Therefore, we get the same error regardless of file not found or any syntax error in file
    any way, I can get to know whether a config file has been read or not ?
    Agniva De Sarker
    @agnivade
    Ok, I used the viper.ConfigFileUsed() != "" check to achieve my purpose
    Max Wolter
    @awishformore
    There is a PR to expose the ConfigFileNotFound error, but it's not quite ready for merging yet.
    Or was it? I'll take a look.
    Agniva De Sarker
    @agnivade
    thanks
    cesco
    @cescoferraro
    @spf13 hello! I was wondering this today. If a flag contains a dash, shouldnt viper.BindpFlag bind also to an environment without the dash to avoid http://unix.stackexchange.com/questions/23659/can-shell-variable-include-character ? I wish I could figure out a way to have a --mongo-host flag and MONGOHOST environment var
    Eddie Huang
    @inoc603
    Hi. I was trying viper.Unmarshal today, and found that it doesn't seem to work with field tags
    type T struct {
        val int `yaml:"with_underscore"`
    }
    
    func TestUnmarshal(t *testing.T) {
        a := assert.New(t)
    
        yamlExample := []byte(`a: 2
    with_underscore: 1`)
    
        viper.SetConfigType("yaml")
        viper.ReadConfig(bytes.NewBuffer(yamlExample))
    
        a.Equal(1, viper.GetInt("with_underscore"))
    
        tmp := T{}
        err := viper.Unmarshal(&tmp)
        a.Nil(err)
        a.Equal(1, tmp.val)
    }
    the with_underscore field didn't get unmarshaled into tmp. is there anyway around this?
    Eddie Huang
    @inoc603
    oh, never mind, I checked the source and find that I need to use mapstructure as tagname
    Marcus Franke
    @Comradin

    Hi, I have a yaml based config with a structure, that is in parts two levels deep. Like this:

    foo: "bar"
    groups:
    • foo: "baz"
    doh
    some markup.. sorry
    I have no problem with viper.GetString("foo")
    but Viper.GetString("groups.foo") returns an empty string
    How do I access the keys below the groups:
    Marcus Franke
    @Comradin
    Ok, found the error, my yaml file was malformed
    instead of:
    groups:
    • foo: "bar"
    groups:
    foo: "bar"
    withouth a trailing dash, the markdown will render as an enumeration ;)
    Tobias Wellnitz
    @dh1tw

    I'm using viper and cobra and bind the cobra flags to viper values. What is the order how viper determines the value? My understanding is:

    1. Flags
    2. toml/yaml... files
    3. default values set for flags

    Is this correct?

    Mario
    @mariolasagna
    Hi there. I'm trying to open a conf file but I'm getting an error: Config File "tst.conf" Not Found "[/home/m/Desktop/Devel/Go/src/tst]" Any restriction on specifying the full file name?
    Mario
    @mariolasagna
    I believe I found the solution. I had to use the extension toml instead of conf.
    Any ideas about how to have a different extension even if it's belongs to a format such as toml?
    Cameron Moore
    @moorereason
    @mariolasagna, SetConfigType and SetConfigFile
    Mario
    @mariolasagna
    @moorereason thank you. I'll check it out!!
    Marcus Franke
    @Comradin
    Hi, with viper.AddConfigPath("/etc/global_dir") and viper.AddConfigPath("$HOME") I have two directories where viper can look for my config file. But with viper.SetConfigName("foo") it will look for /etc/global_dir/foo.(yaml|json|...). But for the lookup in the $HOME directory it will not look for a .foo.(yaml|json|...) but for a non dot'ed config file.
    Is there a toggle to make viper look for a .foo.* config file?
    Steve Louie
    @stephenrlouie

    hi viper folks, is this intentional new behavior around isSet(). isSet() now returns true as soon as I bind a flag to viper, it used to remain false until some input (config, command line, ENV) set the value that was not the flag default.

    I've also commented on this spf13/viper#276 from November '16 and hoped others could provide details on #276 so we can determine if this is desired or a bug.

    Ryan Bastic
    @rbastic
    Hi all
    Arafat Hussain
    @rftHss
    Hello and welcome back, I am Arafat Hussain, a front-end developer.
    Hope you are doing well.
    I am @rftHss on GitHub.
    Ryan Bastic
    @rbastic
    Is this project active? I see issues not being responded to, and there are year-old questions about race conditions when using viper in certain ways.
    Cameron Moore
    @moorereason
    @rbastic, yes, it's active.
    Ryan Bastic
    @rbastic
    @moorereason Thanks for responding. I've noticed that UnmarshalKey() does not work in many instances and the codebase is not thread-safe, so I rewrote a small core of Viper available here: github.com/rbastic/mvga for any interested parties. Target use case is microservices which require dynamic configuration reloads.