如何在Gin中提供静态文件[重复]

This question already has an answer here:

by following the tutorial I try to connect the frontend (React) to backend api (Gin), but the static.Serve doesnt work, error prompted as below:

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

source:

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()
}

if something updated in Gin ? i tried replace static package with others, still the same. Any idea about that ?

</div>

you forget to load file path like

  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")