local.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package http
  2. import (
  3. "net/http"
  4. "strconv"
  5. "go-common/app/interface/main/web-show/conf"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/xstr"
  9. )
  10. // ping check server ok.
  11. func ping(c *bm.Context) {
  12. if jobSvc.Ping(c) != nil || resSvc.Ping(c) != nil || opSvc.Ping(c) != nil {
  13. log.Error("web-show service ping error")
  14. c.AbortWithStatus(http.StatusServiceUnavailable)
  15. }
  16. }
  17. // version check server version.
  18. func version(c *bm.Context) {
  19. c.JSON(map[string]interface{}{
  20. "version": conf.Conf.Version,
  21. }, nil)
  22. }
  23. func grayRate(c *bm.Context) {
  24. params := c.Request.Form
  25. rateStr := params.Get("rate")
  26. whiteStr := params.Get("white")
  27. swtStr := params.Get("swt")
  28. if rateStr == "" && whiteStr == "" {
  29. res := map[string]interface{}{}
  30. res["rate"], res["white"], res["swt"] = resSvc.GrayRate(c)
  31. c.JSON(res, nil)
  32. return
  33. }
  34. rate, _ := strconv.ParseInt(rateStr, 10, 64)
  35. if rate < 0 || rate > 100 {
  36. rate = 0
  37. }
  38. swt, _ := strconv.ParseBool(swtStr)
  39. white, _ := xstr.SplitInts(whiteStr)
  40. resSvc.SetGrayRate(c, swt, rate, white)
  41. }