2025-05-28 16:19:21 +08:00

49 lines
789 B
Go

package main
import (
"log"
"github.com/gin-gonic/gin"
"github.com/spf13/viper"
)
func init() {
// 加载配置文件
viper.SetConfigName("config")
viper.SetConfigType("yaml")
viper.AddConfigPath("./config")
if err := viper.ReadInConfig(); err != nil {
log.Fatalf("Error reading config file: %s", err)
}
}
func main() {
// 创建 Gin 引擎
r := gin.Default()
// 注册路由
setupRoutes(r)
// 启动服务器
port := viper.GetString("server.port")
if port == "" {
port = "8080"
}
if err := r.Run(":" + port); err != nil {
log.Fatalf("Server failed to start: %v", err)
}
}
func setupRoutes(r *gin.Engine) {
// 健康检查
r.GET("/health", func(c *gin.Context) {
c.JSON(200, gin.H{
"status": "ok",
})
})
// TODO: 在这里添加其他路由
}