# Go

> GoBuild builds a Go module with the Go your group pins; a main package makes it a static binary.

**GoBuild builds the Go module in `src/` with the Go your group pins, runs `go test`, and builds a static binary when the module has a main package.**

Build system: `GoBuild`
Start one: `plinto create go-service HelloApp` (or `go-lib`)
Ships as: a static binary in an archive

## The project {#project}

The module is `src/`. Tests go next to the code, as `*_test.go` files, never in `tst/`.

```conf file=plinto.conf
{
  name = HelloApp
  version = 1.0
  build = GoBuild
  # main = src/cmd/server   a program: the package main `plinto run` starts (src for src/ itself)

  build-dependencies: {
    GoBuild = 1.0
    Go = 1.27
  }
  dependencies: {
    XText = v0.21.0      # golang.org/x/text, imported
  }
}
```

## A program {#program}

A project that names its `package main` is a program: `main = src` when it is `src/` itself, or `main = src/cmd/server` for one of its folders. `plinto run` builds it and starts it, with the arguments `args = [--port, 8080]` names first. A release carries the module for the projects that use it, and the program's binary next to it.

## Settings {#settings}

`configuration/GoBuild.config` takes these keys:

| Key | What it does |
|---|---|
| `cgo` | `true` to build with cgo (default `false`, so binaries are static) |
| `platforms` | the platforms a program's release carries a binary for, as well as the machine building it, such as `[linux-x64, linux-aarch64]` |

A program's binary for another platform is cross-compiled, which needs no C compiler with cgo off; with `cgo = true`, a binary is built for the machine building it only. Tests run on the machine building. GoBuild builds for `linux-x64`, `linux-aarch64`, `mac-x64`, `mac-aarch64`, `windows-x64` and `windows-aarch64`.

```
# configuration/GoBuild.config: Linux servers on x86-64 and on ARM
platforms = [linux-x64, linux-aarch64]
```

Builds use only the pinned Go and modules: no network, no module proxy, and none of your own `GO*` variables.

## Libraries {#libraries}

Go modules come in through an import: a group holds one version of each module.

```sh
$ plinto import go golang.org/x/text@v0.21.0
```

Each module is a package named after its path: `golang.org/x/text` is `XText`.

## What it releases {#releases}

The module's sources, and for a program `HelloApp-1.0-bin-<platform>.tar.gz` holding `HelloApp/bin/HelloApp`, built with `-trimpath`: one for the machine it builds on, and one for each other platform [`platforms`](#settings) lists.

- [Rust](rust.md): the other language of static binaries
- [Packages](../concepts/packages.md#imports): imports, for every language
- [Deployments](../concepts/deployments.md): putting a binary on servers
