main.go 2.7 KB

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