toml 总体上要比yaml和json更加优雅
    包地址github.com/BurnSushi/toml

    1. var (
    2. MySql *MySqlConf
    3. Redis *RedisConf
    4. IMService *IMServiceConf
    5. ApiHttpService *ApiHttpServiceConf
    6. )
    7. type MySqlConf struct {
    8. Host string
    9. Port int
    10. Username string
    11. Password string
    12. Db string
    13. Charset string
    14. }
    15. type RedisConf struct {
    16. Host string
    17. Port int
    18. Password string
    19. Db int
    20. }
    21. type IMServiceConf struct {
    22. Addr string
    23. Service string
    24. Port int
    25. }
    26. type ApiHttpServiceConf struct {
    27. Addr string
    28. Port int
    29. }
    30. type config struct {
    31. MySql MySqlConf
    32. Redis RedisConf
    33. IMService IMServiceConf
    34. ApiHttp ApiHttpServiceConf
    35. }
    36. func init() {
    37. var conf config
    38. c := getConfigPath()
    39. logger.D("config path: %s", c)
    40. _, err := toml.DecodeFile(c, &conf)
    41. if err != nil {
    42. panic(fmt.Sprintf("error on load config: %s", err.Error()))
    43. }
    44. MySql = &conf.MySql
    45. Redis = &conf.Redis
    46. IMService = &conf.IMService
    47. ApiHttpService = &conf.ApiHttp
    48. }