Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- toml "github.com/pelletier/go-toml"
- )
- type Config struct {
- DBCluster *DBClusterConfig `toml:"db_cluster"`
- }
- type DBConfig struct {
- User string `toml:"user"`
- Password string `toml:"password"`
- Database string `toml:"database"`
- }
- type DBClusterConfig struct {
- DBConfig
- Sharding []int
- ShardsNum int `toml:"shards_num"`
- }
- func main() {
- doc := []byte(`
- [db_cluster]
- user = "test_user"
- password = "password"
- database = "shard_test"
- shards_num = 2
- sharding = [0]
- `)
- config := Config{}
- toml.Unmarshal(doc, &config)
- fmt.Println("user=", config.DBCluster.User)
- fmt.Println("ShardsNum=", config.DBCluster.ShardsNum)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement