http.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package http
  2. import (
  3. "go-common/app/admin/main/macross/conf"
  4. "go-common/app/admin/main/macross/service"
  5. "go-common/library/log"
  6. bm "go-common/library/net/http/blademaster"
  7. "go-common/library/net/http/blademaster/middleware/permit"
  8. "go-common/library/net/http/blademaster/middleware/verify"
  9. )
  10. var (
  11. verifySvc *verify.Verify
  12. authSvc *permit.Permit
  13. svr *service.Service
  14. )
  15. // Init int http service
  16. func Init(c *conf.Config) {
  17. verifySvc = verify.New(nil)
  18. authSvc = permit.New(c.Auth)
  19. svr = service.New(conf.Conf)
  20. // init internal router
  21. engineInner := bm.DefaultServer(c.BM.Inner)
  22. innerRouter(engineInner)
  23. // init internal server
  24. if err := engineInner.Start(); err != nil {
  25. log.Error("engineInner.Start() error(%v) | config(%v)", err, c)
  26. panic(err)
  27. }
  28. // init external router
  29. engineLocal := bm.DefaultServer(c.BM.Local)
  30. localRouter(engineLocal)
  31. // init external server
  32. if err := engineLocal.Start(); err != nil {
  33. log.Error("engineLocal.Start() error(%v) | config(%v)", err, c)
  34. panic(err)
  35. }
  36. }
  37. // innerRouter init outer router api path.
  38. func innerRouter(e *bm.Engine) {
  39. e.Ping(ping)
  40. e.Register(register)
  41. rs := e.Group("/api/v2/macross")
  42. // MANAGER
  43. mng := rs.Group("/manager")
  44. // auth init.
  45. mng.GET("/getAuths", authSvc.Verify(), getAuths)
  46. // user.
  47. mng.GET("/user", user)
  48. mng.POST("/user/save", saveUser)
  49. mng.POST("/user/del", delUser)
  50. // role.
  51. mng.GET("/role", role)
  52. mng.POST("/role/save", saveRole)
  53. mng.POST("/role/del", DelRole)
  54. // auth.
  55. mng.GET("/auth", auth)
  56. mng.POST("/auth/save", saveAuth)
  57. mng.POST("/auth/del", delAuth)
  58. // relation
  59. mng.POST("/setRelation", authRelation)
  60. // dashboard
  61. rs.POST("/dashboard", dashboard)
  62. // sendmail
  63. rs.POST("/sendmail", sendmail)
  64. // package upload
  65. rs.POST("/upload", packageUpload)
  66. // get package list
  67. rs.GET("/archive", packageList)
  68. }
  69. // localRouter init local router api path.
  70. func localRouter(e *bm.Engine) {
  71. e.GET("/x/macross/version", version)
  72. }