摘要: 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 专职 阅读(52) 评论(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 专职 阅读(819) 评论(0) 推荐(0) 编辑
摘要: 运行服务的返回类型为 :http.Handler 。gin.New(),gin.Default() 返回的就是此类型。使用&http.Server{....} 设置服务参数使用g.Go(func () error{ return server.ListenAndServe()}) 开启一个服务 pa 阅读全文
posted @ 2021-10-28 17:04 专职 阅读(138) 评论(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 专职 阅读(48) 评论(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 专职 阅读(351) 评论(0) 推荐(0) 编辑
摘要: package main import ( "fmt" "github.com/gin-gonic/gin" ) func main() { router := gin.Default() router.GET("/cookie", func(context *gin.Context) { // 获 阅读全文
posted @ 2021-10-28 14:50 专职 阅读(548) 评论(0) 推荐(0) 编辑
摘要: package main import ( "github.com/gin-gonic/gin" "github.com/gin-gonic/gin/binding" "github.com/go-playground/validator/v10" "net/http" "time" ) type 阅读全文
posted @ 2021-10-28 14:23 专职 阅读(377) 评论(0) 推荐(0) 编辑
摘要: package main import ( "github.com/gin-gonic/gin" "log" "time" ) func Logger() gin.HandlerFunc { return func(context *gin.Context) { t := time.Now() // 阅读全文
posted @ 2021-10-28 10:28 专职 阅读(52) 评论(0) 推荐(0) 编辑
摘要: package main import ( "github.com/gin-gonic/gin" "net/http" "time" ) func main() { // 自定义http配置1 //router := gin.Default() //router.GET("/", func(cont 阅读全文
posted @ 2021-10-28 09:53 专职 阅读(219) 评论(0) 推荐(0) 编辑