main.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package main
  2. import (
  3. "context"
  4. "net/http"
  5. "dashoo.cn/opms_libary/micro_srv"
  6. "github.com/gogf/gf/frame/g"
  7. "github.com/gogf/gf/os/glog"
  8. "github.com/smallnest/rpcx/protocol"
  9. "dashoo.cn/micro/app/handler/base"
  10. "dashoo.cn/micro/app/handler/contract"
  11. "dashoo.cn/micro/app/handler/cust"
  12. "dashoo.cn/micro/app/handler/plat"
  13. projHandler "dashoo.cn/micro/app/handler/proj"
  14. )
  15. func main() {
  16. go swaggerui()
  17. srvAddr := g.Config().GetString("setting.bind-addr")
  18. basePath := g.Config().GetString("setting.srv-name")
  19. // 创建总服务包
  20. s := micro_srv.CreateAndInitService(basePath)
  21. s.RegisterName("Product", new(base.ProductHandler), "")
  22. s.RegisterName("Distributor", new(base.DistributorHandler), "")
  23. s.RegisterName("District", new(base.DistrictHandler), "")
  24. s.RegisterName("Region", new(base.RegionHandler), "")
  25. s.RegisterName("Customer", new(cust.CustomerHeader), "")
  26. s.RegisterName("Contact", new(cust.CustomerContantHeader), "")
  27. s.RegisterName("Belong", new(cust.CustBelongHeader), "")
  28. s.RegisterName("FollowUp", new(plat.FollowUpHandler), "")
  29. s.RegisterName("FollowUpComment", new(plat.FollowUpCommentHandler), "")
  30. s.RegisterName("FollowUpFile", new(plat.FollowUpFileHandler), "")
  31. s.RegisterName("Task", new(plat.TaskHandler), "")
  32. s.RegisterName("TaskComment", new(plat.TaskCommentHandler), "")
  33. s.RegisterName("TaskLog", new(plat.TaskLogHandler), "")
  34. s.RegisterName("TaskProgress", new(plat.TaskProgressHandler), "")
  35. s.RegisterName("Business", new(projHandler.BusinessHandler), "")
  36. s.RegisterName("BusinessContact", new(projHandler.BusinessContactHandler), "")
  37. s.RegisterName("BusinessDynamics", new(projHandler.BusinessDynamicsHandler), "")
  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. // 运行服务
  52. if err := s.Serve("tcp", srvAddr); err != nil {
  53. g.Log().Fatal(err)
  54. }
  55. }
  56. // AuthExcludePaths 设定不需要认证的路径
  57. var AuthExcludePaths = []string{
  58. "/Auth/Login",
  59. "/Role/GetRoleList",
  60. "/Common/GetCaptchaImg",
  61. "/Model/*",
  62. "/Organize/GetOrgTreeList",
  63. "/User/SendResetPasswordEmail",
  64. "/User/ResetPasswordFromEmail",
  65. }
  66. // 处理Auth
  67. func handleAuth(ctx context.Context, req *protocol.Message, token string) error {
  68. return micro_srv.HandleAuth(ctx, req, token, AuthExcludePaths)
  69. }
  70. func swaggerui() {
  71. defer func() {
  72. if r := recover(); r != nil {
  73. glog.Error(r)
  74. }
  75. }()
  76. glog.Error(http.ListenAndServe(":8080",
  77. http.FileServer(http.Dir("./swaggerui/"))))
  78. }