Reference: Go Wiki: Go Code Review Comments#
- ## Gofmt ✅ 2024-03-07
- goimports ✅ 2024-03-07
- ## Comment Sentences ✅ 2024-03-07
- full sentences
- https://go.dev/doc/effective_go#commentary
- ## Contexts
- ## Copying ✅ 2024-03-07
- ## Crypto Rand ✅ 2024-03-07
- use
crypto/rand
instead ofmath/rand
for generate keys - print to hexadecimal or base64
- use
- ## Declaring Empty Slices ✅ 2024-03-07
var t []string
nil, JSON encode tonull
t:=[]string{}
non-nil zero-length, JSON encode to[]
- ## Doc Comments ✅ 2024-03-07
- top-level, exported names
- non-trivial unexported type or function declarations
- https://go.dev/doc/effective_go#commentary
- ## Don’t Panic
- https://go.dev/doc/effective_go#errors. ✅ 2024-03-07
- https://go.dev/doc/effective_go#recover. ✅ 2024-03-07
- recover within a package
- ## Error Strings ✅ 2024-03-07
- unless logging, not be capitalized
- ## Examples ✅ 2024-03-07
- ## Goroutine Lifetimes ✅ 2024-03-07
- make it clear when/whethr they exit
- keep simple to obvious or document
- ## Handle Errors ✅ 2024-03-07
- https://go.dev/doc/effective_go#errors ✅ 2024-03-07
- ## Imports ✅ 2024-03-07
- avoid rename
- rename the most local or project-specific import
- organize in groups
- goimports ✅ 2024-03-07
- ## Import Blank ✅ 2024-03-07
- only in main or test
- ## Import Dot ✅ 2024-03-07
- sovle circular dependencies when test
- not use in other
- ## In-Band Errors ✅ 2024-03-07
- prefer extra valid value then in-band error
- ## Indent Error Flow ✅ 2024-03-07
- minimal indentation of normal code
- ## Initialisms ✅ 2024-03-07
- initialisms with a consistent case
- ## Interfaces
- ## Line Length
- ## Mixed Caps ✅ 2024-03-07
- https://go.dev/doc/effective_go#mixed-caps
- Initialisms ✅ 2024-03-07
- ## Named Result Parameters ✅ 2024-03-07
- don't name result parameters just to avoid declaring
- ## Naked Returns ✅ 2024-03-07
- Named Result Parameters ✅ 2024-03-07
- ## Package Comments ✅ 2024-03-07
- ## Package Names ✅ 2024-03-07
- ## Pass Values ✅ 2024-03-07
- don't pass pointers just to save a few bytes
- ## Receiver Names ✅ 2024-03-07
- short but consistent
- ## Receiver Type ✅ 2024-03-07
- finally, when in doubt, use a pointer receiver
- ## Synchronous Functions ✅ 2024-03-07
- prefer synchronous functions over asynchronous ones
- ## Useful Test Failures
if got !=tt.wang{t.Errorf("Foo(%q) = %d; want %d", tt.in, got, tt.want) // or Fatalf, if test can't test anything more past this point
}- table-driven test.
- ## Variable Names ✅ 2024-03-07
- short rather than long
- basic rule: the further from its declaration that a name is used, the more descriptive the name must be
- the Google Go Style Guide.