Gin 框架静态文件服务

当我们渲染的 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" />

Leave a comment

您的电子邮箱地址不会被公开。 必填项已用 * 标注