jesseduffield / jesseduffield/notes

Go IO Cookbook: code review

Open
#2 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
219
Forks
9
PR merge metrics
No merged PRs in 30d

Description

Nice job. I performed a Go code review: correct, maintainable, reasonably efficient, and readable. Here are some suggestions for your directly using io.Reader code.

```
// Directly using io.Reader

package main

import (
"fmt"
"io"
"log"
"strings"
)

func main() {
rdr := strings.NewReader("this is the stuff I'm reading")
var data []byte
buf := make([]byte, 0, 4)
for {
n, err := rdr.Read(buf[:cap(buf)])
buf = buf[:n]

data = append(data, buf...)

if err != nil {
if err == io.EOF {
break
}
log.Fatal(err)
}
}
fmt.Println(string(data))
}
```

Playground: https://play.golang.org/p/k1O3Qf5K39k

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.