http.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package http
  2. import (
  3. "net/http"
  4. "strconv"
  5. "go-common/app/job/main/credit-timer/conf"
  6. "go-common/app/job/main/credit-timer/service"
  7. "go-common/library/log"
  8. bm "go-common/library/net/http/blademaster"
  9. )
  10. var svc *service.Service
  11. // Init init
  12. func Init(c *conf.Config) {
  13. initService(c)
  14. // init inner router
  15. engineInner := bm.DefaultServer(c.BM)
  16. innerRouter(engineInner)
  17. if err := engineInner.Start(); err != nil {
  18. log.Error("bm.DefaultServer error(%v)", err)
  19. panic(err)
  20. }
  21. }
  22. // initService init services.
  23. func initService(c *conf.Config) {
  24. svc = service.New(c)
  25. }
  26. // innerRouter init local router api path.
  27. func innerRouter(e *bm.Engine) {
  28. //init api
  29. e.GET("/monitor/ping", ping)
  30. e.POST("/fixkpi", fixkpi)
  31. }
  32. func ping(c *bm.Context) {
  33. if err := svc.Ping(c); err != nil {
  34. log.Error("answer interface ping error")
  35. c.AbortWithStatus(http.StatusServiceUnavailable)
  36. }
  37. }
  38. func fixkpi(c *bm.Context) {
  39. params := c.Request.Form
  40. yStr := params.Get("year")
  41. mStr := params.Get("month")
  42. dStr := params.Get("day")
  43. midStr := params.Get("mid")
  44. y, _ := strconv.ParseInt(yStr, 10, 64)
  45. m, _ := strconv.ParseInt(mStr, 10, 64)
  46. d, _ := strconv.ParseInt(dStr, 10, 64)
  47. mid, _ := strconv.ParseInt(midStr, 10, 64)
  48. res, _ := svc.FixKPI(c, int(y), int(m), int(d), mid)
  49. c.JSON(res, nil)
  50. }