静态文件服务
当我们渲染的 HTML 文件中引用了静态文件时,我们需要配置静态 web 服务
r.Static("/static", "./static")
前面的 /static
表示路由 后面的 ./static
表示路径
func main() {
r := gin.Default()
r.Static("/static", "./static")
r.LoadHTMLGlob("templates/**/*")
// ... r.Run(":8080")
}
<link rel="stylesheet" href="/static/css/base.css" />
上次更新: 2025/04/03, 16:12:12