Go/Naming Conventions
From charlesreid1
Go Naming Conventions: https://smartystreets.com/blog/2018/10/go-naming-tutorial
Note
Exported vs Unexported names
- Anything (variable, type, or function) that starts with a capital letter is exported, and visible outside the package.
- Anything that does not start with a capital letter is not exported, and is visible only inside the same package.
Use single-character receiver names
package main
import "fmt"
func main() {
new(Printer).Print(
"Use only the first letter of a type as the receiver for its methods (oh, wait...), " +
"and (per tip #5) make sure the receiver is exported")
}
type Printer struct{}
func (P *Printer) Print(Message string) (N int, Err error) {
return fmt.Println(Message)
}
Use single-letter variable names
package main
import "fmt"
func main() {
new(Printer).Print("Use single-letter variables whenever possible")
}
type Printer struct{}
func (P *Printer) Print(M string) (N int, E error) {
return fmt.Println(M)
}
Flags
| Go notes on Go
Go/Strings · Go/Arrays · Go/Slices
Go/Lists · Go/Maps · Go/Stacks · Go/Queues
Go/Naming Conventions · Go/Design Patterns
Go/Timing · Go/Profiling · Go/Benchmarking
Go/Tests · Go/Travis CI · Go/Makefiles
our vim + go setup uses custom solarized colors for Golang
|