package main import ( "log" "net" "net/http" "os" "path/filepath" "recook/asset" "recook/configs" "recook/internal/api/manage" morder "recook/internal/api/manage/order" "recook/internal/api/mobile" _ "recook/internal/api/mobile/bill" "recook/internal/api/mobile/order" "recook/internal/api/store" "recook/internal/api/vend" "recook/internal/cron" "recook/internal/dbc" "recook/internal/mq" "recook/internal/v2/logic/manage/message" "time" "github.com/gin-gonic/gin" "github.com/shopspring/decimal" "golang.org/x/sync/errgroup" ) var ( g errgroup.Group ) func main() { dirs := []string{"credentials"} // 设置需要释放的目录 for _, dir := range dirs { // 解压dir目录到当前目录 if err := asset.RestoreAssets("./", dir); err != nil { log.Println(err) break } } decimal.MarshalJSONWithoutQuotes = true dbc.SetupMysql() dbc.SetupRedis() if configs.IsProductionEnv() { mq.SetUpMq() } if configs.IsProductionEnv() { gin.SetMode("release") } else { gin.SetMode("debug") } /*将今天的数据copy一份分发到接下来的30天*/ manageServer := &http.Server{ Addr: ":8080", Handler: manage.Service(), ReadTimeout: 5 * time.Second, WriteTimeout: 10 * time.Second, } appServer := &http.Server{ Addr: ":8081", Handler: mobile.Service(), ReadTimeout: 5 * time.Second, WriteTimeout: 10 * time.Second, } vendServer := &http.Server{ Addr: ":8082", Handler: vend.Service(), ReadTimeout: 5 * time.Second, WriteTimeout: 10 * time.Second, } storeServer := &http.Server{ Addr: ":8083", Handler: store.Service(), ReadTimeout: 5 * time.Second, WriteTimeout: 10 * time.Second, } // h5的路由处理,现在直接拿mobile来用 h5Server := &http.Server{ Addr: ":8084", Handler: mobile.Service(), ReadTimeout: 5 * time.Second, WriteTimeout: 10 * time.Second, } g.Go(func() error { return manageServer.ListenAndServe() }) g.Go(func() error { return appServer.ListenAndServe() }) g.Go(func() error { return vendServer.ListenAndServe() }) g.Go(func() error { return storeServer.ListenAndServe() }) g.Go(func() error { log.Println("[h5 https] 已启动") ln, err := net.Listen("tcp4", h5Server.Addr) if err != nil { log.Println("[h5 https] err:", err) return err } dir, _ := os.Executable() exPath := filepath.Dir(dir) if configs.IsProductionEnv() { return h5Server.ServeTLS(ln.(*net.TCPListener), exPath+`/./credentials/h5api/h5api.reecook.cn_chain.crt`, exPath+`/./credentials/h5api/h5api.reecook.cn_key.key`) } else { return h5Server.ServeTLS(ln.(*net.TCPListener), exPath+`/./credentials/testh5api/testh5api.reecook.cn_chain.crt`, exPath+`/./credentials/testh5api/testh5api.reecook.cn_key.key`) } }) go order.PlanMonitorTradeSucOrderTask() go order.PlanMonitorExpireOrderTask() go order.PlanPartnerSalesMonthStat() go morder.AfterNotToDoTwo() // 发送邮件任务 if configs.IsProductionEnv() { go cron.SendEmailList() } { //消息中心发送消息 go message.SendMessage() //供应商,商品,品牌资质,临期预警 //go message.QualificationOnSchedule() //每小时标记 发货超时 go message.DeliveryTimeOut() } go func() { cron.Task() }() if err := g.Wait(); err != nil { log.Fatal(err) } }