How to Read an Entire File into Memory in Go (os.ReadFile)

Read an entire file into memory in Go using the os.ReadFile function with a single line of code.

Use os.ReadFile to load the entire file contents into a byte slice in a single call.

package main

import (
	"fmt"
	"os"
)

func main() {
	data, err := os.ReadFile("/home/sd/crewai/src/go/go/README.md")
	if err != nil {
		fmt.Println("Error reading file:", err)
		return
	}
	fmt.Println(string(data))
}