main.go 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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("BusinessFile", new(projHandler.BusinessFileHandler), "")
  38. s.RegisterName("BusinessTeam", new(projHandler.BusinessTeamHandler), "")
  39. s.RegisterName("CtrContract", new(contract.CtrContract), "")
  40. s.RegisterName("CtrContractCollectionPlan", new(contract.CtrContractCollectionPlan), "")
  41. s.RegisterName("CtrContractCollection", new(contract.CtrContractCollection), "")
  42. s.RegisterName("CtrContractAppend", new(contract.CtrContractAppend), "")
  43. s.RegisterName("CtrContractInvoice", new(contract.CtrContractInvoice), "")
  44. // 注册服务对象
  45. //s.RegisterName("Auth", new(handler.Auth), "")
  46. // 注册文件处理Service对象
  47. //dynamic.BeanFactory.BeanRegister(service.NewRoleService())
  48. // 注册auth处理
  49. s.AuthFunc = handleAuth
  50. // 运行服务
  51. if err := s.Serve("tcp", srvAddr); err != nil {
  52. g.Log().Fatal(err)
  53. }
  54. }
  55. // AuthExcludePaths 设定不需要认证的路径
  56. var AuthExcludePaths = []string{
  57. "/Auth/Login",
  58. "/Role/GetRoleList",
  59. "/Common/GetCaptchaImg",
  60. "/Model/*",
  61. "/Organize/GetOrgTreeList",
  62. "/User/SendResetPasswordEmail",
  63. "/User/ResetPasswordFromEmail",
  64. }
  65. // 处理Auth
  66. func handleAuth(ctx context.Context, req *protocol.Message, token string) error {
  67. return micro_srv.HandleAuth(ctx, req, token, AuthExcludePaths)
  68. }
  69. func swaggerui() {
  70. defer func() {
  71. if r := recover(); r != nil {
  72. glog.Error(r)
  73. }
  74. }()
  75. glog.Error(http.ListenAndServe(":8080",
  76. http.FileServer(http.Dir("./swaggerui/"))))
  77. }