Go mod: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * Go Tool =Overview= {{Internal|Go_Modules#go.mod|<tt>go.mod</tt>}} Initialize a v0 or v1 module: <syntaxhighlight lang='bash'> go mod init example....")
 
Line 3: Line 3:
=Overview=
=Overview=
{{Internal|Go_Modules#go.mod|<tt>go.mod</tt>}}
{{Internal|Go_Modules#go.mod|<tt>go.mod</tt>}}
=<tt>init</tt>=
Initialize a v0 or v1 module:
Initialize a v0 or v1 module:
<syntaxhighlight lang='bash'>
<syntaxhighlight lang='bash'>
Line 12: Line 14:
</syntaxhighlight>
</syntaxhighlight>


=<tt>tidy</tt>=
Inspect the code, look for module imports, download them and update <code>go.mod</code>.
Inspect the code, look for module imports, download them and update <code>go.mod</code>.
<syntaxhighlight lang='bash'>
<syntaxhighlight lang='bash'>
go mod tidy
go mod tidy
</syntaxhighlight>
If we know our dependency, it is sufficient to add it to the import list, then execute <code>go mod tidy</code>:
<syntaxhighlight lang='go'>
import (
consul "github.com/hashicorp/consul/api"
)
...
</syntaxhighlight>
</syntaxhighlight>

Revision as of 21:56, 2 October 2023

Internal

Overview

go.mod

init

Initialize a v0 or v1 module:

go mod init example.com/m

Initialize a v2 module:

go mod init example.com/m/v2

tidy

Inspect the code, look for module imports, download them and update go.mod.

go mod tidy

If we know our dependency, it is sufficient to add it to the import list, then execute go mod tidy:

import (
	consul "github.com/hashicorp/consul/api"
)

...