article/cmd/article.go
timerzz 00e4f26d71
All checks were successful
Build image / build (push) Successful in 1m24s
update 修复文件问题
2025-03-30 21:20:13 +08:00

63 lines
1.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"context"
"flag"
"os"
"os/signal"
"gitea.timerzz.com/kedaya_haitao/article/service"
"gitea.timerzz.com/kedaya_haitao/common/pkg/database"
"gitea.timerzz.com/kedaya_haitao/common/pkg/web"
"gitea.timerzz.com/kedaya_haitao/common/structs/storage"
dw_sdk "gitea.timerzz.com/kedaya_haitao/dw-sdk"
"github.com/gofiber/fiber/v3"
"github.com/gofiber/fiber/v3/middleware/cors"
"github.com/gofiber/fiber/v3/middleware/recover"
"github.com/sirupsen/logrus"
)
func main() {
flag.Parse()
logrus.Info(">>> BEGIN INIT<<<")
ctx, cancel := signal.NotifyContext(context.Background(), os.Kill, os.Interrupt)
defer cancel()
// 初始化数据库
db, err := database.InitDefaultDatabase()
if err != nil {
logrus.Fatalf("init database failed: %v", err)
}
client, err := dw_sdk.InitDefaultDWClient()
if err != nil {
logrus.Fatalf("初始化redis失败%v", err)
}
// 初始化服务
r := fiber.New(fiber.Config{ErrorHandler: web.ErrHandle})
r.Use(cors.New(), recover.New())
stg := storage.NewStorage(db)
_ = stg.Article().AutoMigrate()
svc := []web.Register{
web.NewProbe(),
service.NewArticle(stg),
service.NewTools(stg, client), // 添加工具服务
}
for _, s := range svc {
s.Registry(r)
}
port := os.Getenv("PORT")
if port == "" {
port = "80"
}
if err = r.Listen(":"+port, fiber.ListenConfig{
EnablePrintRoutes: true,
GracefulContext: ctx,
}); err != nil {
logrus.Warningf("service over: %v", err)
}
}