main.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. // 注册服务对象
  46. //s.RegisterName("Auth", new(handler.Auth), "")
  47. // 注册文件处理Service对象
  48. //dynamic.BeanFactory.BeanRegister(service.NewRoleService())
  49. // 注册auth处理
  50. s.AuthFunc = handleAuth
  51. s.Plugins.Add(&myerrors.HandleErrorPlugin{})
  52. // 运行服务
  53. if err := s.Serve("tcp", srvAddr); err != nil {
  54. g.Log().Fatal(err)
  55. }
  56. }
  57. // AuthExcludePaths 设定不需要认证的路径
  58. var AuthExcludePaths = []string{
  59. "/Auth/Login",
  60. "/Role/GetRoleList",
  61. "/Common/GetCaptchaImg",
  62. "/Model/*",
  63. "/Organize/GetOrgTreeList",
  64. "/User/SendResetPasswordEmail",
  65. "/User/ResetPasswordFromEmail",
  66. }
  67. // 处理Auth
  68. func handleAuth(ctx context.Context, req *protocol.Message, token string) error {
  69. return micro_srv.HandleAuth(ctx, req, token, AuthExcludePaths)
  70. }
  71. func swaggerui() {
  72. defer func() {
  73. if r := recover(); r != nil {
  74. glog.Error(r)
  75. }
  76. }()
  77. if !g.Config().GetBool("setting.swagger") {
  78. return
  79. }
  80. glog.Info("start swagger at :8080")
  81. glog.Error(http.ListenAndServe(":8080",
  82. http.FileServer(http.Dir("./swaggerui/"))))
  83. }