Dependencies
GOX manages the project's direct dependencies by gox.json and keeps synchronized deps.go, go.mod and go.sum with Go's tools.
The commands get, remove, install and tidy are part of the same administration flow. To consult the installed dependencies, use gox list.
Commands
| Command | Description |
|---|---|
| get | Add or update a dependency. |
| remove | It eliminates a dependency. |
| install | Install and reconcile the declared dependencies. |
| tidy | Synchronize the Go modules. |
| list | It shows the project dependencies. |
get
gox get <package>[@version] get add the package to gox.json and immediately runs the installation of dependencies.
gox get github.com/redis/go-redis/v9
gox get example.com/[email protected] If the version is omitted, GOX stores latest. The separation between the package and the version uses the last character @ of the argument.
The command requires exactly a package.
If the installation fails, GOX restores the previous status of the managed files and the dependency is not partially added.
remove
gox remove <package> remove removes the package from gox.json and resynchronize the dependencies:
gox remove github.com/redis/go-redis/v9 The GOX's main SDK is a protected dependency and cannot be removed by this command.
The command requires exactly one package. If the synchronization fails, GOX restores the previous state of the managed files.
install
gox install install Read gox.json, reconciles the declared versions and synchronizes the Go modules.
During the operation, GOX:
- It guarantees the availability of the Go toolchain.
- Synchronize the permanent bridge
deps.gowith the dependencies declared. - Install the dependencies in stable order.
- Executed
go mod tidyby the toolchain administered. - It guarantees the availability of Node.js and PNPM.
The command does not accept arguments. The preparation of Node.js and PNPM does not install or reconstruct by itself the workspaces of frameworks; that operation belongs to gox client add.
tidy
gox tidy tidy synchronized deps.go, go.mod and go.sum with dependencies declared unmodified gox.json.
So that the Go tools can observe the imports used only by files .gox, GOX keeps deps.go updated before running go mod tidy by your toolchain administered.
gox.json
Direct dependencies are stored as a package and version map:
{
"dependencies": {
"github.com/redis/go-redis/v9": "latest"
}
} The modules can then be imported from GOX using the imports.
deps.go
deps.go is a file generated and maintained by GOX at the root of the project. Its function is to make visible for the tools of go modules the dependencies that can be used only from files .gox.
GOX synchronizes this file during dependency operations. If there is already a deps.go which does not belong to GOX, the operation fails instead of overwriting it.
deps.go is part of the administered state of the project and is not eliminated after install or tidy.
Errors and consistency
An invalid dependency, a gox.json misformed or an error of the Go tools interrupt the command.
get and remove apply their changes transactional. If the subsequent installation or synchronization fails, GOX restores the previous state of gox.json, deps.go, go.mod and go.sumincluding the prior absence of any of these files.
Best practices
- It uses explicit versions for reproducible building.
- Preservation
gox.json,deps.go,go.modandgo.sumunder version control. - Do not manually edit the
deps.goadministered by GOX. - Executed
gox installafter getting dependency changes. - Use
gox listto consult the direct dependencies declared andgox list -twhen you need the effective module graph.