conf.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. package conf
  2. import (
  3. "errors"
  4. "flag"
  5. eleclient "go-common/app/service/main/vip/dao/ele-api-client"
  6. "go-common/library/cache/memcache"
  7. "go-common/library/cache/redis"
  8. "go-common/library/conf"
  9. "go-common/library/database/sql"
  10. ecode "go-common/library/ecode/tip"
  11. "go-common/library/log"
  12. bm "go-common/library/net/http/blademaster"
  13. "go-common/library/net/rpc"
  14. "go-common/library/net/rpc/warden"
  15. xtime "go-common/library/time"
  16. "github.com/BurntSushi/toml"
  17. )
  18. // Conf global variable.
  19. var (
  20. Conf = &Config{}
  21. client *conf.Client
  22. confPath string
  23. )
  24. // Config struct of conf.
  25. type Config struct {
  26. MsgURI string
  27. PayURI string
  28. VipURI string
  29. // log
  30. Log *log.Config
  31. // gorpc server
  32. RPCServer *rpc.ServerConfig
  33. // db
  34. Mysql *sql.Config
  35. // ecodes FIXME
  36. Ecode *ecode.Config
  37. //old db
  38. OldMysql *sql.Config
  39. // http client
  40. HTTPClient *bm.ClientConfig
  41. // mc
  42. Memcache *Memcache
  43. // pay conf
  44. PayConf *PayConf
  45. // rpc clients
  46. RPCClient2 *RPC
  47. // property
  48. Property *Property
  49. // http
  50. BM *bm.ServerConfig
  51. // redis
  52. Redis *Redis
  53. // associate conf
  54. AssociateConf *AssociateConf
  55. // ele conf
  56. ELEConf *eleclient.Config
  57. Host *Host
  58. // grpc server
  59. WardenServer *warden.ServerConfig
  60. // grpc client
  61. CouponClient *warden.ClientConfig
  62. }
  63. // Host host.
  64. type Host struct {
  65. Ele string
  66. Mail string
  67. }
  68. // Redis redis
  69. type Redis struct {
  70. *redis.Config
  71. Expire xtime.Duration
  72. }
  73. // Memcache memcache
  74. type Memcache struct {
  75. *memcache.Config
  76. Expire xtime.Duration
  77. }
  78. //PayConf pay config
  79. type PayConf struct {
  80. CustomerID int64
  81. Token string
  82. OrderNotifyURL string
  83. SignNotifyURL string
  84. PlanID int32
  85. ProductID string
  86. Version string
  87. ReturnURL string
  88. OrderExpire int
  89. SignType string
  90. }
  91. // RPC clients config.
  92. type RPC struct {
  93. Member *rpc.ClientConfig
  94. Point *rpc.ClientConfig
  95. Coupon *rpc.ClientConfig
  96. }
  97. // Property config for biz logic.
  98. type Property struct {
  99. NotifyURL string
  100. MsgURL string
  101. PayURL string
  102. PayCoURL string
  103. AccountURL string
  104. PassportURL string
  105. APIURL string
  106. APICoURL string
  107. VipURL string
  108. TokenBID string
  109. PGCURL string
  110. ActiveDate string
  111. ActiveTip string
  112. Expire string
  113. AnnualVipBcoinDay int16
  114. AnnualVipBcoinCouponMoney int
  115. AnnualVipBcoinCouponActivityID int
  116. GiveBpDay int8
  117. PointGetRule map[string]int
  118. PointActiveDate map[string]string
  119. BubbleTicker xtime.Duration
  120. PayType map[string]string
  121. PayChannelMapping map[string]string
  122. PointBalance int64
  123. ActiveStart string
  124. ActiveEnd string
  125. ConfigMap map[string]string
  126. PointExchangeTitle map[string]string
  127. WillExpiredTitle map[string]string
  128. ExpiredTitle map[string]string
  129. TipButtonName string
  130. TipButtonLink string
  131. AllowanceSwitch int8
  132. CodeSwitch int8
  133. GiveSwitch int8
  134. PanelBgURL string
  135. CodeOpenedSearchSize int
  136. WelfareBgHost string
  137. }
  138. // AssociateConf associate vip conf.
  139. type AssociateConf struct {
  140. // user grant count limit
  141. GrantDurationMap map[string]int64 //限制饿了么发放联合会员的次数
  142. BilibiliPrizeGrantKeyMap map[string]string
  143. MailCouponID1 string //票务优惠券满99减5
  144. MailCouponID2 string //电商优惠券满299减20
  145. BilibiliBuyDurationMap map[string]int64 //限制bilibili购买联合会员的次数
  146. }
  147. func init() {
  148. flag.StringVar(&confPath, "conf", "", "default config path")
  149. }
  150. // Init create config instance.
  151. func Init() (err error) {
  152. if confPath != "" {
  153. return local()
  154. }
  155. return remote()
  156. }
  157. func local() (err error) {
  158. _, err = toml.DecodeFile(confPath, &Conf)
  159. return
  160. }
  161. func remote() (err error) {
  162. if client, err = conf.New(); err != nil {
  163. return
  164. }
  165. if err = load(); err != nil {
  166. return
  167. }
  168. return
  169. }
  170. func load() (err error) {
  171. var (
  172. s string
  173. ok bool
  174. tmpConf *Config
  175. )
  176. if s, ok = client.Toml2(); !ok {
  177. return errors.New("load config center error")
  178. }
  179. if _, err = toml.Decode(s, &tmpConf); err != nil {
  180. return errors.New("could not decode config")
  181. }
  182. *Conf = *tmpConf
  183. return
  184. }