@naxodev/gonx v1.2.0
gonx - Very opinionated Nx plugin for Go/Golang
IMPORTANT: This project is a fork of @nx-go/nx-go. We give most of the credit to the original maintainers. We've built upon their excellent foundation to modernize the plugin for the latest Nx features.
The philosophy of gonx is to generate a non-invasive tooling to work with Go and Nx, heavily relying on inferred tasks and modern Nx features.
✨ Features
- ✅ Generate Go Applications
- ✅ Customizable Go module setup
- ✅ Well-structured Go code scaffolding
- ✅ Generate Go Libraries
- ✅ Full Nx integration
- ✅ Inferred Tasks: Build, Tidy, Test, Run, and Lint
- ✅ Cacheable Tasks: Build, Tidy, Test, and Lint
- ✅ GraphV2 Support
- ✅ Version Actions for Go release
- ✅ Nx Release Publish executor to release to list the module on the registry
- ✅ Use official Go commands in the background
- ✅ Efficient caching and dependency graph tools for Go projects
🚀 Getting started
You need to have a stable version of Go installed on your machine. And... you are ready!
Generate a Nx workspace with Go support
npx create-nx-workspace go-workspace --preset=@naxodev/gonxAdd to an existing workspace
nx add @naxodev/gonxDon't want to use a multi-module Go workspace?
The plugin configures a multi-module Go workspace by default, to simplify project management and improve the quality of the Nx graph. If you don't want to take advantage of this feature, you can use generator convert-to-one-mod after the plugin installation. Generators will automatically adapt to your configuration.
nx g @naxodev/gonx:convert-to-one-mod📖 Generators & executors
Generators
| Generator | Description |
|---|---|
application | Generate a Go application |
library | Generate a Go library |
convert-to-one-mod | Convert a multi-module workspace to a single module |
init | Initialize gonx in an existing workspace |
preset | Preset generator for creating a new workspace |
Executors
| Executor | Description |
|---|---|
build | Build a Go project |
lint | Format and lint a Go project |
serve | Run a Go application |
test | Run tests of a Go project |
tidy | Ensures go.mod file matches a project source code |
nx-release-publish | Lists the module in the Go registry |
!TIP You can use
nx list @naxodev/gonxto see list capabilities.
Need more customization? See our plugin configuration options.
Changes from the original nx-go
- Modern Nx-only, we break compatibility with older versions of Nx.
- We brought cacheable tasks to the table.
- Migrated to the latest version of Nx (21)
- Implemented the CreateNodesV2, enabling inferred tasks
- We have an inferred-tasks first approach
- Removed the generation of the project.json for applications and libraries
- We follow the philosophy of keeping non-js monorepos as pure as possible
- Implemented the new
VersionActionsto enable version generation when usingnx releasewith Go applications and libraries- Project names now use the full path to ensure compatibility with Go's release tagging convention (
projectRoot/vx.x.x)
- Project names now use the full path to ensure compatibility with Go's release tagging convention (
- Implemented the
publishexecutor to use withnx releasefor publishing applications and libraries to the Go registry - Modified the build and serve executors to work with nested
main.gopackages (previously required manualmain.golocation) - Removed the generate executor (we plan to support generation options that better fit the Nx model)
Installation
gonx is published as the @naxodev/gonx package.
| Toolchain | Command |
|---|---|
| NPM CLI | npm install @naxodev/gonx |
| PNPM CLI | pnpm add @naxodev/gonx |
| Yarn CLI | yarn add @naxodev/gonx |
Compatibility
gonx is compatible with the following versions of Nx:
| Nx Version | gonx Version |
|---|---|
| 21.x | 1.0.0 |
This plugin is only tested on stable versions of Go, older versions do not receive support. However, you can expect a fair degree of compatibility. Please note that multi-module Go workspaces require Go 1.18 or later.
Usage
Here are some common usage examples for gonx. For detailed options and configurations, click on the executor or generator name in the sections above.
Go Applications
Creating a new Go application
nx g @naxodev/gonx:application my-go-appSee the application generator docs for all options.
Building a Go application
nx build my-go-appSee the build executor docs for all options.
Running a Go application
nx serve my-go-appSee the serve executor docs for all options.
Go Libraries
Creating a new Go library
nx g @naxodev/gonx:library my-go-libSee the library generator docs for all options.
Testing a Go project
nx test my-go-libSee the test executor docs for all options.
Linting a Go project
nx lint my-go-libSee the lint executor docs for all options.
Managing Go dependencies
nx tidy my-go-libSee the tidy executor docs for all options.
Publishing Go Modules
nx nx-release-publish my-go-libOr as part of the Nx release process:
nx release --publishRelease Configuration
gonx supports Nx's release process with Go's versioning conventions. We automatically set up project names to match their directory paths, which ensures compatibility with Go's release tagging convention (projectRoot/vx.x.x).
To configure your workspace for releasing Go modules, add a configuration like this to your nx.json:
{
"release": {
"projectsRelationship": "independent",
"projects": ["your-go-project"],
"releaseTagPattern": "{projectName}/v{version}", // important! this is the Go release tag pattern
"changelog": {
...
},
"version": {
"useLegacyVersioning": false, // important! this means that we are using the plugin version actions
...
},
}
}Key points about this configuration:
releaseTagPattern: Set to{projectName}/v{version}to create Go-compatible tags (e.g.,apps/myapp/v1.2.3)projectName: With gonx, this is the full path to your project, not just the directory name
See the nx-release-publish executor docs for more information.
Contributors
Thanks goes to these wonderful people (emoji key):
Acknowledgements
This project is a fork of nx-go, a plugin for Nx that provides tools for building Go applications. Most credit goes to the original maintainers of nx-go - we've built upon their excellent foundation to modernize the plugin for the latest Nx features.
We're also inspired by the work done by other Nx Champions:
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago