2024-07-29 21:32:27 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"log"
|
|
|
|
"log/slog"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"gitea.timerzz.com/kedaya_haitao/common/pkg/database"
|
|
|
|
dw_sdk "gitea.timerzz.com/kedaya_haitao/dw-sdk"
|
|
|
|
"gitea.timerzz.com/kedaya_haitao/dw-spider/options"
|
|
|
|
"gitea.timerzz.com/kedaya_haitao/dw-spider/spider"
|
2024-07-29 21:49:39 +08:00
|
|
|
"github.com/gofiber/fiber/v3"
|
|
|
|
"github.com/gofiber/fiber/v3/middleware/cors"
|
2024-07-29 21:32:27 +08:00
|
|
|
"github.com/golang/glog"
|
|
|
|
"gorm.io/gorm/logger"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
slog.Info(">>> BEGIN INIT<<<")
|
|
|
|
ctx, cancel := signal.NotifyContext(context.Background(), os.Kill, os.Interrupt)
|
|
|
|
defer cancel()
|
|
|
|
cfg, err := options.LoadConfig()
|
|
|
|
if err != nil {
|
|
|
|
glog.Fatalf("获取配置失败:%v", err)
|
|
|
|
}
|
|
|
|
db, err := database.InitDatabase(&cfg.DB)
|
|
|
|
if err != nil {
|
|
|
|
glog.Fatalf("初始化数据库失败:%v", err)
|
|
|
|
}
|
|
|
|
db.Logger = logger.New(
|
|
|
|
log.New(os.Stdout, "\r\n", log.LstdFlags),
|
|
|
|
logger.Config{
|
|
|
|
SlowThreshold: time.Second,
|
|
|
|
LogLevel: logger.Warn,
|
|
|
|
IgnoreRecordNotFoundError: false,
|
|
|
|
Colorful: true,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
client := dw_sdk.NewClient(cfg.Dw)
|
|
|
|
ctl := spider.NewController(client, db)
|
2024-07-29 21:49:39 +08:00
|
|
|
go ctl.Run(ctx)
|
|
|
|
r := fiber.New()
|
|
|
|
r.Use(cors.New())
|
|
|
|
|
|
|
|
r.Get("/health", func(ctx fiber.Ctx) error {
|
|
|
|
return ctx.SendString("ok")
|
|
|
|
})
|
|
|
|
|
|
|
|
if err = r.Listen(":8080"); err != nil {
|
|
|
|
glog.Warningf("server over: %v", err)
|
|
|
|
}
|
2024-07-29 21:32:27 +08:00
|
|
|
}
|