Go (Golang)
Go is a statically typed, garbage-collected language built for concurrency, simplicity, and fast builds.
Keywords
- break, case, chan, const, continue
- default, defer
- else, fallthrough, for, func
- go, goto, if, import
- interface, map, package, range
- return, select, struct, switch
- type, var
Language Highlights
- Goroutines (`go fn()`) spawn lightweight concurrent tasks.
- Channels synchronize and share data; select multiplexes operations.
- Interfaces are satisfied implicitly by method sets.
- Packages compile to single binaries with `go build`.
- Generics (Go 1.18+) enable type parameters, constraint interfaces, and instantiation.
Standard Library Essentials
- fmt for formatted I/O.
- net/http for HTTP servers and clients.
- context for cancellation and deadlines.
- encoding/json, encoding/xml, encoding/gob for serialization.
- sync and sync/atomic for primitives beyond channels.
- testing and testify for unit tests and table-driven cases.
Operators
- Arithmetic: + - * / % ++ --
- Comparison: == != < > <= >=
- Logical: && || !
- Bitwise: & | ^ &^ << >>
- Assignment: = += -= *= /= %= &= |= ^= &^= <<= >>=
- Short declaration: := for local variables.
Toolchain
- `go mod init`, `go mod tidy` manage dependencies.
- `go test ./...` runs parallel tests; benchmarks use `go test -bench`.
- `go fmt` and `go vet` enforce style and detect pitfalls.
- Delve (dlv) debugs local or remote processes.
Best Practices
- Keep packages focused; avoid circular dependencies.
- Prefer context propagation over globals for request-scoped data.
- Limit exported surface area; follow Effective Go conventions.
- Use `errgroup` and `context.WithTimeout` for resilient services.