Files
dypid/main.go
T

44 lines
883 B
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 (
"dypid/internal/config"
"dypid/internal/db"
"dypid/internal/service"
"embed"
"fmt"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
)
//go:embed web/dist/*
var webFiles embed.FS
func main() {
config.InitConfig()
db.InitRedis()
db.InitLocalDB()
//初始化一个http服务对象
gin.SetMode(config.APPConfig.RunMode)
r := gin.New()
if config.APPConfig.RunMode == "debug" {
r.Use(gin.Logger()) //日志处理
}
r.Use(gin.Recovery()) //错误处理
r.Use(cors.Default()) //跨域设置
//注册网页服务(Vue
service.RegWebService(r, webFiles)
//注册API接口
service.RegAPIService(r)
// 监听并在 0.0.0.0:8080 上启动服务
fmt.Printf("服务器正在运行:http://%s\n", config.APPConfig.Host)
err := r.Run(config.APPConfig.Host)
if err != nil {
fmt.Println("服务启动失败:", err)
return
}
}