-
静态文件服务
```go func main() { router := gin.Default() router.Static("/assets", "./assets") router.StaticFS("/more_static", http.Dir("my_file_sys -
路由分组
```go func main() { router := gin.Default() // 简单的路由组: v1 v1 := router.Group("/v1") { v1.POST("/login", loginEndpoint) -
重定向
HTTP 重定向很容易。 内部、外部重定向均支持。 ```go r.GET("/test", func(c *gin.Context) { c.Redirect(http.StatusMovedPermanently, "http://www.google.com/") }) ``` -
-
内置函数一览
[](https://cos.micuer.com/web/markdown/63f84c63a4e38.png) -
-
-
-
-
-
-
自定义函数
### 定义 - 首字母大写为公用方法 ```go func Html(str string) (res template.HTML) { return template.HTML(str) } ``` str 为接受参数 res 为返回值 ### 加载 ` -
模板自定义函数
//然后通过SetFuncMap方法把我们自定义的函数Set进去,并且要在LoadHTMLGlob加载模板之前 router.SetFuncMap(template.FuncMap{ "friendtime": common.GetFriendTime, }) 然后通过 -
显示转码HTML
这里需要用 template.HTML 处理一下 ```go func GetContent(c *gin.Context) { contentid := c.Param("contentid") res := model.ContentGetArticle(contentid) -