Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "fmt"
  5.  
  6. toml "github.com/pelletier/go-toml"
  7. )
  8.  
  9. type Config struct {
  10. DBCluster *DBClusterConfig `toml:"db_cluster"`
  11. }
  12.  
  13. type DBConfig struct {
  14. User string `toml:"user"`
  15. Password string `toml:"password"`
  16. Database string `toml:"database"`
  17. }
  18.  
  19. type DBClusterConfig struct {
  20. DBConfig
  21.  
  22. Sharding []int
  23. ShardsNum int `toml:"shards_num"`
  24. }
  25.  
  26. func main() {
  27. doc := []byte(`
  28. [db_cluster]
  29. user = "test_user"
  30. password = "password"
  31. database = "shard_test"
  32.  
  33. shards_num = 2
  34. sharding = [0]
  35. `)
  36.  
  37. config := Config{}
  38. toml.Unmarshal(doc, &config)
  39. fmt.Println("user=", config.DBCluster.User)
  40. fmt.Println("ShardsNum=", config.DBCluster.ShardsNum)
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement