1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
   | package main
  import ( 	"embed" 	"github.com/gin-gonic/gin" 	"html/template" 	"io/fs" 	"net/http" )
  // 下面这一行非常重要!!!!!! //go:embed templates static var FS embed.FS
  func main() { 	gin.SetMode(gin.ReleaseMode)
  	router := gin.Default() 	templ := template.Must(template.New("").ParseFS(FS, "templates/*.html")) 	router.SetHTMLTemplate(templ)
  	fe, _ := fs.Sub(FS, "static") 	router.StaticFS("/static", http.FS(fe))
  	router.GET("/", func(c *gin.Context) { 		c.HTML(http.StatusOK, "index.html",gin.H{}) 	}) 	router.Run(":8080") }
 
 
   |