golang
silver9886
原网易博客:http://blog.163.com/silver9886@126/
展开
-
gin框架传入的gin.context参数是池化的
统一入口,将*gin.Context转化为context.Background(),调用controller。将context作为参数传递,而不再使用*gin.Context作为参数。2. 实现了context接口,导致context.withvalue(*gin.context,key,value).并不会有编译错误。2. 但是gin.context又实现了context的接口。因此,可以当作context去使用。1. 池化导致了复用后的ctx将会将之前使用的ctx中的内容进行覆盖。原创 2024-08-05 18:39:02 · 315 阅读 · 0 评论 -
golang优化命令执行
直接export即可。原创 2022-09-18 15:51:41 · 289 阅读 · 0 评论 -
gorm 的使用上的坑
func (a *RuleTarget) DelSystemRuleTargets( ctx context.Context, targets []*pbWeb.RuleTarget,) (successCount int32, err error) { db := database.GetDB(ctx) for _, target := range targets { // 注意如果是uid层面的删除,要级联删除cid和aid的数据 if...原创 2021-05-24 17:04:32 · 664 阅读 · 0 评论 -
gorm中db.RecordNotFound方法的使用,何时报这个错误
如果是多条记录,ruleTargets := []*RuleTarget{}db := database.GetDB(ctx)db = db.Select("distinct " + column)db = db.Where("rule_targets.account_id in (?)", uids)db.Find(&ruleTargets)这样是不会有db.error的错误的。因为是多条记录的返回。如果是单条记录:ruleTargets := .原创 2021-05-20 20:36:17 · 4605 阅读 · 0 评论 -
gorm model方法的使用
ruleTarget := NewRuleTarget()ruleTarget.RuleID = 0ruleTarget.UserID = 1ruleTarget.AccountID = 2ruleTarget.CampaignID = 3ruleTarget.AdGroupID = 4ruleTarget.ID = 29db.Model(ruleTarget).Update(map[string]interface{}{ "RuleID": 20,})Model 方法中传入的对.原创 2021-05-11 22:20:22 · 1771 阅读 · 1 评论 -
golang 中对slice的使用中的index问题 和golang相关坑
一般golang中会删除slice其中一个元素,并用append拼接起来,而且好像不会有越界问题。但是很多时候,index不争气会直接报panic,slice bounds out of range。这里研究下:1.sxw := []int{1, 2, 3, 4}fmt.Printf("s;%v", cap(sxw))对于这种初始化的slice,cap和len都是4,不会有任何变化2.sxw := []int{1, 2, 3}fmt.Printf("s;%v", cap...原创 2021-04-22 15:22:04 · 1353 阅读 · 0 评论 -
core文件获取等问题
ulimit -c unlimitedCd /proc/92477 cat limitsprlimit --pid xxx core=xxx可以改单个进程的rlimitgdb ./skynet core文件对go文件的core获取注意golang中要设置GOTRACEBACK原创 2021-03-17 10:48:02 · 338 阅读 · 0 评论 -
golang pprof的使用
go tool pprof http://9.141.63.142:10003/debug/pprof/heap(注意ip可以是远端的程序执行机器的ip)go tool pprof -inuse_space -cum -svg http://9.198.134.75:6666/debug/pprof/heap > heap.svggo tool pprof -http=:20001 /usr/local/app/pprof/pprof.weishi.weishi_huodong_qualifi原创 2020-07-15 12:49:34 · 230 阅读 · 0 评论