3

I need Create MultiReader of slice []*bytes.Buffer
buffer_slice := ... (type []*bytes.Buffer)
When i write io.MultiReader(buffer_slice)

I get the error:
cannot use buffer_slice (type []*bytes.Buffer) as type io.Reader in argument to io.MultiReader: []*bytes.Buffer does not implement io.Reader (missing Read method).

But function signature MultiReader(readers ...Reader) Reader

I understand that the transmit array is meaningless, the actual question: besides the trivial cycle, there are no more options?

P.S. Sorry for my bad english.

1

1 Answer 1

4

Your slice should be type []io.Reader

b1 := &bytes.Buffer{}
b2 := &bytes.Buffer{}
buffers := []io.Reader{b1, b2}

multi := io.MultiReader(buffers...)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the advice, now everything is fine!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.