示例#1
0
func (h *Config) Watch(ctx context.Context, stream server.Streamer) error {
	m := new(WatchRequest)
	if err := stream.Recv(m); err != nil {
		return err
	}
	return h.ConfigHandler.Watch(ctx, m, &configWatchStream{stream})
}
示例#2
0
func (h *Example) Stream(ctx context.Context, stream server.Streamer) error {
	m := new(StreamingRequest)
	if err := stream.Recv(m); err != nil {
		return err
	}
	return h.ExampleHandler.Stream(ctx, m, &exampleStreamStream{stream})
}
示例#3
0
func (h *Router) SelectStream(ctx context.Context, stream server.Streamer) error {
	m := new(SelectRequest)
	if err := stream.Recv(m); err != nil {
		return err
	}
	return h.RouterHandler.SelectStream(ctx, m, &routerSelectStreamStream{stream})
}
示例#4
0
func (h *Event) Stream(ctx context.Context, stream server.Streamer) error {
	m := new(StreamRequest)
	if err := stream.Recv(m); err != nil {
		return err
	}
	return h.EventHandler.Stream(ctx, m, &eventStreamStream{stream})
}
示例#5
0
func (e *Example) PingPong(ctx context.Context, stream server.Streamer) error {
	for {
		req := &example.Ping{}
		if err := stream.Recv(req); err != nil {
			return err
		}
		log.Printf("Got ping %v", req.Stroke)
		if err := stream.Send(&example.Pong{Stroke: req.Stroke}); err != nil {
			return err
		}
	}
}
示例#6
0
func (e *Example) Stream(ctx context.Context, stream server.Streamer) error {
	log.Info("Executing streaming handler")
	req := &example.StreamingRequest{}

	// We just want to receive 1 request and then process here
	if err := stream.Recv(req); err != nil {
		log.Errorf("Error receiving streaming request: %v", err)
		return err
	}

	log.Infof("Received Example.Stream request with count: %d", req.Count)

	for i := 0; i < int(req.Count); i++ {
		log.Infof("Responding: %d", i)

		if err := stream.Send(&example.StreamingResponse{
			Count: int64(i),
		}); err != nil {
			return err
		}
	}

	return nil
}