Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1.  
  2. srv := &http.Server{
  3. Addr: fmt.Sprintf(":%s", configData.DashboardPort),
  4. Handler: dashboardweb.New(logger, dashbaordService).Router(),
  5. }
  6.  
  7. var g errgroup.Group
  8. // g.Go(grpcServer.Serve)
  9. g.Go(func() error {
  10. listener, err := net.Listen("tcp", fmt.Sprintf(":%s", configData.PORT))
  11. if err != nil {
  12. return errors.Wrap(err, "failed to listen: %v")
  13. }
  14. defer listener.Close()
  15.  
  16. logger.Log("port", configData.PORT, "gRPC server port")
  17.  
  18. return grpcSrv.Serve(listener)
  19. })
  20. g.Go(func() error {
  21. logger.Log("port", configData.DashboardPort, "http server port")
  22. return srv.ListenAndServe()
  23. })
  24.  
  25. go func() {
  26. quit := make(chan os.Signal)
  27. signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
  28. <-quit
  29. logger.Log("Shutting down all services... 😔")
  30.  
  31. ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
  32. defer cancel()
  33. if err := srv.Shutdown(ctx); err != nil {
  34. logger.Log("Server Shutdown:", err, "error shutting down")
  35. }
  36.  
  37. grpcSrv.GracefulStop()
  38. }()
  39.  
  40. logger.Log("starting gRPC and HTTP server")
  41. err = g.Wait()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement