Go.mod: Difference between revisions
Jump to navigation
Jump to search
Line 13: | Line 13: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<code>go.mod</code> stays with the code, including in the source repository. | <code>go.mod</code> stays with the code, including in the source repository. | ||
As <code>go</code> tools are used to manage dependencies, the tools update the <code>go.mod</code> file so that it maintains the current list of dependencies. | |||
=Example= | =Example= |
Revision as of 17:51, 14 December 2023
External
Internal
Overview
go.mod
declares the module path, which is the import path prefix for all packages within the module. It also tracks the modules that provide dependencies to this module. go.mod
is located in the root of the module, which is also the root of the source tree for the module.
One way to create it is with go mod init
:
go mod init <module-path>
go.mod
stays with the code, including in the source repository.
As go
tools are used to manage dependencies, the tools update the go.mod
file so that it maintains the current list of dependencies.
Example
module example.com/hello
go 1.21.0
require rsc.io/quote v1.5.2
require (
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c // indirect
rsc.io/sampler v1.3.0 // indirect
)
Initialize go.mod
In the module root directory, initialize the go.mod
file.
go mod init <module-path>
go mod init example.com/generic