watcher/main/main.go
2024-04-10 17:36:56 +08:00

51 lines
1.1 KiB
Go

package main
import (
"context"
"github.com/gofiber/fiber/v3"
"github.com/golang/glog"
"haitao_watcher/pkg/database"
"haitao_watcher/pkg/model"
"haitao_watcher/pkg/options"
"haitao_watcher/pkg/pools"
"haitao_watcher/pkg/pusher"
"haitao_watcher/pkg/watcher"
"haitao_watcher/server"
"log/slog"
"os"
"os/signal"
)
func main() {
slog.Info(">>> BEGIN INIT<<<")
ctx := context.Background()
_ctx, cancel := signal.NotifyContext(ctx, os.Kill, os.Interrupt)
defer cancel()
cfg, _ := options.LoadConfig()
db, err := database.InitDatabase(&cfg.DB)
if err != nil {
glog.Fatalf("初始化数据库失败:%v", err)
}
pool := pools.NewProxyPool(cfg.Proxy.Subscribes)
pusherCtl := pusher.NewController(_ctx, db)
ch := make(chan model.PushMsg, 30)
pusherCtl.Consume(ch)
watcherCtl := watcher.NewController(_ctx, db, pool, ch)
r := fiber.New()
r.Static("/", "/work/dist")
api := r.Group("/api/v1")
server.NewWatcherController(watcherCtl).RegistryRouter(api)
server.NewPusherSvcController(pusherCtl).RegistryRouter(api)
if err = r.Listen(":2280"); err != nil {
glog.Warningf("server over: %v", err)
}
}