config.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. LogLevel string `toml:"log_level"`
  28. }
  29. type FlogControlItem struct {
  30. Percent int `toml:"percent"`
  31. Duration int `toml:"duration"`
  32. }
  33. type ActionWeight struct {
  34. VIEW int `toml:"VIEW"`
  35. VIDEOTIMER int `toml:"VIDEO_TIMER"`
  36. CLICK int `toml:"CLICK"`
  37. CLOSE int `toml:"CLOSE"`
  38. VIDEOFINISH int `toml:"VIDEO_FINISH"`
  39. }
  40. type CombinationActionsConf struct {
  41. PercentBegin int `toml:"percent_begin"`
  42. PercentEnd int `toml:"percent_end"`
  43. GroupValue []string `toml:"group_value"`
  44. LastAction string `toml:"last_action"`
  45. }
  46. var svrConf SvrConf
  47. var once sync.Once
  48. func GetConf() *SvrConf {
  49. once.Do(func() {
  50. _, err := toml.DecodeFile("../conf/config.toml", &svrConf)
  51. if err != nil {
  52. panic(err)
  53. }
  54. })
  55. return &svrConf
  56. }