http.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package http
  2. import (
  3. "go-common/app/service/main/upcredit/conf"
  4. "go-common/app/service/main/upcredit/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. idfSvc *verify.Verify
  12. //Svc service.
  13. Svc *service.Service
  14. authSrc *permit.Permit
  15. )
  16. // Init init account service.
  17. func Init(c *conf.Config) {
  18. // service
  19. initService(c)
  20. // init internal router
  21. innerEngine := bm.DefaultServer(c.BM.Inner)
  22. setupInnerEngine(innerEngine)
  23. // init internal server
  24. if err := innerEngine.Start(); err != nil {
  25. log.Error("httpx.Serve2 error(%v)", err)
  26. panic(err)
  27. }
  28. }
  29. func initService(c *conf.Config) {
  30. idfSvc = verify.New(nil)
  31. Svc = service.New(c)
  32. authSrc = permit.New(c.Auth)
  33. }
  34. // innerRouter
  35. func setupInnerEngine(e *bm.Engine) {
  36. // monitor ping
  37. e.GET("/monitor/ping", ping)
  38. // base
  39. var base *bm.RouterGroup
  40. if conf.Conf.IsTest {
  41. base = e.Group("/x/internal/upcredit")
  42. } else {
  43. base = e.Group("/x/internal/upcredit", idfSvc.Verify)
  44. }
  45. {
  46. base.GET("/test", test)
  47. base.POST("/log/add", logCredit)
  48. base.GET("/log/get", logGet)
  49. base.GET("/score/get", scoreGet)
  50. base.POST("/score/recalc", recalc)
  51. base.POST("/score/calc_section", calcSection)
  52. }
  53. }
  54. // ping check server ok.
  55. func ping(ctx *bm.Context) {
  56. }