1.并发
var waitGroup = new(sync.WaitGroup)
waitGroup.Add(num)
waitGroup.Wait()
func xxx(){
...
waitGroup.Done()
}
2.打印代码处理时间
func TimeCost(str string, start time.Time) {
terminal := time.Since(start)
fmt.Println(str, terminal)
}
func xxx(){
defer common.TimeCost("本次执行时间:", time.Now())
...
}
3.判断key是否在map中
if v, ok := m[key];ok{
存在
}
4.断言
if backtime, ok := LS[uuid][cid].Ele.Back().Value.(int); !ok {
fmt.Fprintf(os.Stderr, "断言失败")
return
}
Go语言常用代码
最新推荐文章于 2024-04-12 20:15:36 发布