byte slice
A Go slice of bytes, the raw form data takes when it is read from or written to files, networks and encoders.
In more detail
os.ReadFile, io.ReadAll and json.Marshal all return a []byte. Convert it to text with string(data) and back with []byte("text"). Byte counts from len tell you how much data you have.
Example
conf := []byte("interval=30s\n")Related terms
- slice — A flexible, growable view over a list of values of one type, written like []string, and Go's everyday list.
- string — A sequence of characters, that is, a piece of text.
- bytes, kilobytes, megabytes — Units of data size: a kilobyte is about a thousand bytes, a megabyte about a million, a gigabyte about a billion.
- os.ReadFile — The Go function that reads a whole file into memory in one call and returns its bytes and an error.
Taught in
- Files and the os Package — Concurrent Systems Programming with Go
- Parsing JSON with encoding/json — Concurrent Systems Programming with Go