54 lines
1.1 KiB
Go
54 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/gofiber/fiber/v3"
|
|
"github.com/gofiber/fiber/v3/middleware/logger"
|
|
"github.com/spf13/viper"
|
|
|
|
"fafa-crawler/src/controller"
|
|
)
|
|
|
|
func main() {
|
|
// 初始化配置
|
|
initConfig()
|
|
|
|
app := fiber.New()
|
|
|
|
// 添加日志中间件
|
|
app.Use(logger.New())
|
|
|
|
// Initialize controller and services
|
|
ctrl := controller.Controller{}
|
|
|
|
// Set up routes
|
|
app.Get("/data", ctrl.GetData)
|
|
app.Post("/data", ctrl.PostData)
|
|
|
|
// 美团数据同步商品库数据和图片
|
|
app.Post("/meituan/data/sync", ctrl.SyncMeiTuanData)
|
|
// 思迅数据同步商品库数据和图片
|
|
app.Post("/sixun/data/sync", ctrl.SyncSiXunGoodsData)
|
|
|
|
// Start the server
|
|
port := viper.GetString("server.port")
|
|
if port == "" {
|
|
port = "3001"
|
|
}
|
|
log.Fatal(app.Listen(":"+port, fiber.ListenConfig{EnablePrefork: true}))
|
|
}
|
|
|
|
func initConfig() {
|
|
// 设置配置文件路径和类型
|
|
viper.SetConfigFile("./config/config.toml")
|
|
viper.SetConfigType("toml")
|
|
|
|
// 读取配置文件
|
|
err := viper.ReadInConfig()
|
|
if err != nil {
|
|
log.Printf("Warning: unable to read config file: %s", err)
|
|
return
|
|
}
|
|
}
|