Skip to content

Commit 82b3234

Browse files
author
Jay Conrod
committed
_content/doc: update FAQ on managing dependencies with 'go get'
Change-Id: Ia8a55ac05ab2209f6076e4328bd5f53d67df8b53 Reviewed-on: https://go-review.googlesource.com/c/website/+/293169 Trust: Jay Conrod <[email protected]> Trust: Bryan C. Mills <[email protected]> Run-TryBot: Jay Conrod <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent de781e5 commit 82b3234

File tree

1 file changed

+34
-28
lines changed

1 file changed

+34
-28
lines changed

_content/doc/go_faq.html

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,49 +1318,55 @@ <h3 id="get_version">
13181318
How should I manage package versions using "go get"?</h3>
13191319

13201320
<p>
1321-
Since the inception of the project, Go has had no explicit concept of package versions,
1322-
but that is changing.
1323-
Versioning is a source of significant complexity, especially in large code bases,
1324-
and it has taken some time to develop an
1325-
approach that works well at scale in a large enough
1326-
variety of situations to be appropriate to supply to all Go users.
1321+
The Go toolchain has a built-in system for managing versioned sets of related packages, known as <dfn>modules</dfn>.
1322+
Modules were introduced in <a href="/doc/go1.11#modules">Go 1.11</a> and have been ready for production use since <a href="/doc/go1.14#introduction">1.14</a>.
13271323
</p>
13281324

13291325
<p>
1330-
The Go 1.11 release adds new, experimental support
1331-
for package versioning to the <code>go</code> command,
1332-
in the form of Go modules.
1333-
For more information, see the <a href="/doc/go1.11#modules">Go 1.11 release notes</a>
1334-
and the <a href="/cmd/go#hdr-Modules__module_versions__and_more"><code>go</code> command documentation</a>.
1326+
To create a project using modules, run <a href="/ref/mod#go-mod-init"><code>go mod init</code></a>.
1327+
This command creates a <code>go.mod</code> file that tracks dependency versions.
1328+
</p>
1329+
1330+
<pre>
1331+
go mod init example.com/project
1332+
</pre>
1333+
1334+
<p>
1335+
To add, upgrade, or downgrade a dependency, run <a href="/ref/mod#go-get"><code>go get</code></a>:
1336+
</p>
1337+
1338+
<pre>
1339+
go get golang.org/x/[email protected]
1340+
</pre>
1341+
1342+
<p>
1343+
See <a href="/doc/tutorial/create-module.html">Tutorial: Create a module</a> for more information on getting started.
13351344
</p>
13361345

13371346
<p>
1338-
Regardless of the actual package management technology,
1339-
"go get" and the larger Go toolchain does provide isolation of
1340-
packages with different import paths.
1341-
For example, the standard library's <code>html/template</code> and <code>text/template</code>
1342-
coexist even though both are "package template".
1343-
This observation leads to some advice for package authors and package users.
1347+
See <a href="/doc/#developing-modules">Developing modules</a> for guides on managing dependencies with modules.
13441348
</p>
13451349

13461350
<p>
1347-
Packages intended for public use should try to maintain backwards compatibility as they evolve.
1351+
Packages within modules should maintain backward compatibility as they evolve, following the <a href="https://research.swtch.com/vgo-import">import compatibility rule</a>:
1352+
</p>
1353+
1354+
<blockquote>
1355+
If an old package and a new package have the same import path,<br>
1356+
the new package must be backwards compatible with the old package.
1357+
</blockquote>
1358+
1359+
<p>
13481360
The <a href="/doc/go1compat.html">Go 1 compatibility guidelines</a> are a good reference here:
13491361
don't remove exported names, encourage tagged composite literals, and so on.
13501362
If different functionality is required, add a new name instead of changing an old one.
1351-
If a complete break is required, create a new package with a new import path.
13521363
</p>
13531364

13541365
<p>
1355-
If you're using an externally supplied package and worry that it might change in
1356-
unexpected ways, but are not yet using Go modules,
1357-
the simplest solution is to copy it to your local repository.
1358-
This is the approach Google takes internally and is supported by the
1359-
<code>go</code> command through a technique called "vendoring".
1360-
This involves
1361-
storing a copy of the dependency under a new import path that identifies it as a local copy.
1362-
See the <a href="https://golang.org/s/go15vendor">design
1363-
document</a> for details.
1366+
Modules codify this with <a href="https://semver.org/">semantic versioning</a> and semantic import versioning.
1367+
If a break in compatibility is required, release a module at a new major version.
1368+
Modules at major version 2 and higher require a <a href="/ref/mod#major-version-suffixes">major version suffix</a> as part of their path (like <code>/v2</code>).
1369+
This preserves the import compatibility rule: packages in different major versions of a module have distinct paths.
13641370
</p>
13651371

13661372
<h2 id="Pointers">Pointers and Allocation</h2>

0 commit comments

Comments
 (0)