The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
Bluelion

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

  •  
  •   Bluelion · Mar 28, 2023 · 1155 views
    This topic created in 1149 days ago, the information mentioned may be changed or developed.

    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  
       Apr 3, 2023
    我去,go 里面出现了 dao?


    你这个类型报错不是在 `tasks <- oneSlice` 那行
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1480 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 17:00 · PVG 01:00 · LAX 10:00 · JFK 13:00
    ♥ Do have faith in what you're doing.