package main import ( "flag" "fmt" "go-micro.dev/v4/logger" "golang.org/x/sync/errgroup" "gomicro-base/common/logz" "gomicro-base/service/demo/internal/conf" "gomicro-base/service/demo/internal/dao" "gomicro-base/service/demo/internal/server" "gomicro-base/service/demo/internal/service" "os" "os/signal" "syscall" ) func main() { flag.Parse() conf.LoadConfig() if conf.Conf.Server.Name == "" { panic("服务名不能为空") } // github.com/go-micro/plugins/v4/logger/zap logger.DefaultLogger = logz.NewLogger(conf.Conf.Log) defer logz.Flush() svc := service.New(dao.New(conf.Conf)) microServer := server.NewMicroServer(conf.Conf, svc) eg := errgroup.Group{} eg.Go(func() error { return microServer.Run() }) eg.Go(func() error { ch := make(chan os.Signal, 1) signal.Notify(ch, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT) v := <-ch fmt.Println() logz.Warnf("捕获退出信号: %v", v) return nil }) if err := eg.Wait(); err != nil { logz.Error(err) } }