V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
Bluelion
V2EX  ›  Go 编程语言

求解惑,同样是向 chan 里面塞切片

  •  
  •   Bluelion · 2023-03-28 12:00:50 +08:00 · 694 次点击
    这是一个创建于 396 天前的主题,其中的信息可能已经有所发展或是发生改变。

    channels 是一个切片,这样写通过了编译

     func (j *gameChannelKickJob) Produce(ctx context.Context, tasks chan<- interface{}) {
         channels, err := dao.GetAllActiveGameChannel(ctx, model.GAME_CHANNEL_ACTIVE)
          	tasks <- channels
      }
    

    当这样写,编译不通过提示 mismatched types ,同样是向 chan 塞切片,为啥啊

    func (j *gameChannelKickJob) Produce(ctx context.Context, tasks chan<- interface{}) {
    	channels, err := dao.GetAllActiveGameChannel(ctx, model.GAME_CHANNEL_ACTIVE)
    	for k,_ := range channels {
        	oneSlice := dao.GetSomeSliceData(ctx,channels[k])
            tasks <- oneSlice
        }
    }
    
    lysS
        1
    lysS  
       2023-04-03 12:51:31 +08:00
    我去,go 里面出现了 dao?


    你这个类型报错不是在 `tasks <- oneSlice` 那行
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1482 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 16:59 · PVG 00:59 · LAX 09:59 · JFK 12:59
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.