Skip to content

Add Go to an existing workspace

Use the init generator to wire up the gonx inference plugin in an existing Nx workspace that was not created with the gonx preset.

nx g @naxodev/gonx:init

This registers @naxodev/gonx under plugins in nx.json. Once registered, the plugin scans your workspace for go.mod files and infers Nx targets from them automatically.

OptionTypeDefaultDescription
addGoDotWorkbooleanfalseCreate a go.work file and register all Go modules in it.

Pass --addGoDotWork if you want a Go workspace (go.work) at the repo root:

nx g @naxodev/gonx:init --addGoDotWork

After init, add Go projects in one of two ways:

Generate a new application or library:

nx g @naxodev/gonx:application apps/my-api
nx g @naxodev/gonx:library libs/my-lib

Or drop a go.mod into an existing directory. The inference plugin picks it up automatically — no project.json required.

Once a go.mod is present in a directory, the plugin infers the following targets:

TargetAvailable onDescription
buildApplications onlyCompile the Go binary.
serveApplications onlyRun the application locally.
testApplications and libsRun go test.
tidyApplications and libsRun go mod tidy.
lintApplications and libsRun the configured Go linter.
generateApplications and libsRun go generate.
nx-release-publishApplications and libsPublish via nx release.

Applications are detected by the presence of a main.go containing package main and func main(, or a cmd/ directory.

nx show project my-api

The project appears in the graph with its inferred targets — no project.json required.