You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

157 lines
3.4 KiB

package main
import (
"context"
"git.oa00.com/go/alipay"
"log"
"net/http"
"os"
"os/signal"
"recook/configs"
"recook/internal/api/manage"
"recook/internal/api/mobile"
_ "recook/internal/api/mobile/bill"
"recook/internal/api/store"
"recook/internal/api/vend"
"recook/internal/cron"
"recook/internal/dbc"
"recook/internal/mq"
"runtime"
"syscall"
"time"
cron2 "recook/internal/v2/lib/cron"
"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
// }
//}
runtime.GOMAXPROCS(runtime.NumCPU())
decimal.MarshalJSONWithoutQuotes = true
dbc.SetupMysql()
dbc.SetupRedis()
if configs.IsProductionEnv() {
mq.SetUpMq()
}
if configs.IsProductionEnv() {
mq.SetUpShaMa()
}
if configs.IsProductionEnv() {
gin.SetMode("release")
} else {
gin.SetMode("debug")
}
// 初始化配置
// 支付宝初始化
if err := alipay.InitAlipay(alipay.Config{
AppId: configs.AlipayAppid,
PrivateKey: configs.AlipayPrivateKey,
AliPublicKey: configs.AlipayAliPublicKey,
IsProduction: true,
}); err != nil {
log.Panicln("支付宝初始化错误", err)
}
/*将今天的数据copy一份分发到接下来的30天*/
manageServer := &http.Server{
Addr: ":8180",
Handler: manage.Service(),
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
}
appServer := &http.Server{
Addr: ":8181",
Handler: mobile.Service(),
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
}
vendServer := &http.Server{
Addr: ":8182",
Handler: vend.Service(),
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
}
storeServer := &http.Server{
Addr: ":8183",
Handler: store.Service(),
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
}
h5Server := &http.Server{
Addr: ":8184",
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()
})
c := cron2.GetCron()
idleConnClosed := make(chan struct{})
go func() {
sigint := make(chan os.Signal, 1)
signal.Notify(sigint, syscall.SIGINT, syscall.SIGTERM)
<-sigint
if err := manageServer.Shutdown(context.Background()); err != nil {
log.Printf("HTTP server Shutdown: %v", err)
}
if err := appServer.Shutdown(context.Background()); err != nil {
log.Printf("HTTP server Shutdown: %v", err)
}
if err := vendServer.Shutdown(context.Background()); err != nil {
log.Printf("HTTP server Shutdown: %v", err)
}
if err := storeServer.Shutdown(context.Background()); err != nil {
log.Printf("HTTP server Shutdown: %v", err)
}
if err := h5Server.Shutdown(context.Background()); err != nil {
log.Printf("HTTP server Shutdown: %v", err)
}
_ = mq.Conn.Close()
_ = mq.Conn1.Close()
c.Stop()
close(idleConnClosed)
}()
cron.Task(c.Cron)
c.Start()
if err := g.Wait(); err != nil {
log.Fatal(err)
}
}