Golang

关注公众号 jb51net

关闭
首页 > 脚本专栏 > Golang > Go gin静态文件的使用、自定义模板渲染器

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

作者:学亮编程手记

本文详细介绍了Gogin静态文件的使用方法,包括指定静态文件路径的两个参数用法,并讲解了前端引入静态文件及自定义模板渲染器的步骤;强调了使用"html/template"的重要性及路径设置建议

Go gin静态文件的使用

指定静态文件路径

engine.Static("/static", “static”)
engine.StaticFS("/static", http.Dir(“static”))

前端引入静态文件

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

自定义模板渲染器

使用"html/template"

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

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

总结

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

您可能感兴趣的文章:
阅读全文