main.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package main
  2. import (
  3. "git.finogeeks.club/base/apm"
  4. "mop-account-system/common"
  5. "mop-account-system/config"
  6. "mop-account-system/router"
  7. "net"
  8. "github.com/sirupsen/logrus"
  9. "github.com/gin-gonic/gin"
  10. "google.golang.org/grpc"
  11. "google.golang.org/grpc/reflection"
  12. "mop-account-system/consul"
  13. "mop-account-system/handler/organ"
  14. pb "mop-account-system/protobuf/golang"
  15. )
  16. func InitGrpc() {
  17. cfg := config.GetConfig()
  18. if cfg.ConsulAddr == "" {
  19. return
  20. }
  21. consul.InitConsul()
  22. lis, err := net.Listen("tcp", ":"+cfg.GrpcPort)
  23. if err != nil {
  24. panic(err)
  25. }
  26. s := grpc.NewServer()
  27. pb.RegisterMopAccountSystemServer(s, &organ.GrpcServer{})
  28. reflection.Register(s)
  29. if err := s.Serve(lis); err != nil {
  30. panic(err)
  31. }
  32. }
  33. func main() {
  34. cfg := config.GetConfig()
  35. go InitGrpc()
  36. gin.SetMode(cfg.Mode)
  37. g := gin.Default()
  38. apm.ApmClient().InjectHttpMiddleware(g)
  39. router.Load(g)
  40. common.GinLog.Info("start server v3")
  41. err := g.Run(":" + cfg.HttpPort)
  42. if err != nil {
  43. common.GinLog.WithFields(logrus.Fields{
  44. "error": err.Error(),
  45. "start_port": cfg.HttpPort,
  46. }).Error("server start error!")
  47. panic(err.Error())
  48. }
  49. }