Context) { //模板渲染 c.HTML(http.StatusOK,"index.tmpl",gin.H{ "title":"鸡尾酒", }) }) r.GET("/json", func(c *gin.Context) { data := gin.H{"name":"iverson","msg":"crossover","age":20} //json序列化之map c.JSON(http.StatusOK,data) }) var person struct{ Name string...
engin :=gin.Default() engin.GET("/user", func(c *gin.Context) {//设置 FuncMap 即前端可以调用的方法engin.SetFuncMap(template.FuncMap{"say":say,})//解析模板engin.LoadHTMLFiles("./view/template/master","./view/user/user")//渲染模板c.HTML(http.StatusOK,"user",gin.H{"title":"中间...
packagemainimport("github.com/gin-gonic/gin""net/http")funcmain(){app:=gin.Default()// 指明html加载文件目录app.LoadHTMLGlob("./html/*")app.Handle("GET","/",func(context*gin.Context){context.HTML(http.StatusOK,"index.html",gin.H{"title":"首页","fullpath":context.FullPath(),})}...
import ( "github.com/gin-gonic/gin" "net/http" ) func main() { //定义一个路由 r := gin.Default() //模板解析 r.LoadHTMLGlob("templates/**/*") //模板渲染 r.GET("/posts", func(c *gin.Context) { c.HTML(http.StatusOK, "posts/index.tmpl", gin.H{ "title": "Posts index",...
golang新教程-高级-Gin框架 课程简介 Golang课程主要介绍了Go语言的基础理论知识、开发方法与技巧,以及如何通过大量的线上训练,帮助学习者全面掌握服务端高并发、过载保护、水平扩展、服务降级、服务限流以及微服务等主流互联网产品的开发技术栈。课程从Golang环境搭建开始,详细讲解了Go...
"github.com/gin-gonic/gin" "net/http" ) func main() { //定义一个路由 r := gin.Default() //模板解析 r.LoadHTMLGlob("templates/**/*") //模板渲染 r.GET("/posts", func(c *gin.Context) { c.HTML(http.StatusOK, "posts/index.tmpl", gin.H{ ...