os.ReadFile

The Go function that reads a whole file into memory in one call and returns its bytes and an error.

In more detail

It is ideal for small files such as configuration. For large or unbounded input, open the file and stream it instead, so memory use stays flat. Convert the bytes with string(data) to print them.

Example

back, err := os.ReadFile("probe.conf")

Related terms

Taught in

References