一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

Gogin静态文件的使用:自定义模板渲染器详解

时间:2026-06-24 08:34:49 编辑:袖梨 来源:一聚教程网

Go gin静态文件的使用

指定静态文件路径

engine.Static("/static", “static”)
  • 第一个参数是url
  • 第二个参数是url对应的文件夹
engine.StaticFS("/static", http.Dir(“static”))

前端引入静态文件

<link rel="stylesheet" href="/static/user/index.css" rel="external nofollow" >

自定义模板渲染器

使用"html/template"

要指定所有的html路径,不推荐

Gogin静态文件的使用、自定义模板渲染器详解

router := gin.Default()
html := template.Must(template.ParseFiles("test1.html", "test2.html"))
router.SetHTMLTemplate(html)
router.Run(":8080")

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持本站。

您可能感兴趣的文章:
  • Go语言gin框架中加载html/css/js等静态资源问题
  • Golang Gin Router冲突conflicts with existing wildcard问题
  • Go语言中的Web框架:从Gin到Echo
  • Go-Gin Web框架的实现示例
  • Go语言结合Gin框架快速实现分页查询接口
  • Go语言用Gin实现图书管理接口的实现示例
  • Go语言使用Gin处理路由参数和查询参数

热门栏目