http.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/admin/main/card/conf"
  5. "go-common/app/admin/main/card/service"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/net/http/blademaster/middleware/permit"
  9. )
  10. const _maxnamelen = 18
  11. var (
  12. srv *service.Service
  13. cf *conf.Config
  14. permitSvc *permit.Permit
  15. )
  16. // Init init
  17. func Init(c *conf.Config, svc *service.Service) {
  18. srv = svc
  19. permitSvc = permit.New2(nil)
  20. cf = c
  21. engine := bm.DefaultServer(c.BM)
  22. route(engine)
  23. if err := engine.Start(); err != nil {
  24. log.Error("bm Start error(%v)", err)
  25. panic(err)
  26. }
  27. }
  28. func route(e *bm.Engine) {
  29. e.Ping(ping)
  30. e.Register(register)
  31. group := e.Group("/x/admin/card", permitSvc.Permit2("CARD"))
  32. group.GET("/group/list", groups)
  33. group.POST("/group/add", addGroup)
  34. group.POST("/group/modify", updateGroup)
  35. group.POST("/group/state/change", groupStateChange)
  36. group.POST("/group/delete", deleteGroup)
  37. group.POST("/group/order", groupOrderChange)
  38. group.POST("/order", cardOrderChange)
  39. group.POST("/add", addCard)
  40. group.POST("/modify", updateCard)
  41. group.GET("/list", cards)
  42. group.POST("/state/change", cardStateChange)
  43. group.POST("/delete", deleteCard)
  44. }
  45. func ping(c *bm.Context) {
  46. if err := srv.Ping(c); err != nil {
  47. log.Error("ping error(%v)", err)
  48. c.AbortWithStatus(http.StatusServiceUnavailable)
  49. }
  50. }
  51. func register(c *bm.Context) {
  52. c.JSON(map[string]interface{}{}, nil)
  53. }