config.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package adslib
  2. import (
  3. "github.com/BurntSushi/toml"
  4. "sync"
  5. )
  6. type SvrConf struct {
  7. HostIos string `toml:"Host_Ios"`
  8. HostAndroid string `toml:"Host_Android"`
  9. Host string `toml:"Host"`
  10. HostScript string `toml:"Host_script"`
  11. HostMiao string `toml:"Host_miao"`
  12. IPReqSource []string `toml:"ip_req_source"`
  13. BlackReqSource []string `toml:"black_req_source"`
  14. DpTest string `toml:"dp_test"`
  15. FreqControlNum int `toml:"freq_control_num"`
  16. FlowPercent map[string]map[string]FlogControlItem `toml:"flow_percent"`
  17. FlowPercent1 map[string]map[string]FlogControlItem `toml:"flow_percent_1"`
  18. AdsActions map[string][]string `toml:"Ads_Actions"`
  19. AdsDuration map[string]int `toml:"Ads_Duration"`
  20. ActionWeight ActionWeight `toml:"action_weight"`
  21. CombinationActions map[string][]CombinationActionsConf `toml:"combination_actions"`
  22. SecretKey string `toml:"secret_key"`
  23. Ip2RegionFile string `toml:"ip2region_file"`
  24. LogPath string `toml:"log_path"`
  25. RedisHost string `toml:"redis_host"`
  26. RedisPassword string `toml:"redis_password"`
  27. }
  28. type FlogControlItem struct {
  29. Percent int `toml:"percent"`
  30. Duration int `toml:"duration"`
  31. }
  32. type ActionWeight struct {
  33. VIEW int `toml:"VIEW"`
  34. VIDEOTIMER int `toml:"VIDEO_TIMER"`
  35. CLICK int `toml:"CLICK"`
  36. CLOSE int `toml:"CLOSE"`
  37. VIDEOFINISH int `toml:"VIDEO_FINISH"`
  38. }
  39. type CombinationActionsConf struct {
  40. PercentBegin int `toml:"percent_begin"`
  41. PercentEnd int `toml:"percent_end"`
  42. GroupValue []string `toml:"group_value"`
  43. LastAction string `toml:"last_action"`
  44. }
  45. var svrConf SvrConf
  46. var once sync.Once
  47. func GetConf() *SvrConf {
  48. once.Do(func() {
  49. _, err := toml.DecodeFile("../conf/config.toml", &svrConf)
  50. if err != nil {
  51. panic(err)
  52. }
  53. })
  54. return &svrConf
  55. }