上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 22 下一页
摘要: { b:=2 fmt.Println(b) } fmt.Println(b) //这里读取不到上面代码块中的b,花括号可以什么条件都不跟单独为代码块来自为知笔记(Wiz) 阅读全文
posted @ 2019-12-20 00:39 离地最远的星 阅读(116) 评论(0) 推荐(0) 编辑
摘要: package main import ( "github.com/gin-gonic/gin" "topic.jtthink.com/src" ) func main() { router := gin.Default() v1 := router.Group("/v1/topics") { v1.GET("", src.GetTo... 阅读全文
posted @ 2019-12-20 00:38 离地最远的星 阅读(210) 评论(0) 推荐(0) 编辑
摘要: func init() { DBHelper, err = gorm.Open("mysql", "root:root@(115.159.59.129:3306)/test?charset=utf8&parseTime=True&loc=Local") DBHelper.SingularTable(true) DBHelper.DB().SetMaxIdleConns(... 阅读全文
posted @ 2019-12-20 00:38 离地最远的星 阅读(190) 评论(0) 推荐(0) 编辑
摘要: package main import ( "github.com/gin-gonic/gin" "net/http" ) func main() { //代码块 router := gin.Default() v1:=router.Group("/v1/topics") { v1.GET("", func(context *gin... 阅读全文
posted @ 2019-12-20 00:37 离地最远的星 阅读(129) 评论(0) 推荐(0) 编辑
摘要: 优雅关闭web服务 DBHelper, err = gorm.Open("mysql", "root:root@(115.159.59.129:3306)/test?charset=utf8&parseTime=True&loc=Local") if err != nil { log.Fatal("数据库初始化错误", err) //log.Fatal输出日志并且退出主程... 阅读全文
posted @ 2019-12-20 00:36 离地最远的星 阅读(681) 评论(0) 推荐(0) 编辑
摘要: 实现redis缓存装饰器,路由函数 func GetTopicDetail(context *gin.Context) { tid:=context.Param("topic_id") topics:=Topics{} DBHelper.Find(&topics,tid)//从数据库取 context.Set("dbResult",topics) //这里d... 阅读全文
posted @ 2019-12-20 00:36 离地最远的星 阅读(307) 评论(0) 推荐(0) 编辑
摘要: api的url设计规则 router := gin.Default() router.GET("/topic/:topic_id", func(context *gin.Context) { context.String(http.StatusOK,"获取帖子Id为%s",context.Param("topic_id")) }) router.Run() package m... 阅读全文
posted @ 2019-12-20 00:34 离地最远的星 阅读(709) 评论(0) 推荐(0) 编辑
摘要: 来自为知笔记(Wiz) 阅读全文
posted @ 2019-12-20 00:34 离地最远的星 阅读(81) 评论(0) 推荐(0) 编辑
摘要: String get(String key) { String value = redis.get(key); if (value == null) { if (redis.setnx(key_mutex, "1")) { //设置分布式锁,同一时刻只能有一个线程能进行此操作 // 3 min timeout to avoid mutex... 阅读全文
posted @ 2019-12-20 00:34 离地最远的星 阅读(1017) 评论(0) 推荐(0) 编辑
摘要: var RedisDefaultPool *redis.Pool func newPool(addr string) *redis.Pool { return &redis.Pool{ MaxIdle: 3, MaxActive: 0, IdleTimeout: 240 * time.Second, Dial: ... 阅读全文
posted @ 2019-12-20 00:33 离地最远的星 阅读(2772) 评论(0) 推荐(0) 编辑
上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 22 下一页