Skip to content
Rogue spell

Go

Ranks 1-3

The rogue's Sprint: a small language that compiles to one fast binary. Fast to build, fast to run, fast to hand to a server.

Wears the Classic spell Sprint.

Coming from Python: Functions, packages, and testing transfer directly. The new discipline is explicitness: every variable you ignore must be ignored on purpose, and errors are values you return, not exceptions you throw.

Advertisement

Summoning the language

Rank 1

First summoning

Install Go, make a module with go mod init, and run the classic. The language fits in an afternoon; the standard library does the heavy lifting.

package main

import "fmt"

func main() {
    fmt.Println("Hello, Azeroth")
}

// $ go run main.go
Rank 2

The temper

Errors are values: if err is not nil, you handle it, right there. And a web service is ten lines of standard library, no framework required for a first one.

http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintln(w, "ok")
})
log.Fatal(http.ListenAndServe(":8080", nil))
Rank 3

First real chore

Build the JSON API from the Python project ladder in Go instead: one endpoint, one struct, json.Marshal. Then run go build and feel the deploy: the output is ONE file you can copy to any server and run. No runtime, no dependencies.

type Spell struct {
    Name string `json:"name"`
    Rank int    `json:"rank"`
}
// json.NewEncoder(w).Encode(spells)
Back to the grimoireThe Programmer's GrimoirePython, the eight ranks, and every second spell.