main.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package main
  2. import (
  3. "context"
  4. "lims_adapter/handler"
  5. "lims_adapter/handler/learning"
  6. "lims_adapter/service/timers"
  7. "net/http"
  8. "github.com/golang/glog"
  9. _ "lims_adapter/boot"
  10. "dashoo.cn/micro_libary/micro_srv"
  11. "github.com/gogf/gf/frame/g"
  12. "github.com/robfig/cron"
  13. "github.com/smallnest/rpcx/protocol"
  14. )
  15. func main() {
  16. go swaggerui()
  17. // 定时任务
  18. c := cron.New()
  19. spec := "0 0 1 * * ?" // 每日1点执行
  20. if err := c.AddJob(spec, timers.Timer{}); err != nil {
  21. glog.Error(err.Error())
  22. }
  23. c.Start()
  24. srvAddr := g.Config().GetString("setting.bind-addr")
  25. basePath := g.Config().GetString("setting.srv-name")
  26. // 创建总服务包
  27. s := micro_srv.CreateAndInitService(basePath)
  28. // 注册服务对象
  29. s.RegisterName("Meeting",
  30. new(handler.Meeting), "")
  31. s.RegisterName("Reservation",
  32. new(handler.Reservation), "")
  33. s.RegisterName("Equipment",
  34. new(handler.Equipment), "")
  35. s.RegisterName("System",
  36. new(handler.System), "")
  37. s.RegisterName("Result",
  38. new(handler.Result), "")
  39. s.RegisterName("Account",
  40. new(handler.Account), "")
  41. s.RegisterName("SettleAccountBill",
  42. new(handler.SettleAccountBillController), "")
  43. s.RegisterName("SettleAccountMain",
  44. new(handler.SettleAccountMainController), "")
  45. s.RegisterName("SettleAccountDetail",
  46. new(handler.SettleAccountDetailController), "")
  47. s.RegisterName("InstrumentSurcharge",
  48. new(handler.InstrumentSurchargeController), "")
  49. s.RegisterName("Test",
  50. new((handler.TestController)), "")
  51. s.RegisterName("LearningSkill",
  52. new((learning.LearningSkill)), "")
  53. // 注册auth处理
  54. s.AuthFunc = handleAuth
  55. // 运行服务
  56. if err := s.Serve("tcp", srvAddr); err != nil {
  57. g.Log().Fatal(err)
  58. }
  59. }
  60. // AuthExcludePaths 设定不需要认证的路径
  61. //var AuthExcludePaths = []string{}
  62. // 处理Auth
  63. func handleAuth(ctx context.Context, req *protocol.Message, token string) error {
  64. return micro_srv.HandleAuth(ctx, req, token, nil)
  65. }
  66. func swaggerui() {
  67. defer func() {
  68. if r := recover(); r != nil {
  69. glog.Error(r)
  70. }
  71. }()
  72. glog.Error(http.ListenAndServe(":8080",
  73. http.FileServer(http.Dir("./swaggerui/"))))
  74. }