type Engine struct { queue chan interface{} } // 推送请求到队列 func (e *Engine) Push(req interface{}) { e.queue <- req } // 开启服务协程 func (e *Engine) Serve() { go func() { for { req := <-e.queue // do some thing _ = req } }() }
type Engine struct { queue chan interface{} } // 推送请求到队列 func (e *Engine) Push(req interface{}) { e.queue <- req } // 开启服务协程 func (e *Engine) Serve() { go func() { for { req := <-e.queue // do some thing _ = req } }() }