liveBook · Manning

Goos

As explained in Learn Go with Pocket-Sized Projects

GOOS is the Go build setting that specifies the target operating system for compiled code.

GOOS specifies the target operating system for compiled Go code. Set it when building for a platform different from the machine running the build; ordinary builds use the machine’s environment value. section 12.1.1

Compile Go for WebAssembly

A small Go program can be compiled for a browser-based WebAssembly runtime with GOOS=js and GOARCH=wasm. The build produces main.wasm. On Windows, set the variables first, then run go build -o main.wasm. section 12.1.1

> GOOS=js GOARCH=wasm go build -o main.wasm

Use the executable build command to produce a WebAssembly binary with explicit target settings. section 12.1.1

How Learn Go with Pocket-Sized Projects covers it

How deep it goes
Defines GOOS, explains machine defaults, and demonstrates commands, while stopping short of compiler internals.
Examples
Uses GOOS=js GOARCH=wasm go build -o main.wasm and equivalent Windows set commands.
What it assumes
Assumes a basic Go program and module setup, then demonstrates target selection from the standard build workflow.
What you can do after
Apply it via Go build commands to produce binaries for an explicitly selected operating-system target.
How it connects
Connects GOOS with GOARCH, environment variables, Go build, WebAssembly, JavaScript, and browser runtimes.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Go with Pocket-Sized Projects. The section links point to the parts of the book it draws on.