http.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/admin/main/sms/conf"
  5. "go-common/app/admin/main/sms/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. authSrv *permit.Permit
  12. svc *service.Service
  13. )
  14. // Init http server
  15. func Init(c *conf.Config, s *service.Service) {
  16. svc = s
  17. authSrv = permit.New(c.Auth)
  18. engine := bm.DefaultServer(c.HTTPServer)
  19. route(engine)
  20. if err := engine.Start(); err != nil {
  21. panic(err)
  22. }
  23. }
  24. func route(e *bm.Engine) {
  25. e.Ping(ping)
  26. g := e.Group("/x/admin/sms")
  27. {
  28. tplg := g.Group("/template", authSrv.Permit("SMS_TEMPLATE"))
  29. {
  30. tplg.POST("/add", addTemplate)
  31. tplg.POST("/update", updateTemplate)
  32. tplg.GET("/list", templateList)
  33. }
  34. taskg := g.Group("/task", authSrv.Permit("SMS_TASK"))
  35. {
  36. taskg.POST("/add", addTask)
  37. taskg.POST("/update", updateTask)
  38. taskg.POST("/delete", deleteTask)
  39. taskg.GET("/info", taskInfo)
  40. taskg.GET("/list", taskList)
  41. taskg.POST("/upload", upload)
  42. }
  43. }
  44. }
  45. func ping(ctx *bm.Context) {
  46. if err := svc.Ping(ctx); err != nil {
  47. log.Error("sms-admin ping error(%v)", err)
  48. ctx.AbortWithStatus(http.StatusServiceUnavailable)
  49. }
  50. }