|
- package main
-
- import (
- "applet/app/cfg"
- "applet/app/db"
- "applet/app/utils"
- "applet/app/utils/logx"
- "applet/processor"
- "errors"
- "fmt"
- "os"
- "os/signal"
- "strings"
- "syscall"
- )
-
- //系统初始化
- func init() {
- cfg.InitCfg() //配置初始化
- cfg.InitLog() //日志初始化
- cfg.InitCache() //缓存初始化
- cfg.InitMq() //队列初始化
- if cfg.Debug { //判断是否是debug
- if err := db.InitDB(cfg.DB); err != nil { //主数据库初始化
- panic(err)
- }
- channel := make(chan int, 0) //开辟管道,缓冲为
- go db.InitDBs(channel)
- <-channel
- }
- fmt.Println("init success")
-
- }
-
- // @title 智莺生活移动端接口
- // @version 1.0
- // @description 移动端接口
- // @termsOfService 智莺生活后端组
- // @contact.name sherlockwhite
- // @host localhost:5000
- // @securityDefinitions.apikey MasterID
- // @in header
- // @name MasterID
- // @BasePath /
- func main() {
- if cfg.CurlDebug {
- utils.CurlDebug = true
- }
- //r := router.Init() //创建路由
- //srv := &http.Server{ //设置http服务参数
- // Addr: cfg.SrvAddr, //指定ip和端口
- // Handler: r, //指定路由
- //}
- //go func() { //协程启动监听队列
- // fmt.Println("Listening and serving HTTP on " + cfg.SrvAddr)
- // if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
- // log.Fatalf("listen: %s\n", err)
- // }
- //}()
- //退出go守护进程
- //quit := make(chan os.Signal)
- //signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
- //<-quit
- //log.Println("Shutting down server...")
- //ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
- //defer cancel()
- //if err := srv.Shutdown(ctx); err != nil {
- // log.Fatal("Server forced to shutdown:", err)
- //}
- //log.Println("Server exiting")
-
- //获取需要监听多少个队列
- if cfg.RabbitMqAddr == "" {
- panic(errors.New("请填写MQ参数"))
- }
- forever := make(chan bool)
- for _, workQueueName := range strings.Split(cfg.MqWorkQueueName, ",") {
- if workQueueName == "" {
- continue
- }
- fmt.Printf("监听%s队列", workQueueName)
- fmt.Println()
- go processor.WorkReceive(workQueueName)
- }
- //processor.TestWorkSend()
- <-forever
- quit := make(chan os.Signal)
- signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
- <-quit
- _ = logx.Info("Server exiting...")
-
- }
|