setting.go 885 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package http
  2. import (
  3. "strconv"
  4. pushmdl "go-common/app/service/main/push/model"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. func setSettingInternal(c *bm.Context) {
  10. var (
  11. params = c.Request.Form
  12. midStr = params.Get("mid")
  13. typeStr = params.Get("type")
  14. valStr = params.Get("value")
  15. )
  16. mid, _ := strconv.ParseInt(midStr, 10, 64)
  17. if mid <= 0 {
  18. log.Warn("mid(%s) is wrong", midStr)
  19. c.JSON(nil, ecode.RequestErr)
  20. return
  21. }
  22. typ, _ := strconv.Atoi(typeStr)
  23. if _, ok := pushmdl.Settings[typ]; !ok {
  24. log.Warn("type(%s) is wrong", typeStr)
  25. c.JSON(nil, ecode.RequestErr)
  26. return
  27. }
  28. val, _ := strconv.Atoi(valStr)
  29. if val != pushmdl.SwitchOn && val != pushmdl.SwitchOff {
  30. log.Warn("value(%s) is wrong", valStr)
  31. c.JSON(nil, ecode.RequestErr)
  32. return
  33. }
  34. c.JSON(nil, pushSrv.SetSetting(c, mid, typ, val))
  35. }