![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
go_nsq
「已注销」
这个作者很懒,什么都没留下…
展开
-
一个统一处理出错的技巧
package mainimport ( "fmt" "sync")type WaitGroupWrapper struct { sync.WaitGroup}func (w *WaitGroupWrapper) Wrap(cb func()) { w.Add(1) go func() { cb() w.Done() }()}func test1() error { fmt.Println("test1") return nil}func test2() e原创 2020-10-22 02:12:42 · 62 阅读 · 0 评论 -
once只执行一次
package mainimport ( "fmt" "sync")func main() { One := &sync.Once{} for i := 0; i < 3; i++ { One.Do(func() { fmt.Println("just one") }) fmt.Println(11111) }}输出just one111111111111111原创 2020-10-22 00:41:13 · 95 阅读 · 0 评论 -
waitgroup包的warp(包装)
将sync.WaitGroup包装一层,代码优雅一些package mainimport ( "fmt" "sync")type WaitGroupWrapper struct { sync.WaitGroup}func (w *WaitGroupWrapper) Wrap(cb func()) { w.Add(1) go func() { cb() w.Done() }()}func main(){ w:= &WaitGroupWrapper{} w原创 2020-10-22 00:05:54 · 147 阅读 · 0 评论 -
svc包
go get github.com/judwhite/go-svc/svcpackage mainimport ( "github.com/judwhite/go-svc/svc" "log" "os" "syscall" "time")type pro struct {}func main() { pro :=&pro{} svc.Run(pro,syscall.SIGINT)}func (p *pro)Init( e svc.Environmen原创 2020-10-21 23:19:16 · 229 阅读 · 0 评论