Skip to content

toml parse error #1245

Answered by Liudon
Liudon asked this question in Q&A
Discussion options

You must be logged in to vote
    type Conf struct {
	    Shard map[string][]struct {
		    Table string
	    }
    }

    viper.SetConfigType("toml")  // need this !!!
    viper.SetConfigFile("./config.toml")
    
    // If a config file is found, read it in.
    if err := viper.ReadInConfig(); err == nil {
    fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed())
    }
    
    conf := &Conf{}
    err := viper.Unmarshal(conf)
    if err != nil {
    fmt.Fprintln(os.Stderr, "unable to decode into config struct", err)
    }
    
    fmt.Printf("conf: %+v \n", conf)
    fmt.Println("setting:", viper.GetViper().AllSettings())

resolved.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Liudon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant