Code-Memo

File handling and I/O

os and io
f, err := os.Open("input.txt")
if err != nil {
	return err
}
defer f.Close()

data, err := io.ReadAll(f)
bufio

Buffered reads/writes reduce syscalls.

scanner := bufio.NewScanner(f)
for scanner.Scan() {
	line := scanner.Text()
	_ = line
}
ioutil deprecation

ioutil is deprecated; use os.ReadFile, os.WriteFile, and io.ReadAll.

Path handling

Use path/filepath for filesystem paths (OS-aware separators), not path (URL-like).

Temporary files
f, err := os.CreateTemp("", "prefix-*")
io interfaces

Design APIs around io.Reader and io.Writer so buffers, files, network, and bytes.Buffer plug in uniformly.

fs.FS (Go 1.16+)

Embed files with embed and serve or read via fs.FS for testable filesystem abstractions.