group-ratio.go 588 B

123456789101112131415161718192021222324252627282930
  1. package common
  2. import "encoding/json"
  3. var GroupRatio = map[string]float64{
  4. "default": 1,
  5. "vip": 1,
  6. "svip": 1,
  7. }
  8. func GroupRatio2JSONString() string {
  9. jsonBytes, err := json.Marshal(GroupRatio)
  10. if err != nil {
  11. SysError("Error marshalling model ratio: " + err.Error())
  12. }
  13. return string(jsonBytes)
  14. }
  15. func UpdateGroupRatioByJSONString(jsonStr string) error {
  16. return json.Unmarshal([]byte(jsonStr), &GroupRatio)
  17. }
  18. func GetGroupRatio(name string) float64 {
  19. ratio, ok := GroupRatio[name]
  20. if !ok {
  21. SysError("Group ratio not found: " + name)
  22. return 1
  23. }
  24. return ratio
  25. }