Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Bob Liu
    @Akagi201
    What do u think of consul vs etcd? consul has native support for multi datacenter
    It is needed for a cluster deployment.
    Chakrit Wichian
    @chakrit
    I like consul better, it’s much more powerful but I have limited DNS knowledge (which is required to setup and use consul to the full extent)
    So I usually end up just running etcd and use with spf13/viper : )
    Bob Liu
    @Akagi201
    Um, thanks for ur answers
    Chakrit Wichian
    @chakrit
    IMO You really need to have a good grasp of DNS to use consul otherwise if you are using it as a dumb K/V store, just use ectd or redis
    np ; )
    Bob Liu
    @Akagi201
    I think I should try etcd, :)
    Frederick F. Kautz IV
    @fkautz
    @spf13 for cobra+viper integration, is there a way to automatically populate --flags with entries in viper?
    or do we need to check each flag in viper through viper.Get*() calls?
    Steve Francia
    @spf13
    Needs to go through viper.
    The flag becomes one of the data sources that viper reads from when a Get() is called.
    Does that make sense? I'm not sure that I fully understand what you are trying to do.
    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.