1 2 3 4 5 6 7 8 9 10 11
| //go:embed public/* var Fs embed.FS
//静态资源加载 加载public下的所有文件 使静态资源可以通过http获取 router.Any("public/*filepath", func(context *gin.Context) { staticServer := http.FileServer(http.FS(Fs)) staticServer.ServeHTTP(context.Writer, context.Request) })
//加载单个文件 以下加载浏览器图标 router.StaticFileFS("/favicon.ico", "./public/static/favicon.ico", http.FS(Fs))
|