上一页 1 ··· 27 28 29 30 31 32 33 34 35 ··· 40 下一页
摘要: package main import ( "encoding/json" "fmt" "reflect" ) type Movie struct { Title string `json:"title"` Year int `json:"year"` Price int `json:"rmb"` 阅读全文
posted @ 2021-10-30 09:48 专职 阅读(209) 评论(0) 推荐(0) 编辑
摘要: package main import ( "fmt" "reflect" ) type resume struct { // 反射解析结构体标签tag Name string `info:"name" doc:"我的名字"` Sex string `info:"sex"` } // 方法一:传递结 阅读全文
posted @ 2021-10-30 09:28 专职 阅读(616) 评论(0) 推荐(0) 编辑
摘要: 先重复一遍反射三定律: 1.反射可以将“接口类型变量”转换为“反射类型对象”。 2.反射可以将“反射类型对象”转换为“接口类型变量”。 3.如果要修改“反射类型对象”,其值必须是“可写的”(settable) 总结 下面详细说明了Golang的反射reflect的各种功能和用法,都附带有相应的示例, 阅读全文
posted @ 2021-10-29 16:38 专职 阅读(1127) 评论(0) 推荐(0) 编辑
摘要: package main import ( "github.com/gin-gonic/gin" "net/http" ) func main() { // 静态文件服务 router := gin.Default() router.Static("/assets", "./assets") // 阅读全文
posted @ 2021-10-29 10:37 专职 阅读(324) 评论(0) 推荐(0) 编辑
摘要: package main import ( "github.com/gin-gonic/gin" ) func main() { // HTTP重定向很容易,内部、外部重定向均支持 router := gin.Default() /* GET重定向 router.GET("/", func(cont 阅读全文
posted @ 2021-10-29 10:01 专职 阅读(295) 评论(0) 推荐(0) 编辑
摘要: package main import ( "fmt" "reflect" ) type User struct { Id int Name string Age int } func (u User) Call() { fmt.Println("user is called.") fmt.Prin 阅读全文
posted @ 2021-10-28 22:24 专职 阅读(51) 评论(0) 推荐(0) 编辑
摘要: package main import "fmt" type Reader interface { ReadBook() } type Writer interface { WriteBook() } // 具体类型 type Book struct {} func (b *Book) ReadBo 阅读全文
posted @ 2021-10-28 21:41 专职 阅读(759) 评论(0) 推荐(0) 编辑
摘要: 运行服务的返回类型为 :http.Handler 。gin.New(),gin.Default() 返回的就是此类型。使用&http.Server{....} 设置服务参数使用g.Go(func () error{ return server.ListenAndServe()}) 开启一个服务 pa 阅读全文
posted @ 2021-10-28 17:04 专职 阅读(109) 评论(0) 推荐(0) 编辑
摘要: package main import ( "github.com/gin-gonic/gin" ) func main() { router := gin.Default() // 后台路由 admin := router.Group("/admin") admin.GET("/t1", func 阅读全文
posted @ 2021-10-28 16:11 专职 阅读(46) 评论(0) 推荐(0) 编辑
摘要: package main import ( "fmt" "github.com/gin-gonic/gin" ) func main() { router := gin.Default() // 路由参数1,将匹配/user/mayanan和/user/,但是不会匹配/user //router.G 阅读全文
posted @ 2021-10-28 15:54 专职 阅读(349) 评论(0) 推荐(0) 编辑
上一页 1 ··· 27 28 29 30 31 32 33 34 35 ··· 40 下一页