Skip to content

Chapter 1 of 7

Language Fundamentals and Project Structure

Go (often called Golang) is an open-source, statically typed, compiled language developed at Google by Robert Griesemer, Rob Pike, and Ken Thompson. It is designed around simplicity, strong concurrency support, and predictable performance, which is why it has become a common choice for backend services, CLI tools, and infrastructure software. Every Go source file begins with a package declaration, and a program becomes an executable only when it lives in package main and defines func main(). Capitalization controls visibility within this packaging: identifiers starting with an uppercase letter are exported and accessible from other packages, while lowercase identifiers remain private to their package. Beyond ordinary imports, Go supports blank imports import _ "pkg" that run side effects (commonly used to register database drivers), aliased imports such as import f "fmt", and dot imports that bring names into the current namespace. Files can also be conditionally compiled using build constraints like //go:build linux && amd64 or filename suffixes such as _linux.go and _amd64.go.

Go's basic type system is intentionally small. The numeric types span signed and unsigned integers of multiple widths (int, int8...int64, and their unsigned counterparts), floats (float32, float64), and complex numbers (complex64, complex128). The aliases byte for uint8 and rune for int32 handle byte and Unicode code-point work. Every type has a deterministic zero value: numeric types are 0, bool is false, strings are "", and reference-like types (pointers, slices, maps, channels, interfaces, functions) are nil. This makes Go programs easier to reason about because variables always start in a known state. Variables can be declared explicitly with var x int = 10, with inferred types using var y = "hello", or with the short form z := 42 inside functions. For repeated constant values, the iota keyword inside const blocks produces successive integer values, which is the idiomatic way to write enumerations.

Pointers in Go are restricted to safe use: &x takes the address of x, and *p dereferences a pointer to read or write the underlying value. Unlike C, Go disallows pointer arithmetic, so pointers cannot wander outside the bounds of allocated memory. The distinction between new(T) and make(T, args) is also important: new allocates zero-valued memory and returns a *T, while make is reserved for slices, maps, and channels, returning an initialized value (not a pointer). Go programs depend on packages through Go modules. A module is initialized with go mod init module-name, and its dependencies live in go.mod with checksums in go.sum. Running go mod tidy synchronizes those files with the actual imports; go mod vendor copies dependencies into a vendor/ directory for reproducible or air-gapped builds. go.work files, introduced in Go 1.18, let developers work on multiple modules together without replace directives. The retract directive can mark a published version as unsafe to use, and -trimpath removes local filesystem paths from binaries for reproducible production builds.

All chapters
  1. 1Language Fundamentals and Project Structure
  2. 2Composite Types and Data Structures
  3. 3Functions, Methods, and Interfaces
  4. 4Error Handling, defer, and Formatting
  5. 5Concurrency
  6. 6Standard Library: I/O, Encoding, Web, and Time
  7. 7Testing, Tooling, and Runtime Internals

Drill it

Reading is not remembering. These come from the Go Programming deck:

Q

What is Go (Golang)?

Go is an open-source programming language developed at Google by Robert Griesemer, Rob Pike, and Ken Thompson. It is statically typed, compiled, and designed fo...

Q

How do you declare a variable in Go?

You can declare variables using:var x int = 10var y = "hello" (type inferred)z := 42 (short declaration, only inside functions)

Q

What is a goroutine?

A goroutine is a lightweight thread managed by the Go runtime. You start one with the go keyword:go myFunction()Goroutines are multiplexed onto OS threads and a...

Q

How do you create a channel in Go?

Use the make function:ch := make(chan int) — unbufferedch := make(chan string, 5) — buffered with capacity 5Channels are used to communicate between goroutines...