config.go 2.0 KB

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