8

I defined a struct as below, but always get the build error: “undefined: bytes in bytes.Buffer”

type test struct {
    id       int64
    Content    []byte
    Buffer     *bytes.Buffer
}
2
  • Also, make sure you actually want a pointer to bytes.Buffer. That struct has some "scratch space" internally, which is used to avoid unneeded allocations for small buffers. Commented Feb 22, 2017 at 13:12
  • I faced the same issue. The problem was that I had declared a variable name bytes! Commented Jul 7, 2022 at 1:56

1 Answer 1

20

You forgot about import statement.

import "bytes"
Sign up to request clarification or add additional context in comments.

Comments

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.