Golang
Learn Golang
- Learn Golang from the official tutorial site: Tour of Go.
Code Style
- Code interpretability trumps everything else.
- Please conform to the Golang code style established in the following articles.
Naming
- The convention in Go is to use mixedCase rather than underscores to write multiword names.
- Packages are given lower case, single-word names; there should be no need for underscores or mixedCase.
-
Naming guide:
Type Internal Exported Packages lowercase Variables mixedCase MixedCase Function/Method Names mixedCase MixedCase Function/Method Parameters mixedCase Structs mixedCase MixedCase Exceptions MixedCase Constants mixedCase MixedCase
Code Documentation - GoDoc
- GoDoc extracts and generates documentation for Go programs.
- It runs as a web server and presents the documentation as a web page.
- Usage:
$ godoc [flag] [flag] -goroot=$GOROOT : Go root directory -http=addr : HTTP service address (e.g., '127.0.0.1:6060' or just ':6060')
- Example:
$ godoc -http=:6060
- By default, godoc looks at the packages it finds via
$GOROOT
and$GOPATH
(if set). This behavior can be altered by providing an alternative$GOROOT
with the-goroot
flag.
Profiling
- To profile a Go code using a web interface, run:
$ go tool pprof -http=localhost:8080 /tmp/cpu.pprof $ go tool pprof -http=localhost:8080 /tmp/mem.pprof
Here,
/tmp/cpu.pprof
and/tmp/mem.pprof
are the cpu and memory profiler output files. - To see time spent on each line, run:
$ go tool pprof /tmp/cpu.pprof $ list <packageName>
Leave a comment