package main import ( "flag" "fmt" "golang.org/x/sync/errgroup" "grpc-base/common/logger" "grpc-base/service/testuser/internal/conf" "grpc-base/service/testuser/internal/dao" "grpc-base/service/testuser/internal/server" "grpc-base/service/testuser/internal/service" "os" "os/signal" "syscall" ) func main() { flag.Parse() conf.LoadConfig() logger.Init(conf.Conf.Log) defer logger.Flush() d := dao.New(conf.Conf) svc := service.New(d) eg := errgroup.Group{} eg.Go(func() error { return server.NewGrpcServer(conf.Conf, svc) }) eg.Go(func() error { ch := make(chan os.Signal, 1) signal.Notify(ch, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT) v := <-ch fmt.Printf("\n捕获信号: %v\n", v) //time.Sleep(time.Millisecond * 600) server.GracefulStopGrpc() return nil }) logger.Infof("%s", "server start") if err := eg.Wait(); err != nil { logger.Error(err) } logger.Info("end") }