6
0

main.go 2.0 KB

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