Files
go-learning/notes/00-cheatsheet.md

15 lines
845 B
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Ściągawka Go
## Złote zasady idiomatycznego Go
* **Błędy to wartości:** zawsze sprawdzaj `if err != nil`, opakowuj kontekstem przez `fmt.Errorf("doing x: %w", err)`, sprawdzaj przez `errors.Is` / `errors.As`.
* **Małe interfejsy:** definiuj interfejs po stronie konsumenta, zwykle 1–2 metody (np. `io.Reader`).
* **Zawsze zamykaj zasoby:** `defer resp.Body.Close()` lub `defer f.Close()`.
* **Współbieżność:** zawsze używaj `context.Context` do timeoutów i anulowania goroutines; zawsze testuj z `go test -race`.
* **Zero values:** projektuj struktury tak, żeby ich wartość zerowa była od razu użyteczna.
## Komendy `make`
* `make check` — `go vet ./...`
* `make lint` — `staticcheck ./...`
* `make test PKG=./exercises/01-core/01-basics` — testy jednego rozdziału z `-race`
* `make fmt` — `gofmt -w exercises`