main.go 912 字节
package main

import (
	"context"
	"fmt"
	"os"
	"os/signal"
	"syscall"

	"github.com/astaxie/beego"
	"github.com/astaxie/beego/logs"
	_ "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg"
	_ "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/log"
	_ "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/port/beego"
	"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/port/consumer"
)

func main() {
	sigs := make(chan os.Signal, 1)
	signal.Notify(sigs, os.Interrupt, os.Kill, syscall.SIGINT, syscall.SIGTERM)
	ctx, cancel := context.WithCancel(context.Background())
	closeConsumer, err := consumer.StartConsumer(ctx)
	if err != nil {
		fmt.Printf("启动kafka消息消费者失败 err%s \n", err)
		logs.Error("启动kafka消息消费者失败:%s", err)
		return
	}
	go func() {
		logs.Info("应用启动")
		beego.Run()
	}()
	for {
		select {
		case <-sigs:
			cancel()
			closeConsumer()
			return
		default:
		}
	}
}