It is suggested that you introduce yourself to Golang by first completing the tour. Most topics are covered to help you hit the ground running.
Most Go idioms can then be learned by reading Effective Go. This is highly suggested before you begin writing Go code for production.
The Go Blog contains many useful articles going over how to use several essential Go features like go-routines, JSON, constants, etc.
All golang services written by Clever should be on Go 1.16.
The style guides used for Go are Effective Go and the community Go style guide. There are two tools that can be used to detect common mistakes.
go fmt
should be run in any directory that contains go files. It will automatically format the code.golint file.go
should be run for every go file. It will lint the code and return any issues it finds.
Optionally you can have Vim run the linters for you:
" highlight Go errors
let g:syntastic_go_checkers = ['golint', 'govet']
- Makefiles: A Go package should have a Makefile that runs "golint" on all files. See the sfncli Makefile as an example.
- toolchain version check
- testing
- gofmt
- golint
- go vet
- go test
-
emacs: Go has an official emacs mode that ships with a
gofmt
command. To get it to run on save, you can add this to your.emacs
:(add-hook 'before-save-hook 'gofmt-before-save)
-
sublime: Add GoSublime for code highlighting and
go fmt
on save. -
vim:
Sets are typically best represented by a map[key type]bool
structure where every boolean value is set to true
.
Since maps return the default value of the value type when a key does not exist, they will return false
(the default boolean value) when accessed with a nonexistent key.
This allows you to use code like:
crew := map[string]bool{
"Malcom": true,
"Zoe": true,
"Wash": true,
"Inara": true,
"Jayne": true,
"Kaylee": true,
"Simon": true,
"River": true,
"Shepherd": true,
}
// now we can use a map access like a boolean condition
if crew["River"] {
println("member of the crew!")
}
// alternatively the "comma ok" idiom obfuscates what is happening
if _, isCrew := crew["River"]; isCrew {
println("member of the crew!")
}
- (suggested) Full example of bool map set: https://play.golang.org/p/0NngCA8e6t
- Full example of comma ok set: https://play.golang.org/p/OCxq0U7olc
- Full example of slice set: https://play.golang.org/p/0NngCA8e6t
If you need more than addition and presence methods, please consider using a more full featured set implementation (https://github.com/fatih/set).
Drone should build your executable and it should be copied into Docker:
gliderlabs/alpine:3.2
- smaller image footprint
- requires additional build configuration
- see catapult/Makefile as an example
debian:jessie
- larger image
- no special configuration needed
- suggested if you have any dependencies you exec
- see shorty/Dockerfile as an example
We use go mod
to manage golang dependencies. See go/mod.
See our dep
documentation.
See our glide
documentation
See our godeps
documentation.
Essential Godeps for extended instruction.