liveBook · Manning

Go

As explained in Go in Practice, Second Edition

Go is a statically typed, compiled, open-source programming language designed for systems programming and large-scale software development.

Go is an open-source, statically typed, compiled language designed for practical systems programming. It is particularly suited to services and system-level processes built by teams working on large codebases. Its compiled programs include a runtime with garbage collection, trading some low-level control for simpler memory management. section 1.1 section 1.3 section 1.3.1

Go is also a development toolchain. The `go` command supports compilation, module-based dependencies, tests, formatting, and documentation. Packages group code and are imported by name; standard-library packages such as `fmt` and `net/http` provide common application building blocks. section 1.1 section 1.2.4

Run a small HTTP service

Initialize a project with `go mod init hellogo`, then save this as `main.go`: package main import ( "fmt" "net/http" ) func hello(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, "Hello, world!") } func main() { http.HandleFunc("/", hello) http.ListenAndServe("localhost:4000", nil) } Use `go run main.go` while developing, or `go build main.go` to create an executable. The `main` package supplies the entry point; `net/http` registers a handler and serves requests. section 1.5

Other Go techniques become useful as an application grows:

  • Use `go test` to exercise functions and `go test -cover` to check statement coverage. A string-reversal test demonstrates why processing text as bytes can fail where processing it as runes succeeds. section 1.2.4
  • Use structs, methods, and interfaces to connect types by the behavior they provide rather than by class inheritance. section 3.2
  • Handle ordinary failures as errors; reserve panics for severe abnormal conditions. Goroutines support concurrent execution, including concurrent web-server connections. section 4.0 section 1.3.4

Go is not the first choice for resource-constrained embedded systems: its runtime and garbage collector have a cost. For server deployment, a compiled Go binary contains the application, imported packages, and runtime, avoiding a separately installed language runtime. section 1.3 section 1.3.3

How Go in Practice, Second Edition covers it

How deep it goes
Defines the language, works through a runnable HTTP server and tool commands, then addresses design, errors, and advanced facilities.
Examples
Uses an HTTP hello-world server, a tested string-reversal program, and a Java-to-Go comparison of inheritance and interfaces.
What it assumes
Assumes general programming experience while teaching Go installation, project initialization, packages, and basic application structure.
What you can do after
Build it from scratch: initialize a Go module, run and build a small HTTP service, and test its functions.
How it connects
Connects modules and packages with testing, goroutines, garbage collection, interfaces, error handling, reflection, and code generation.

Also explained in

Compare how 11 books explain Go →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Go in Practice, Second Edition. The section links point to the parts of the book it draws on.