選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 

42 行
932 B

  1. package common
  2. import (
  3. "encoding/json"
  4. "sync"
  5. )
  6. var topupGroupRatio = map[string]float64{
  7. "default": 1,
  8. "vip": 1,
  9. "svip": 1,
  10. }
  11. var topupGroupRatioMutex sync.RWMutex
  12. func TopupGroupRatio2JSONString() string {
  13. topupGroupRatioMutex.RLock()
  14. defer topupGroupRatioMutex.RUnlock()
  15. jsonBytes, err := json.Marshal(topupGroupRatio)
  16. if err != nil {
  17. SysError("error marshalling topup group ratio: " + err.Error())
  18. }
  19. return string(jsonBytes)
  20. }
  21. func UpdateTopupGroupRatioByJSONString(jsonStr string) error {
  22. topupGroupRatioMutex.Lock()
  23. defer topupGroupRatioMutex.Unlock()
  24. topupGroupRatio = make(map[string]float64)
  25. return json.Unmarshal([]byte(jsonStr), &topupGroupRatio)
  26. }
  27. func GetTopupGroupRatio(name string) float64 {
  28. topupGroupRatioMutex.RLock()
  29. defer topupGroupRatioMutex.RUnlock()
  30. ratio, ok := topupGroupRatio[name]
  31. if !ok {
  32. SysError("topup group ratio not found: " + name)
  33. return 1
  34. }
  35. return ratio
  36. }