conf.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package conf
  2. import (
  3. "go-common/app/common/openplatform/encoding"
  4. "go-common/library/cache/redis"
  5. "go-common/library/database/sql"
  6. "go-common/library/log"
  7. "go-common/library/net/http/blademaster"
  8. "go-common/library/net/rpc/warden"
  9. "go-common/library/net/trace"
  10. "go-common/library/queue/databus"
  11. "go-common/library/time"
  12. "github.com/BurntSushi/toml"
  13. )
  14. var (
  15. // Conf common conf
  16. Conf = &Config{}
  17. )
  18. //Config config struct
  19. type Config struct {
  20. //数据库配置
  21. DB *DB
  22. // redis
  23. Redis *Redis
  24. // http client
  25. HTTPClient HTTPClient
  26. // http
  27. BM *blademaster.ServerConfig
  28. // tracer
  29. Tracer *trace.Config
  30. // log
  31. Log *log.Config
  32. // UT
  33. UT *UT
  34. GRPCClient map[string]*warden.ClientConfig
  35. Encrypt *encoding.EncryptConfig
  36. URLs map[string]string
  37. //basecenter配置
  38. BaseCenter *BaseCenter
  39. Databus map[string]*databus.Config
  40. TestProject *TestProject
  41. }
  42. // HTTPClient config
  43. type HTTPClient struct {
  44. Read *blademaster.ClientConfig
  45. Write *blademaster.ClientConfig
  46. }
  47. // HTTPServers Http Servers
  48. type HTTPServers struct {
  49. Inner *blademaster.ServerConfig
  50. Local *blademaster.ServerConfig
  51. }
  52. // Redis config
  53. type Redis struct {
  54. Master *redis.Config
  55. Expire time.Duration
  56. }
  57. // DB config
  58. type DB struct {
  59. Master *sql.Config
  60. }
  61. // UT config
  62. type UT struct {
  63. DistPrefix string
  64. }
  65. //BaseCenter 的配置
  66. type BaseCenter struct {
  67. AppID string
  68. Token string
  69. }
  70. // TestProject 测试项目配置
  71. type TestProject struct {
  72. IDs []int64
  73. CheckQuery string
  74. }
  75. // Set set config and decode.
  76. func (c *Config) Set(text string) error {
  77. var tmp Config
  78. if _, err := toml.Decode(text, &tmp); err != nil {
  79. return err
  80. }
  81. *c = tmp
  82. return nil
  83. }