main.go
912 字节
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
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:
}
}
}