Go channel 实现自增长ID
1 //autoInc.go 2 3 package autoInc 4 5 type AutoInc struct { 6 start, step int 7 queue chan int 8 running bool 9 } 10 11 func New(start, step int) (ai *AutoInc) { 12 ai = &AutoInc{ 13 start: start, 14 step: step, 15 running: true, 16 queue: make(chan int, 4), 17 } 18 19 go ai.process() 20 return 21 } 22 23 func (ai *AutoInc) process() { 24 defer fu...阅读全文