This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"dypid/global"
|
|
||||||
"dypid/internal/db"
|
"dypid/internal/db"
|
||||||
|
"dypid/internal/global"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"dypid/global"
|
|
||||||
"dypid/internal/db"
|
"dypid/internal/db"
|
||||||
|
"dypid/internal/global"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package db
|
package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"dypid/config"
|
"dypid/internal/config"
|
||||||
"dypid/global"
|
"dypid/internal/global"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/redis/go-redis/v9"
|
"github.com/redis/go-redis/v9"
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package api
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"dypid/global"
|
|
||||||
"dypid/internal/controller"
|
"dypid/internal/controller"
|
||||||
|
"dypid/internal/global"
|
||||||
"embed"
|
"embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RegRoutes(r *gin.Engine) {
|
func RegAPIService(r *gin.Engine) {
|
||||||
g := r.Group("/api") //初始化路由组 /api/xxxx
|
g := r.Group("/api") //初始化路由组 /api/xxxx
|
||||||
{
|
{
|
||||||
g.GET("/test", func(context *gin.Context) {
|
g.GET("/test", func(context *gin.Context) {
|
||||||
@@ -35,16 +35,16 @@ func RegRoutes(r *gin.Engine) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func RegWebService(r *gin.Engine, webDir embed.FS) {
|
func RegWebService(r *gin.Engine, webFiles embed.FS) {
|
||||||
assets, _ := fs.Sub(webDir, "web/dist/assets")
|
assets, _ := fs.Sub(webFiles, "web/dist/assets")
|
||||||
r.StaticFS("/assets", http.FS(assets))
|
r.StaticFS("/assets", http.FS(assets))
|
||||||
|
|
||||||
icon, _ := fs.ReadFile(webDir, "web/dist/favicon.ico")
|
icon, _ := fs.ReadFile(webFiles, "web/dist/favicon.ico")
|
||||||
r.GET("/favicon.ico", func(c *gin.Context) {
|
r.GET("/favicon.ico", func(c *gin.Context) {
|
||||||
c.Data(200, "image/x-icon", icon)
|
c.Data(200, "image/x-icon", icon)
|
||||||
})
|
})
|
||||||
|
|
||||||
indexHtml, _ := fs.ReadFile(webDir, "web/dist/index.html")
|
indexHtml, _ := fs.ReadFile(webFiles, "web/dist/index.html")
|
||||||
r.NoRoute(func(c *gin.Context) {
|
r.NoRoute(func(c *gin.Context) {
|
||||||
c.Data(200, "text/html; charset=utf-8", indexHtml)
|
c.Data(200, "text/html; charset=utf-8", indexHtml)
|
||||||
})
|
})
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"dypid/api"
|
"dypid/internal/config"
|
||||||
"dypid/config"
|
|
||||||
"dypid/internal/db"
|
"dypid/internal/db"
|
||||||
|
"dypid/internal/service"
|
||||||
"embed"
|
"embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
@@ -12,22 +12,23 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
//go:embed web/dist/*
|
//go:embed web/dist/*
|
||||||
var webDir embed.FS
|
var webFiles embed.FS
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
config.InitConfig()
|
config.InitConfig()
|
||||||
db.InitRedis()
|
db.InitRedis()
|
||||||
db.InitLocalDB()
|
db.InitLocalDB()
|
||||||
|
|
||||||
//初始化一个http服务对象
|
//初始化一个http服务对象
|
||||||
gin.SetMode(config.APPConfig.RunMode)
|
gin.SetMode(config.APPConfig.RunMode)
|
||||||
r := gin.Default()
|
r := gin.New()
|
||||||
|
r.Use(gin.Recovery())
|
||||||
|
r.Use(cors.Default()) //跨域设置
|
||||||
|
|
||||||
//跨域设置
|
|
||||||
r.Use(cors.Default())
|
|
||||||
//注册网页服务(Vue)
|
//注册网页服务(Vue)
|
||||||
api.RegWebService(r, webDir)
|
service.RegWebService(r, webFiles)
|
||||||
//注册API接口
|
//注册API接口
|
||||||
api.RegRoutes(r)
|
service.RegAPIService(r)
|
||||||
|
|
||||||
// 监听并在 0.0.0.0:8080 上启动服务
|
// 监听并在 0.0.0.0:8080 上启动服务
|
||||||
fmt.Printf("服务器正在运行:http://%s\n", config.APPConfig.Host)
|
fmt.Printf("服务器正在运行:http://%s\n", config.APPConfig.Host)
|
||||||
|
|||||||
Reference in New Issue
Block a user