Gin Web Framework
Gin is a web framework written in Go (Golang). It features a martini-like API with performance that is up to 40 times faster thanks to httprouter. If you need performance and good productivity, you will love Gin.
`package web
import (
"fmt"
"github.com/gin-gonic/gin"
)
func init() {
fmt.Println("启动web服务")
run()
}
func run() {
go func() {
r := gin.Default()
r.LoadHTMLGlob("dist/.html") // 添加入口index.html
//r.LoadHTMLFiles("dist//*") // 添加资源路径
r.Static("/js", "./dist/js") // 添加资源路径
r.Static("/css", "./dist/css") // 添加资源路径
r.Static("/img", "./dist/img") // 添加资源路径
r.Static("/fonts", "./dist/fonts") // 添加资源路径
r.Static("/media", "./dist/media") // 添加资源路径
r.StaticFile("/favicon.ico", "./dist/favicon.ico") // 添加资源路径
r.StaticFile("/", "dist/index.html") //前端接口
r.Run(":8000")
}()
}`
1.在go项目下新建web目录,新建web.go文件粘贴进以上内容
2.vue打包好的dist放在go目录下
3.main.go中加入引用"github.com/gin-gonic/gin"
4.go.mod 加入github.com/gin-gonic/gin v1.7.7