From dc08095e2bad041d4d5b76726e6122e79383d496 Mon Sep 17 00:00:00 2001 From: Michael Matloob Date: Wed, 16 Mar 2022 12:18:56 -0400 Subject: [PATCH] _content/ref: update the modules reference for GOWORK The -workfile flag's function has been absorbed by the GOWORK environment variable. Update the workspaces reference to reflect that. Also fix an error in the workspaces tutorial. For golang/go#45713 Change-Id: Id8dc8bb8dc6458d03d7b947ec78d84263d9689e1 Reviewed-on: https://go-review.googlesource.com/c/website/+/393360 Trust: Michael Matloob Run-TryBot: Michael Matloob Reviewed-by: Bryan Mills TryBot-Result: Gopher Robot Reviewed-by: Beth Brown --- _content/doc/tutorial/workspaces.md | 4 ++-- _content/ref/mod.md | 28 ++++++++++++++++++++-------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/_content/doc/tutorial/workspaces.md b/_content/doc/tutorial/workspaces.md index a34524993e..517b5d9e10 100644 --- a/_content/doc/tutorial/workspaces.md +++ b/_content/doc/tutorial/workspaces.md @@ -190,7 +190,7 @@ add a new function to the `stringutil` package that we can use instead of `Rever We'll add a new function to uppercase a string to the `golang.org/x/example/stringutil` package. - Add a new folder to the `workspace/example/stringutil` directory containing the following contents: + Create a new file named `toupper.go` in the `workspace/example/stringutil` directory containing the following contents: ``` package stringutil @@ -230,7 +230,7 @@ add a new function to the `stringutil` package that we can use instead of `Rever From the workspace directory, run ``` - $ go run example/hello + $ go run example.com/hello HELLO ``` diff --git a/_content/ref/mod.md b/_content/ref/mod.md index a4bcfa2528..4fd2f388a0 100644 --- a/_content/ref/mod.md +++ b/_content/ref/mod.md @@ -1088,14 +1088,17 @@ operate on the set of modules determined by the current workspace. and `go get` always operate on a single main module. A command determines whether it is in a workspace context by first examining -the `-workfile` flag. If `-workfile` is set to `off`, the command will be +the `GOWORK` environment variable. If `GOWORK` is set to `off`, the command will be in a single-module context. If it is empty or not provided, the command will search the current working directory, and then successive parent directories, for a file `go.work`. If a file is found, the command will operate in the workspace it defines; otherwise, the workspace will include only the module containing the working directory. -If `-workfile` names a path to an existing file that ends in .work, -workspace mode will be enabled. Any other value is an error. +If `GOWORK` names a path to an existing file that ends in .work, +workspace mode will be enabled. Any other value is an error. You can use the +`go env GOWORK` command to determine which `go.work` file the `go` command +is using. `go env gowork` will be empty if the `go` command is not in workspace +mode. ### `go.work` files {#go-work-file} @@ -1446,11 +1449,6 @@ commands accept the following flags, common to all module commands. `-modfile` is specified, an alternate `go.sum` file is also used: its path is derived from the `-modfile` flag by trimming the `.mod` extension and appending `.sum`. -* The `-workfile` flag instructs the `go` command to enter workspace mode using the provided - [`go.work` file](#go-work-file) to define the workspace. If `-workfile` is - set to `off` workspace mode is disabled. If `-workfile` is not provided the - `go` command will search for a `go.work` file as described in the - [Workspaces](#workspaces) section. ### Vendoring {#vendoring} @@ -4325,6 +4323,20 @@ GOSUMDB="sum.golang.org+<publickey> https://sum.golang.org"

+ + GOWORK + +

+ The `GOWORK` environment variable instructs the `go` command to enter workspace + mode using the provided [`go.work` file](#go-work-file) to define the workspace. + If `GOWORK` is set to `off` workspace mode is disabled. This can be used to run + the `go` command in single module mode: for example, `GOWORK=off go build .` builds + the `.` package in single-module mode.`If `GOWORK` is empty, the + `go` command will search for a `go.work` file as described in the [Workspaces](#workspaces) + section. +

+ +