- introduction to the go programming language (golang) for developers familiar with other languages
- from practitioners for practitioners
- a little bit of the history of go, comparison with other languages (chart)
- many tiny fully self-contained coding examples to exemplify common coding patterns and pitfalls in golang
- distilled version: save you time reading a thick textbook or watch hours of tutorials (maybe)
- focus on relevant features and examples
- Go Playground https://go.dev/play/
- A Tour Of Go https://go.dev/tour/list
- Go By Example https://gobyexample.com/
- How to write Go code https://go.dev/doc/code
- Effective Go https://go.dev/doc/effective_go
- Go Blog https://go.dev/blog/strings
- Downloads https://go.dev/dl/
- Rob Pike, Lexical Scanning in Go (channels) - https://www.youtube.com/watch?v=HxaD_trXwRE
- Liz Rice, Building a container from scratch in Go (unix system commands) - https://www.youtube.com/watch?v=Utf-A4rODH8
- simplicity - simple, concise and C-inspired syntax
- shadowing - shadowing variables based on scope
- interface - interface, type casts and type conversions, no generics
- pointers - pointers work very much like they do in C
- functional - functional programming
- variadic - introduction to variadic functions
- defer - use defer when you don't want to forget to clean up
- panic - recover from panics
- mapsandslices - basic operations with maps and slices
- safemap - a thread safe map implementation
- jsoninjsonout - parse and serialize json payloads
- duck - duck typing, no need to explicitly declare which interfaces are implemented
- composition - composition over inheritance
- oop - limitations regarding overriding functions, workaround using functional programming
- concurrency - use go routines for concurrent execution
- channel - creative use of goroutines and channels
- workerpool - combine go routines with go channels to send jobs to workers in a pool
- fanoutfanin - use worker pool to fan-out work and main thread to fan-in results
- producerconsumer / producer sends work to consumer via channel
- packages - importing and using packages, packages live inside a directory, everything uppercase is visible from outside the package
- module - manage package versions and dependencies
- aws - use aws sdk to interact with amazon web services
- options - functional options
- context - use go context to manage lifecycle of long-running tasks with cancel and / or timeout
- errors - errors.As(), errors.Is()
- tinywebservice - a tiny web service using the http package from the standard library
- controlc - capture ctrl-c OS signal, then wait for all goroutines to finish
- shell execute shell command
- shellong execute long running shell command
- File I/O and HTTP
- init function
- Commandline parameters
- webservice - building REST APIs using viper, cobra, gorilla mux, zerolog and other frameworks
- https://github.com/aws/aws-sdk-go-v2 - AWS SDK
- https://github.com/IBM/sarama - Kafka library
- https://github.com/rs/zerolog - structured logging
- https://github.com/gorilla/mux - http web services
- https://github.com/spf13/cobra - cli commands
- https://github.com/spf13/viper - configuration
go mod init
go mod tidy
go get somedomain.com/somepackage
go build
GOOS=linux GOARCH=arm go build -o myprogram myprogram.go
go test -v
go test -bench=.
Note: Runtime of benchmarked function must converge!
https://dave.cheney.net/2013/06/30/how-to-write-benchmarks-in-go
go test -race
goldie - easy testing with golden files
https://github.com/sebdah/goldie
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
golangci-lint run
https://golangci-lint.run/usage/configuration/#config-file
pprof - use pprof for heap profiling etc
Profile interactively for example with
go tool pprof http://localhost:8080/debug/pprof/heap
then use web
command.
https://jvns.ca/blog/2017/09/24/profiling-go-with-pprof/
- Core features
- compiled
- statically typed
- garbage collected
- statically linked
- C-style pointers
- no objects (structs and composition instead)
- no generics
- no method overloading
- conventions (tests, exported functions, init function etc.)
- Strong support for concurrency built in (channels and concurrent execution as first class object, suited for multi-core architectures)
- History of golang and resources, Rob Pike et al.
- "Young" language
- Easy to transition, especially if you know a little about C (structs, pointers)
- Intellij Goland and debugging with https://github.com/go-delve/delve
- Semantic versioning