- 博客(6)
- 收藏
- 关注
原创 装饰器包装函数
package main import "github.com/gin-gonic/gin" func main(){ r:= gin.New() r.GET("/Test1",Test1) r.GET("/Test2",Test2) r.Run() } func Test1(c *gin.Context){ c.JSON(200,gin.H{"message":"Test1","code":1000,"result":""}) } func Test2(c *gin.Context){ c
2020-10-27 23:38:45 79
原创 kafka docker-compose go
在云主机上调用docker-compose脚本: version: '3' services: zookeeper: image: zookeeper ports: - "2182:2181" networks: - hbl_net kafka: image: wurstmeister/kafka depends_on: - zookeeper links: - zookeeper network
2020-10-27 01:03:20 104
原创 一个统一处理出错的技巧
package main import ( "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 61
原创 once只执行一次
package main import ( "fmt" "sync" ) func main() { One := &sync.Once{} for i := 0; i < 3; i++ { One.Do(func() { fmt.Println("just one") }) fmt.Println(11111) } } 输出 just one 11111 11111 11111
2020-10-22 00:41:13 94
原创 waitgroup包的warp(包装)
将sync.WaitGroup包装一层,代码优雅一些 package main import ( "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 145
原创 svc包
go get github.com/judwhite/go-svc/svc package main import ( "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 227
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人