main.go 1.09 KB
Newer Older
kzkzzzz's avatar
kzkzzzz committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
package main

import (
	"flag"
	"fmt"
	"go-micro.dev/v4/logger"
	"golang.org/x/sync/errgroup"
	"gomicro-base/common/logz"
	"gomicro-base/service/wallet/client"
	"gomicro-base/service/wallet/internal/conf"
	"gomicro-base/service/wallet/internal/dao"
	"gomicro-base/service/wallet/internal/server"
	"gomicro-base/service/wallet/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)

	client.NewMicroClient(conf.Conf)

	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)
	}

}