githubEdit

go.mod

Learn how to generate and configure the go.mod file to manage modules and dependencies for Go apps on Discloud.

πŸ—‚οΈ What is go.mod?

go.mod defines your module path, the Go toolchain version (in major.minor form), and the direct dependencies required by your project. Discloud uses it (and the accompanying go.sum) to download and verify modules before building your application.


πŸ› οΈ Creating a New Module

1

Initialize a module in the current directory:

go mod init github.com/you/yourapp
2

Add (or update) dependencies automatically by referencing them in code and tidying:

go mod tidy

This creates go.sum (must not be empty) with checksum lines.

3

Add a specific dependency explicitly:

go get github.com/go-chi/chi/v5

Then tidy again if needed:

go mod tidy
circle-info

Need Go locally? See the local environment guide.


🧩 Minimal Example

go.mod
module github.com/you/yourapp

go 1.22
circle-exclamation

πŸ“¦ Adding Dependencies

To add a new dependency, either:

1

Import it in your source file then run go mod tidy, or

2

Run go get module/path@version directly.

Example: add Chi router

Resulting go.mod snippet:

Versions are resolved semantically by the proxy/module system.


πŸ”’ go.sum Integrity & Empty Case

go.sum contains cryptographic hashes of every required module version (direct & indirect) to guarantee reproducible builds. It must be committed together with go.mod.

Regenerate / update it anytime:


πŸ§ͺ Application Type Examples

Tabbed examples for common scenarios:


🧰 Common Commands Reference

Last updated