func Dial(url string, srv *rpc.Server) (client *rpc.Client, err error) { conn, err := direct.Dial(url) if err != nil { return } muxed, err := muxconn.Split(conn, 2) if err != nil { return } // Server on second, client on first (reverse of above) client = rpc.NewClient(muxed[0]) go srv.ServeConn(muxed[1]) return }
func run() { defer func() { donech <- true }() conn, err := direct.Dial("http://localhost:8080/streamz") if err != nil { log.Fatal("failed to direct dial:", err) } ch := streamz.Channelify(conn) timeout := time.After(time.Duration(rand.Intn(10)) * time.Second) for s := range ch { select { case <-timeout: return default: } log.Print(s.Key, "=", s.Value) } }