通过遵循教程,我尝试连接前端(React)到后端API (Gin),但static.Serve不工作,错误提示如下:
cannot use static.Serve("/", static.LocalFile("./views", true)) (type "github.com/gin-gonic/gin".HandlerFunc) as type "github.com/supebirdgz/amgmt/vendor/github.com/gin-gonic/gin".HandlerFunc in argument to router.Use来源:
import (
"github.com/gin-gonic/gin"
"github.com/gin-gonic/contrib/static"
)
func main() {
router := gin.Default()
router.Use(static.Serve("/", static.LocalFile("./frontend", true)))
router.Run()
}Gin中有什么更新了吗?我试着用其他包替换静态包,仍然是一样的。
发布于 2019-01-29 15:01:51
您忘记加载文件路径,如下所示
r := gin.Default()
r.LoadHTMLGlob("dist/*.html") // load the built dist path
r.LoadHTMLFiles("static/*/*") // load the static path
r.Static("/static", "./dist/static") // use the loaded source
r.StaticFile("/hello/", "dist/index.html") // use the loaded source
r.Run(":8080")https://stackoverflow.com/questions/54414043
复制相似问题