dw-spider/cmd/main.go

45 lines
1.0 KiB
Go
Raw Normal View History

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"
"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)
ctl.Run(ctx)
}