provider/cmd/provider.go

51 lines
1.0 KiB
Go
Raw Normal View History

2024-08-26 16:28:37 +08:00
package main
2024-08-27 14:25:21 +08:00
import (
"os"
"gitea.timerzz.com/kedaya_haitao/common/pkg/database"
"gitea.timerzz.com/kedaya_haitao/common/pkg/web"
"gitea.timerzz.com/kedaya_haitao/common/structs/storage"
"gitea.timerzz.com/kedaya_haitao/provider/service"
"github.com/gofiber/fiber/v3"
"github.com/gofiber/fiber/v3/middleware/cors"
"github.com/gofiber/fiber/v3/middleware/recover"
"github.com/golang/glog"
)
2024-08-26 16:28:37 +08:00
func main() {
2024-08-27 14:25:21 +08:00
glog.Info(">>> BEGIN INIT<<<")
// 初始化数据库
db, err := database.InitDefaultDatabase()
if err != nil {
glog.Fatalf("init database failed: %v", err)
}
// 初始化服务
r := fiber.New()
r.Use(cors.New(), recover.New())
stg := storage.NewStorage(db)
if err = stg.Provider().AutoMigrate(); err != nil {
glog.Fatalf("autoMigrate database failed: %v", err)
}
svc := []web.Register{
web.NewProbe(),
service.NewProvider(stg),
}
for _, s := range svc {
s.Registry(r)
}
2024-08-26 16:28:37 +08:00
2024-08-27 14:25:21 +08:00
port := os.Getenv("PORT")
if port == "" {
port = "80"
}
if err = r.Listen(":" + port); err != nil {
glog.Warningf("service over: %v", err)
}
2024-08-26 16:28:37 +08:00
}