http.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/admin/main/coupon/conf"
  5. "go-common/app/admin/main/coupon/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. var (
  11. svc *service.Service
  12. authSvc *permit.Permit
  13. )
  14. // Init init
  15. func Init(c *conf.Config) {
  16. initService(c)
  17. // init router
  18. engine := bm.DefaultServer(c.BM)
  19. initRouter(engine)
  20. if err := engine.Start(); err != nil {
  21. log.Error("engine.Start error(%v)", err)
  22. panic(err)
  23. }
  24. }
  25. // initService init services.
  26. func initService(c *conf.Config) {
  27. authSvc = permit.New(c.Auth)
  28. svc = service.New(c)
  29. }
  30. // initRouter init outer router api path.
  31. func initRouter(e *bm.Engine) {
  32. //init api
  33. e.Ping(ping)
  34. group := e.Group("/x/admin/coupon", authSvc.Permit("CONPON"))
  35. group.GET("/batch/list", batchlist)
  36. group.POST("/batch/add", batchadd)
  37. group.GET("/appinfo/list", allAppInfo)
  38. group.POST("/salary", salaryCoupon)
  39. allowance := group.Group("/allowance", authSvc.Permit("CONPON_ALLOWANCE"))
  40. allowance.GET("/batch/list", batchlist)
  41. allowance.GET("/batch/info", batchInfo)
  42. allowance.POST("/batch/block", allowanceBatchBlock)
  43. allowance.POST("/batch/unblock", allowanceBatchUnBlock)
  44. allowance.POST("/batch/add", allowanceBatchadd)
  45. allowance.POST("/batch/modify", allowanceBatchModify)
  46. allowance.GET("/list", allowanceList)
  47. allowance.POST("/block", allowanceBlock)
  48. allowance.POST("/unblock", allowanceUnBlock)
  49. allowance.POST("/salary", allowanceSalary)
  50. allowance.POST("/activity/salary", batchSalaryCoupon)
  51. allowance.POST("/uploadfile", uploadFile)
  52. view := group.Group("/view", authSvc.Permit("COUPON_VIEW"))
  53. {
  54. view.GET("/batch/list", batchlist)
  55. view.GET("/batch/info", batchInfo)
  56. view.POST("/batch/block", batchBlock)
  57. view.POST("/batch/unblock", batchUnBlock)
  58. view.POST("/batch/add", viewBatchAdd)
  59. view.POST("/batch/save", viewBatchSave)
  60. view.GET("/list", viewList)
  61. view.POST("/block", viewBlock)
  62. view.POST("/unblock", viewUnblock)
  63. view.POST("/salary", salaryView)
  64. }
  65. // code
  66. group.GET("/batch_code/list", codeBatchList)
  67. group.POST("/batch_code/block", codeBatchBlock)
  68. group.POST("/batch_code/unblock", codeBatchUnBlock)
  69. group.POST("/batch_code/add", codeAddBatch)
  70. group.POST("/batch_code/modify", codeBatchModify)
  71. group.GET("/code/list", codePage)
  72. group.POST("/code/block", codeBlock)
  73. group.POST("/code/unblock", codeUnBlock)
  74. group.GET("/code/export", exportCode)
  75. }
  76. // ping check server ok.
  77. func ping(c *bm.Context) {
  78. if err := svc.Ping(c); err != nil {
  79. log.Error("coupon http admin ping error(%v)", err)
  80. c.AbortWithStatus(http.StatusServiceUnavailable)
  81. }
  82. }