4

I am trying to make load balancer with container/ring of channels and I am having problems writing to them. Ring seems to take interface {} as type which causes problem when I try to write to it's assigned channel.

Error that comes out is

prog.go:11: invalid operation: chring.Value <- true (send to non-chan type interface {})

simplified code: http://play.golang.org/p/AJs2MV_UUC

package main

//import "fmt"
import "container/ring"

func main() {
    chring := ring.New(10)
    for i:=0;i<10;i++ {
        ch:=make(chan bool)
        chring.Value=ch
        chring.Value <- true //dies here
        chring = chring.Next()
    }   


}
4

1 回答 1

3

使用类型断言

chring.Value.(chan bool) <- true
于 2013-05-15T16:02:28.457 回答