main.go 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package main
  2. import (
  3. "context"
  4. "dashoo.cn/opms_libary/myerrors"
  5. "net/http"
  6. "dashoo.cn/opms_libary/micro_srv"
  7. "github.com/gogf/gf/frame/g"
  8. "github.com/gogf/gf/os/glog"
  9. "github.com/smallnest/rpcx/protocol"
  10. "dashoo.cn/micro/app/handler/base"
  11. "dashoo.cn/micro/app/handler/contract"
  12. "dashoo.cn/micro/app/handler/cust"
  13. "dashoo.cn/micro/app/handler/plat"
  14. projHandler "dashoo.cn/micro/app/handler/proj"
  15. )
  16. func main() {
  17. go swaggerui()
  18. srvAddr := g.Config().GetString("setting.bind-addr")
  19. basePath := g.Config().GetString("setting.srv-name")
  20. // 创建总服务包
  21. s := micro_srv.CreateAndInitService(basePath)
  22. s.RegisterName("Product", new(base.ProductHandler), "")
  23. s.RegisterName("Distributor", new(base.DistributorHandler), "")
  24. s.RegisterName("District", new(base.DistrictHandler), "")
  25. s.RegisterName("Region", new(base.RegionHandler), "")
  26. s.RegisterName("Customer", new(cust.CustomerHeader), "")
  27. s.RegisterName("Contact", new(cust.CustomerContantHeader), "")
  28. s.RegisterName("Belong", new(cust.CustBelongHeader), "")
  29. s.RegisterName("FollowUp", new(plat.FollowUpHandler), "")
  30. s.RegisterName("FollowUpComment", new(plat.FollowUpCommentHandler), "")
  31. s.RegisterName("FollowUpFile", new(plat.FollowUpFileHandler), "")
  32. s.RegisterName("Task", new(plat.TaskHandler), "")
  33. s.RegisterName("TaskComment", new(plat.TaskCommentHandler), "")
  34. s.RegisterName("TaskLog", new(plat.TaskLogHandler), "")
  35. s.RegisterName("TaskProgress", new(plat.TaskProgressHandler), "")
  36. s.RegisterName("Business", new(projHandler.BusinessHandler), "")
  37. s.RegisterName("BusinessContact", new(projHandler.BusinessContactHandler), "")
  38. s.RegisterName("BusinessFile", new(projHandler.BusinessFileHandler), "")
  39. s.RegisterName("BusinessTeam", new(projHandler.BusinessTeamHandler), "")
  40. s.RegisterName("CtrContract", new(contract.CtrContract), "")
  41. s.RegisterName("CtrContractCollectionPlan", new(contract.CtrContractCollectionPlan), "")
  42. s.RegisterName("CtrContractCollection", new(contract.CtrContractCollection), "")
  43. s.RegisterName("CtrContractAppend", new(contract.CtrContractAppend), "")
  44. s.RegisterName("CtrContractInvoice", new(contract.CtrContractInvoice), "")
  45. s.RegisterName("Schedule", new(plat.ScheduleHeader), "")
  46. // 注册服务对象
  47. //s.RegisterName("Auth", new(handler.Auth), "")
  48. // 注册文件处理Service对象
  49. //dynamic.BeanFactory.BeanRegister(service.NewRoleService())
  50. // 注册auth处理
  51. s.AuthFunc = handleAuth
  52. s.Plugins.Add(&myerrors.HandleErrorPlugin{})
  53. // 运行服务
  54. if err := s.Serve("tcp", srvAddr); err != nil {
  55. g.Log().Fatal(err)
  56. }
  57. }
  58. // AuthExcludePaths 设定不需要认证的路径
  59. var AuthExcludePaths = []string{
  60. "/Auth/Login",
  61. "/Role/GetRoleList",
  62. "/Common/GetCaptchaImg",
  63. "/Model/*",
  64. "/Organize/GetOrgTreeList",
  65. "/User/SendResetPasswordEmail",
  66. "/User/ResetPasswordFromEmail",
  67. }
  68. // 处理Auth
  69. func handleAuth(ctx context.Context, req *protocol.Message, token string) error {
  70. return micro_srv.HandleAuth(ctx, req, token, AuthExcludePaths)
  71. }
  72. func swaggerui() {
  73. defer func() {
  74. if r := recover(); r != nil {
  75. glog.Error(r)
  76. }
  77. }()
  78. if !g.Config().GetBool("setting.swagger") {
  79. return
  80. }
  81. glog.Info("start swagger at :8080")
  82. glog.Error(http.ListenAndServe(":8080",
  83. http.FileServer(http.Dir("./swaggerui/"))))
  84. }