================ CODE SNIPPETS ================ TITLE: Go Project Setup and Execution DESCRIPTION: This snippet details the shell commands required to set up a Go project environment, including setting GOPATH, creating directories, copying source files, and establishing symlinks. It then demonstrates executing Go commands to list the project root, run a Go program, build it, and install it. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/list_symlink_vendor_issue14054.txt#_snippet_0 LANGUAGE: shell CODE: ``` env GO111MODULE=off mkdir $WORK/tmp/gopath/src/dir1/vendor/v cp p.go $WORK/tmp/gopath/src/dir1/p.go cp v.go $WORK/tmp/gopath/src/dir1/vendor/v/v.go symlink $WORK/tmp/symdir1 -> $WORK/tmp/gopath/src/dir1 env GOPATH=$WORK/tmp/gopath cd $WORK/tmp/symdir1 go list -f '{{.Root}}' . stdout '^'$WORK/tmp/gopath'$' # All of these should succeed, not die in vendor-handling code. go run p.go & go build & go install & wait ``` -------------------------------- TITLE: Go Project Setup and Execution DESCRIPTION: This snippet demonstrates setting up a Go project structure, including creating directories, copying source files, and establishing symbolic links. It then shows how to configure the GOPATH and execute Go commands to build and run the project, highlighting the use of `go list`, `go run`, and `go install`. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/list_symlink_internal.txt#_snippet_0 LANGUAGE: shell CODE: ``` env GO111MODULE=off mkdir $WORK/tmp/gopath/src/dir1/internal/v cp p.go $WORK/tmp/gopath/src/dir1/p.go cp v.go $WORK/tmp/gopath/src/dir1/internal/v/v.go symlink $WORK/tmp/symdir1 -> $WORK/tmp/gopath/src/dir1 env GOPATH=$WORK/tmp/gopath cd $WORK/tmp/symdir1 go list -f '{{.Root}}' . stdout '^'$WORK/tmp/gopath'$' # All of these should succeed, not die in internal-handling code. go run p.go & go build & go install & wait ``` -------------------------------- TITLE: Basic Go Build and Install DESCRIPTION: Demonstrates building and installing a Go command-line application. It shows how to set environment variables for cross-compilation and the expected output path for the installed binary. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/install_cross_gobin.txt#_snippet_0 LANGUAGE: shell CODE: ``` env GO111MODULE=off cd mycmd go build mycmd ``` LANGUAGE: shell CODE: ``` # cross-compile install with implicit GOBIN=$GOPATH/bin can make subdirectory env GOARCH=386 [GOARCH:386] env GOARCH=amd64 env GOOS=linux go install mycmd exists $GOPATH/bin/linux_$GOARCH/mycmd ``` LANGUAGE: shell CODE: ``` # cross-compile install with explicit GOBIN cannot make subdirectory env GOBIN=$WORK/bin ! go install mycmd ! exists $GOBIN/linux_$GOARCH ``` LANGUAGE: shell CODE: ``` # The install directory for a cross-compiled standard command should include GOARCH. go list -f '{{.Target}}' cmd/pack stdout ${GOROOT}[/\\]pkg[[/\\]]tool[[/\\]]${GOOS}_${GOARCH}[/\\]]pack$ ``` -------------------------------- TITLE: Building and Installing gofmt DESCRIPTION: Builds the 'gofmt' command-line tool and then installs it to the GOBIN directory. It includes checks for the executable's existence and cleanup. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/build_output.txt#_snippet_7 LANGUAGE: shell CODE: ``` go build cmd/gofmt exists -exec gofmt$GOEXE rm gofmt$GOEXE ! exists gofmt$NONEXE ``` -------------------------------- TITLE: Basic Golang Project Structure (go.mod and main.go) DESCRIPTION: Provides a minimal `go.mod` file defining the module and Go version, alongside a simple `main.go` file with an empty `main` function. This serves as a starting point for new Golang projects. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/install_relative_gobin_fail.txt#_snippet_1 LANGUAGE: go CODE: ``` -- go.mod -- module triv go 1.16 -- triv.go -- package main func main() {} ``` -------------------------------- TITLE: Main Package Example DESCRIPTION: A minimal Go program that defines the 'main' package and includes an empty 'main' function. This serves as a basic executable entry point. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/build_output.txt#_snippet_13 LANGUAGE: go CODE: ``` package main func main() {} ``` -------------------------------- TITLE: Package 'p' Example DESCRIPTION: A Go file that defines a package named 'p'. This is typically used for creating reusable libraries. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/build_output.txt#_snippet_14 LANGUAGE: go CODE: ``` package p ``` -------------------------------- TITLE: Go Build and Install Commands DESCRIPTION: Demonstrates basic Go commands for installing packages and building the current project. The 'go install .' command compiles and installs the package in the current directory. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/mod_import_v1suffix.txt#_snippet_1 LANGUAGE: shell CODE: ``` go get example.com/invalidpath/v1 go install . ``` -------------------------------- TITLE: Go Program Entrypoint DESCRIPTION: A simple Go program 'p.go' that imports a vendored package 'v'. This serves as the main executable in the project setup. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/list_symlink_vendor_issue14054.txt#_snippet_1 LANGUAGE: go CODE: ``` package main import _ `v` func main () {} ``` -------------------------------- TITLE: Go Project Initialization and CGO Setup DESCRIPTION: This snippet demonstrates setting up Go modules, installing the CGO package, and building a Go project that utilizes CGO. It includes environment variable configuration and project build commands. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/mod_case_cgo.txt#_snippet_0 LANGUAGE: shell CODE: ``` #!cgo] skip env GO111MODULE=on go get rsc.io/CGO [short] stop go build rsc.io/CGO ``` LANGUAGE: go CODE: ``` -- go.mod -- module x ``` -------------------------------- TITLE: Go Project Setup and Package Listing Example DESCRIPTION: This snippet demonstrates setting up a Go project environment by disabling module mode, creating a temporary directory structure, copying a Go source file, setting the GOPATH, and then using the 'go list' command to display the root of the 'dir1' package. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/list_symlink.txt#_snippet_0 LANGUAGE: bash CODE: ``` env GO111MODULE=off mkdir $WORK/tmp/src symlink $WORK/tmp/src/dir1 -> $WORK/tmp cp p.go $WORK/tmp/src/dir1/p.go env GOPATH=$WORK/tmp go list -f '{{.Root}}' dir1 stdout '^'$WORK/tmp'$' ``` -------------------------------- TITLE: Go Main Package Example DESCRIPTION: A simple Go program demonstrating a `main` package that imports a local module. This illustrates how Go handles package dependencies within a project structure. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/list_symlink_internal.txt#_snippet_1 LANGUAGE: go CODE: ``` package main import _ `dir1/internal/v` func main() {} ``` -------------------------------- TITLE: Go Module File Example DESCRIPTION: An example of a go.mod file, which defines the module path for a Go project. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/mod_install_versioned.txt#_snippet_1 LANGUAGE: go CODE: ``` module m ``` -------------------------------- TITLE: Go Project Structure DESCRIPTION: Provides the source code for a simple Go application named 'mycmd'. This serves as the target for the build and installation commands. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/install_cross_gobin.txt#_snippet_1 LANGUAGE: go CODE: ``` -- mycmd/x.go -- package main func main() {} ``` -------------------------------- TITLE: Go Main Function Example DESCRIPTION: A simple 'Hello, World!' program written in Go, demonstrating the basic structure of a Go application. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/vcstest/svn/hello.txt#_snippet_3 LANGUAGE: go CODE: ``` package main func main() { println("hello, world") } ``` -------------------------------- TITLE: Go Build with Cache Setup DESCRIPTION: Sets up a fresh Go build cache directory and demonstrates a basic build command. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/build_cache_link.txt#_snippet_0 LANGUAGE: shell CODE: ``` env GO111MODULE=off # Set up fresh GOCACHE. env GOCACHE=$WORK/gocache mkdir $GOCACHE # Building a main package should run the compiler and linker ... go build -o $devnull -x main.go stderr '(compile|gccgo)( |\.exe).*main\.go' stderr '(link|gccgo)( |\.exe)' ``` -------------------------------- TITLE: Fetch Go Dependency with Verbose Output DESCRIPTION: Uses 'go get -x' to download and install a specific version of a Go package ('golang.org/x/text@v0.1.0'). The '-x' flag enables verbose output, logging the URLs being fetched. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/mod_getx.txt#_snippet_1 LANGUAGE: bash CODE: ``` go get -x golang.org/x/text@v0.1.0 ``` -------------------------------- TITLE: Go Module Download and Installation DESCRIPTION: Commands to download specific versions of Go modules and install them. `go mod download` fetches modules, `go get` updates or adds modules, and `go install` compiles and installs packages. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/version_replace.txt#_snippet_0 LANGUAGE: shell CODE: ``` go mod download example.com/printversion@v0.1.0 example.com/printversion@v1.0.0 go get example.com/printversion@v0.1.0 go install example.com/printversion ``` -------------------------------- TITLE: Building and Executing from a Directory DESCRIPTION: Creates a 'bin' directory, builds a Go program 'x.go' into it, executes the program, and then removes the directory. This is useful for organizing build outputs. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/build_output.txt#_snippet_5 LANGUAGE: shell CODE: ``` ! exists bin mkdir bin go build -o bin x.go exists -exec bin/x$GOEXE rm bin ``` -------------------------------- TITLE: Go Module Initialization and Package Installation DESCRIPTION: This snippet demonstrates how to create a new Go module, specify the Go version, and install packages using the 'go install' command with race detection enabled. It sets up a basic project structure for Go development. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/test_race_install.txt#_snippet_0 LANGUAGE: shell CODE: ``` mkdir $WORKDIR/tmp/pkg go install -race -pkgdir=$WORKDIR/tmp/pkg std ``` LANGUAGE: go CODE: ``` module empty go 1.16 ``` LANGUAGE: go CODE: ``` package p ``` -------------------------------- TITLE: Basic Go Build and Execution DESCRIPTION: Compiles a Go program 'x.go', executes it, and then cleans up the generated executable. This is a fundamental build and run cycle. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/build_output.txt#_snippet_0 LANGUAGE: shell CODE: ``` go build x.go exists -exec x$GOEXE rm x$GOEXE ``` -------------------------------- TITLE: Building into a Specific Directory DESCRIPTION: Compiles a Go program 'x.go' and places the output executable 'x' into the 'bin' directory. It includes steps to create the directory, build, execute, and clean up. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/build_output.txt#_snippet_2 LANGUAGE: shell CODE: ``` ! exists bin go build -o bin/x x.go exists -exec bin/x rm bin ``` -------------------------------- TITLE: Golang Installation with GOBIN Error Handling DESCRIPTION: Demonstrates setting the GOBIN environment variable and the expected output when GOBIN is not an absolute path during `go install`. This is crucial for understanding correct Go binary installation paths. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/install_relative_gobin_fail.txt#_snippet_0 LANGUAGE: shell CODE: ``` env GOBIN=. ! go install stderr 'cannot install, GOBIN must be an absolute path' ``` -------------------------------- TITLE: Go Source File Example (x.go.txt) DESCRIPTION: This is a simple Go source file that imports an unstable package. It's used in the project setup to demonstrate dependency usage. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/mod_gopkg_unstable.txt#_snippet_3 LANGUAGE: go CODE: ``` package x import _ "gopkg.in/dummy.v2-unstable" ``` -------------------------------- TITLE: Go Module and Import Example DESCRIPTION: Demonstrates a simple Go module setup with an import statement, used in conjunction with the embed examples. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/embed.txt#_snippet_4 LANGUAGE: go CODE: ``` -- use/use.go -- package use import _ "m" -- go.mod -- module m go 1.16 ``` -------------------------------- TITLE: Building a Go Package as an Archive DESCRIPTION: Compiles a Go package 'p.go' into an archive file 'p.a' and then uses a separate tool 'isarchive' to verify its format. This is common for creating libraries. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/build_output.txt#_snippet_6 LANGUAGE: shell CODE: ``` go build -o p.a p.go exists p.a exec $GOBIN/isarchive p.a ``` -------------------------------- TITLE: Go Module Definitions and Error Files DESCRIPTION: Provides example content for a go.mod file, a Go source file, and error message files used in the testing scenarios. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/mod_install_pkg_version.txt#_snippet_15 LANGUAGE: go CODE: ``` -- m/go.mod -- module m go 1.16 require example.com/cmd v1.1.0-doesnotexist -- x/x.go -- package main func main() {} -- replace-err -- go: example.com/cmd/a@v1.0.0-replace (in example.com/cmd@v1.0.0-replace): The go.mod file for the module providing named packages contains one or more replace directives. It must not contain directives that would cause it to be interpreted differently than if it were the main module. -- exclude-err -- go: example.com/cmd/a@v1.0.0-exclude (in example.com/cmd@v1.0.0-exclude): The go.mod file for the module providing named packages contains one or more exclude directives. It must not contain directives that would cause it to be interpreted differently than if it were the main module. ``` -------------------------------- TITLE: Get Specific Dependency Version DESCRIPTION: Fetches a specific version of a module. 'go get example.com/bar@none' is used here as a no-operation example when the module is not active. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/mod_get_none.txt#_snippet_1 LANGUAGE: bash CODE: ``` go get example.com/bar@none ``` -------------------------------- TITLE: Go Environment Setup and Module Download DESCRIPTION: Configures the Go environment with a specific Go version and toolchain, then downloads a module. It includes an example of handling a version incompatibility error during module download. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/mod_get_future.txt#_snippet_0 LANGUAGE: shell CODE: ``` env TESTGO_VERSION=go1.21 env GOTOOLCHAIN=local ! go mod download rsc.io/future@v1.0.0 stderr '^go: rsc.io/future@v1.0.0 requires go >= 1.999 \(running go 1.21; GOTOOLCHAIN=local\)$' ``` -------------------------------- TITLE: Install echo command DESCRIPTION: Installs the 'echo' command for use in environments where it's not natively available, by setting the GOBIN and PATH environment variables. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/generate.txt#_snippet_0 LANGUAGE: shell CODE: ``` env GOBIN=$WORK/tmp/bin go install echo.go env PATH=$GOBIN:${:}$PATH ``` -------------------------------- TITLE: Go Source File Example DESCRIPTION: A basic Go source file example for a package named 'subpkg'. This file serves as a placeholder or a starting point for package implementation. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/mod/example.com_split_subpkg_v1.1.0.txt#_snippet_2 LANGUAGE: go CODE: ``` package subpkg ``` -------------------------------- TITLE: Windows Specific Build and Execution DESCRIPTION: Demonstrates building a Go program on Windows, specifying the output path with backslashes, and executing the resulting '.exe' file. It also includes cleanup steps. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/build_output.txt#_snippet_3 LANGUAGE: shell CODE: ``` [GOOS:windows] ! exists bin [GOOS:windows] go build -o bin\x x.go [GOOS:windows] exists -exec bin\x [GOOS:windows] rm bin ``` -------------------------------- TITLE: Install Specific Tool Version DESCRIPTION: Installs a specific version of a tool using 'go get -tool'. This updates the go.mod file to include the tool and its required version. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/mod_get_tool.txt#_snippet_0 LANGUAGE: shell CODE: ``` go get -tool example.com/tools/cmd/hello@v1.0.0 cmp go.mod go.mod.want ``` -------------------------------- TITLE: Build Error Example DESCRIPTION: Illustrates a common error message encountered during Go builds, specifically 'unable to find math.a', which often indicates issues with the Go installation or environment setup. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/build_arm.txt#_snippet_2 LANGUAGE: shell CODE: ``` ! stderr 'unable to find math.a' ``` -------------------------------- TITLE: Installing Packages and Handling Errors DESCRIPTION: Demonstrates installing specific packages and handling cases where packages are not main packages or have compilation errors. It also shows how to verify installed binaries. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/mod_install_pkg_version.txt#_snippet_10 LANGUAGE: shell CODE: ``` # a main package. ! go install example.com/cmd/a@v1.0.0 example.com/cmd/err@v1.0.0 stderr '^package example.com/cmd/err is not a main package$' # Wildcards should match only main packages. This module has a non-main package # with an error, so we'll know if that gets built. mkdir tmp cd tmp go mod init m go get example.com/cmd@v1.0.0 ! go build example.com/cmd/... stderr 'err[/\]err.go:3:9: undefined: DoesNotCompile( .*)?$ ' cd .. go install example.com/cmd/... @v1.0.0 exists $GOPATH/bin/a$GOEXE exists $GOPATH/bin/b$GOEXE rm $GOPATH/bin ``` -------------------------------- TITLE: Error: 'go get -tool' with 'all' DESCRIPTION: Illustrates an error scenario where 'go get -tool' cannot be used with the 'all' keyword. The command is designed for specific tool management, not bulk installation of all project tools. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/mod_get_tool.txt#_snippet_6 LANGUAGE: shell CODE: ``` ! go get -tool all stderr 'go get -tool does not work with "all"' ``` -------------------------------- TITLE: Go Test File Example DESCRIPTION: A basic Go test file (`main_test.go`) that includes a simple test function `TestF` using the `testing` package. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/test_go111module_cache.txt#_snippet_3 LANGUAGE: go CODE: ``` package main import "testing" func TestF(t *testing.T) {} ``` -------------------------------- TITLE: Go Modules Fetch with Insecure (Error Example) DESCRIPTION: Demonstrates fetching a package using `go get` with the `-insecure` flag when `GO111MODULE` is on. Similar to the GOPATH example, this command is expected to fail due to the deprecation of the `-insecure` flag. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/get_insecure_no_longer_supported.txt#_snippet_3 LANGUAGE: shell CODE: ``` ! go get -insecure test stderr 'go: -insecure flag is no longer supported; use GOINSECURE instead' ``` -------------------------------- TITLE: Go Project Initialization and Dependency Fetching DESCRIPTION: This snippet demonstrates the initial setup of a Go project, including enabling module support, copying a template go.mod file, and fetching an unstable dependency. It also shows how to copy source files and list project modules. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/mod_gopkg_unstable.txt#_snippet_0 LANGUAGE: bash CODE: ``` env GO111MODULE=on cp go.mod.empty go.mod go get gopkg.in/dummy.v2-unstable cp x.go.txt x.go cp go.mod.empty go.mod go list ``` -------------------------------- TITLE: Custom Build and Installation of gofmt DESCRIPTION: Builds the 'gofmt' tool with a custom output name 'mygofmt' and then executes it. It verifies the custom executable and ensures the default 'gofmt' is not present. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/build_output.txt#_snippet_8 LANGUAGE: shell CODE: ``` go build -o mygofmt cmd/gofmt exists -exec mygofmt ! exists mygofmt.exe ! exists gofmt ! exists gofmt.exe ``` -------------------------------- TITLE: Go Get All Test Dependencies DESCRIPTION: Shows the behavior of 'go get all' with respect to test dependencies. This example demonstrates that 'go get all' considers test dependencies, similar to using 'go get -t all'. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/mod_get_test.txt#_snippet_5 LANGUAGE: shell CODE: ``` # 'go get all' should consider test dependencies with or without -t. cp go.mod.empty go.mod go get all grep 'rsc.io/quote v1.5.2$' go.mod ``` -------------------------------- TITLE: Go Module Initialization and Package Fetching DESCRIPTION: Demonstrates how to enable Go modules, fetch a package, and list its target path. It also shows how to fetch a versioned package. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/mod_install_versioned.txt#_snippet_0 LANGUAGE: shell CODE: ``` env GO111MODULE=on go get rsc.io/fortune go list -f '{{.Target}}' rsc.io/fortune ``` LANGUAGE: shell CODE: ``` go get rsc.io/fortune/v2 go list -f '{{.Target}}' rsc.io/fortune/v2 ``` -------------------------------- TITLE: Handle Version Conflicts with 'go get' DESCRIPTION: This example demonstrates how 'go get' handles version conflicts. When 'rsc.io/quote@v1.5.2' requires 'rsc.io/sampler@v1.3.0' but 'rsc.io/sampler@v1.0.0' is specified, 'go get' reports the inconsistency. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/mod_get_downgrade.txt#_snippet_3 LANGUAGE: shell CODE: ``` ! go get rsc.io/sampler@v1.0.0 rsc.io/quote@v1.5.2 golang.org/x/text@none ! stderr add|remove|upgrad|downgrad stderr '^go: rsc.io/quote@v1.5.2 requires rsc.io/sampler@v1.3.0, not rsc.io/sampler@v1.0.0$' go list -m all stdout 'rsc.io/quote v1.5.1' stdout 'rsc.io/sampler v1.3.0' ``` -------------------------------- TITLE: GOPATH Fetch with Insecure (Error Example) DESCRIPTION: Demonstrates fetching a package using `go get` with the `-insecure` flag when `GO111MODULE` is off. This command is expected to fail with a specific error message indicating the flag's deprecation. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/get_insecure_no_longer_supported.txt#_snippet_1 LANGUAGE: shell CODE: ``` ! go get -insecure test stderr 'go: -insecure flag is no longer supported; use GOINSECURE instead' ``` -------------------------------- TITLE: Go Build Cache and Installation Example DESCRIPTION: Demonstrates how to check the Go build cache status before and after installation. It uses environment variables and `go list` commands to verify if the build is stale. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/mod_stale.txt#_snippet_0 LANGUAGE: shell CODE: ``` env GOCACHE=$WORK/cache go list -f '{{.Stale}}' . stdout true go install . go list -f '{{.Stale}}' . stdout false ``` LANGUAGE: go CODE: ``` module example.com/mod go 1.20 ``` LANGUAGE: go CODE: ``` package m ``` -------------------------------- TITLE: Go Assembly Symbol Naming Example DESCRIPTION: Demonstrates how Go's linker handles symbol names in assembly files. A symbol starting with a period, like `·Int`, is prefixed with the package path (e.g., `math/rand/`) by the linker. SOURCE: https://github.com/golang/go/blob/go1.24.6/doc/asm.html#_snippet_9 LANGUAGE: go CODE: ``` // In a Go assembly file within the math/rand package: // The function 'Int' can be referred to as `·Int`. // The linker will resolve this to 'math/rand/Int'. ``` -------------------------------- TITLE: Building with Custom Output Path (Windows) DESCRIPTION: Shows how to build a Go program on Windows, specifying an output path that includes a space, and then executing the generated '.exe'. Cleanup is also performed. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/build_output.txt#_snippet_4 LANGUAGE: shell CODE: ``` [GOOS:windows] ! exists bin [GOOS:windows] go build -o bin\ x.go [GOOS:windows] exists -exec bin\x.exe [GOOS:windows] rm bin ``` -------------------------------- TITLE: Go Local Module Package Example DESCRIPTION: A Go package named `v` intended to be part of a local module. This serves as a dependency for other packages within the same project. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/list_symlink_internal.txt#_snippet_2 LANGUAGE: go CODE: ``` package v ``` -------------------------------- TITLE: Running a Go Module Version Example DESCRIPTION: This snippet demonstrates how to execute a Go module located at 'example.com/printversion' with version 'v0.1.0' and verify its standard output matches an expected version string. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/run_work_versioned.txt#_snippet_0 LANGUAGE: shell CODE: ``` go run example.com/printversion@v0.1.0 stdout '^main is example.com/printversion v0.1.0$' ``` -------------------------------- TITLE: Git Environment Setup and Commit DESCRIPTION: Sets Git author and committer environment variables, initializes a Git repository, adds specified files, and creates an initial commit. It also renames the master branch to main. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/vcstest/git/modlegacy1-new.txt#_snippet_0 LANGUAGE: shell CODE: ``` env GIT_AUTHOR_NAME='Russ Cox' env GIT_AUTHOR_EMAIL='rsc@golang.org' env GIT_COMMITTER_NAME=$GIT_AUTHOR_NAME env GIT_COMMITTER_EMAIL=$GIT_COMMITTER_EMAIL git init at 2018-04-25T11:00:57-04:00 git add go.mod new.go p1 p2 git commit -m 'initial commit' git branch -m master ``` -------------------------------- TITLE: Go Project Setup and Test Execution DESCRIPTION: This snippet demonstrates the setup process for a Go project, including setting environment variables like GO111MODULE and GOPATH, creating directories, copying source and test files, and executing the 'go list' command to verify the project structure and test execution. It also includes a comparison with expected output. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/list_dedup_packages.txt#_snippet_0 LANGUAGE: bash CODE: ``` env GO111MODULE=off mkdir $WORK/tmp/testdata/src/xtestonly cp f.go $WORK/tmp/testdata/src/xtestonly/f.go cp f_test.go $WORK/tmp/testdata/src/xtestonly/f_test.go env GOPATH=$WORK/tmp/testdata cd $WORK # Check output of go list to ensure no duplicates go list xtestonly ./tmp/testdata/src/xtestonly/... cmp stdout $WORK/gopath/src/wantstdout ``` -------------------------------- TITLE: Go Get Exclude Imported Test Dependencies DESCRIPTION: Shows that 'go get -t' does not consider test dependencies of indirectly imported packages. The example verifies that 'rsc.io/quote' is not fetched when 'go get -t m/b' is executed, as 'm/b' imports 'm/a' which has test dependencies. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/mod_get_test.txt#_snippet_2 LANGUAGE: shell CODE: ``` # 'go get -t' should not consider test dependencies of imported packages, # including packages imported from tests. cp go.mod.empty go.mod go get -t m/b ! grep rsc.io/quote go.mod ``` -------------------------------- TITLE: SVN Log Entry Example DESCRIPTION: An example of an SVN log entry in XML format, showing revision details such as revision number, author, date, and commit message. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/vcstest/svn/hello.txt#_snippet_4 LANGUAGE: xml CODE: ``` rsc 2017-09-22T01:12:45.861368Z hello world ``` -------------------------------- TITLE: Go Main Package Example DESCRIPTION: Provides a simple Go program (`hello.go`) that prints 'hello, world' to the console. This serves as a basic example of a runnable Go application. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/run_hello_pkg.txt#_snippet_3 LANGUAGE: go CODE: ``` -- hello/hello.go -- package main func main() { println("hello, world") } ``` -------------------------------- TITLE: Go Module File Example DESCRIPTION: A minimal 'go.mod' file defining the module name as 'm' and specifying the Go version as 1.18. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/mod_getx.txt#_snippet_3 LANGUAGE: go CODE: ``` module m go 1.18 ``` -------------------------------- TITLE: Go Get Include Tests DESCRIPTION: Illustrates the use of 'go get -t' to include test dependencies. This example shows that when '-t' is used, test dependencies like 'rsc.io/quote' are fetched and recorded in go.mod. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/mod_get_test.txt#_snippet_1 LANGUAGE: shell CODE: ``` # 'go get -t' should consider test dependencies of the named package. cp go.mod.empty go.mod go get -t m/a grep 'rsc.io/quote v1.5.2$' go.mod ``` -------------------------------- TITLE: Go Build with Caching and Execution DESCRIPTION: This snippet shows the process of building a Go program, managing the build cache, and executing the compiled binary. It includes steps for setting up the environment, compiling, copying output, and comparing results. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/build_dash_x.txt#_snippet_0 LANGUAGE: bash CODE: ``` mkdir $WORK/tmp/cache env GOCACHE=$WORK/tmp/cache go build runtime/cgo go build -x -o main main.go cp stderr commands.txt cat header.txt commands.txt cp stdout test.sh exec ./main cmp stderr hello.txt rm ./main exec /usr/bin/env bash -x test.sh exec ./main cmp stderr hello.txt grep '^WORK=(.*)\n' commands.txt ``` -------------------------------- TITLE: Go Get Update Test Dependencies DESCRIPTION: Demonstrates updating test dependencies using 'go get -t -u'. This example shows that when a specific version of a dependency is required ('rsc.io/quote@v1.5.1') and 'go get -t -u m/a' is run, the test dependency is updated to the latest compatible version. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/mod_get_test.txt#_snippet_3 LANGUAGE: shell CODE: ``` # 'go get -t -u' should update test dependencies of the named package. cp go.mod.empty go.mod go mod edit -require=rsc.io/quote@v1.5.1 go get -t -u m/a grep 'rsc.io/quote v1.5.2$' go.mod ``` -------------------------------- TITLE: Go Get Do Not Update Imported Test Dependencies DESCRIPTION: Illustrates that 'go get -t -u' does not add or update test dependencies of indirectly imported packages. The example shows that running 'go get -t -u m/b' after setting a specific version for 'rsc.io/quote' does not change the version of the test dependency. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/mod_get_test.txt#_snippet_4 LANGUAGE: shell CODE: ``` # 'go get -t -u' should not add or update test dependencies # of imported packages, including packages imported from tests. cp go.mod.empty go.mod go mod edit -require=rsc.io/quote@v1.5.1 go get -t -u m/b ! grep rsc.io/quote go.mod go mod edit -require=rsc.io/quote@v1.5.1 go get -t -u m/b grep 'rsc.io/quote v1.5.1$' go.mod ``` -------------------------------- TITLE: Go Module Setup and External Library Build DESCRIPTION: Demonstrates setting the Go module environment, fetching an external module, building it as a C-shared library, and verifying its version and module path. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/version_cshared.txt#_snippet_0 LANGUAGE: shell CODE: ``` env GO111MODULE=on go get rsc.io/fortune go build -buildmode=c-shared -o external.so rsc.io/fortune go version external.so stdout '^external.so: .+' go version -m external.so stdout '^ path\trsc.io/fortune' stdout '^ mod\trsc.io/fortune\tv1.0.0' ``` -------------------------------- TITLE: Go Module and Source File Example DESCRIPTION: Provides a minimal `go.mod` file defining the module and Go version, and a `x.go` file that imports a vendored package (`rsc.io/quote`). This demonstrates a basic setup for a Go project using modules. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/mod_getmode_vendor.txt#_snippet_8 LANGUAGE: go CODE: ``` -- go.mod -- module x go 1.16 -- x.go -- package x import _ "rsc.io/quote" ``` -------------------------------- TITLE: Project README DESCRIPTION: Provides a textual overview of the project's development, specifically mentioning the addition of a subpackage in a future version. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/mod/example.net_pkgadded_v1.1.0.txt#_snippet_2 LANGUAGE: text CODE: ``` We will add the package example.net/pkgadded/subpkg in v1.2.0. ``` -------------------------------- TITLE: Go Build and Test Benchmarking Setup DESCRIPTION: Installs helper commands for checking file modification times and executing tests. Sets the GOBIN environment variable. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/build_issue6480.txt#_snippet_0 LANGUAGE: shell CODE: ``` env GOBIN=$WORK/tmp/bin go install m/now m/mtime m/before ``` -------------------------------- TITLE: Go Get for Main Package in Main Module DESCRIPTION: This snippet shows 'go get' being used for a main package within the main module. The intent is to update dependencies, and 'go install' would be used for direct installation. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/mod_get_deprecate_install.txt#_snippet_4 LANGUAGE: bash CODE: ``` cp go.mod.orig go.mod go get m ! stderr . cp go.mod.orig go.mod ``` -------------------------------- TITLE: Install Tools with Wildcards DESCRIPTION: Installs tools from a local module path using wildcards. This allows for installing multiple tools defined within a directory structure. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/mod_get_tool.txt#_snippet_4 LANGUAGE: shell CODE: ``` go get -tool ./cmd/... cmp go.mod go.mod.wildcard ``` -------------------------------- TITLE: Building and Archiving a Go Package DESCRIPTION: Builds the 'sync/atomic' package into a custom archive file 'myatomic.a' and then uses 'isarchive' to verify it. It also checks that the default package artifacts are not created. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/build_output.txt#_snippet_10 LANGUAGE: shell CODE: ``` go build -o myatomic.a sync/atomic exists myatomic.a exec $GOBIN/isarchive myatomic.a ! exists atomic ! exists atomic.a ! exists atomic.exe ``` -------------------------------- TITLE: Get Module Versions with Query and Exclusions DESCRIPTION: Demonstrates fetching module versions that match a query constraint, while also respecting exclusions defined in the go.mod file. This example shows how `go get` and `go list` interact with exclusion rules. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/mod_query_exclude.txt#_snippet_4 LANGUAGE: shell CODE: ``` # get query with excluded version cp go.exclude.mod.orig go.exclude.mod go get -modfile=go.exclude.mod rsc.io/quote@>=v1.5 go list -modfile=go.exclude.mod -m ...quote stdout 'rsc.io/quote v1.5.[1-9]' ``` -------------------------------- TITLE: Git Log File Content DESCRIPTION: Example content of a .git-log file showing a summarized commit history with branch and tag information. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/vcstest/git/issue47650.txt#_snippet_6 LANGUAGE: git CODE: ``` -- .git-log -- 21535ef (HEAD -> main) add go.mod 4d237df (tag: v0.1.0) add cmd/issue47650 ``` -------------------------------- TITLE: Initialize Git Repository and Basic Commits DESCRIPTION: Sets up Git author information, initializes a repository, makes an initial commit, renames the master branch, and creates tags for different versions. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/vcstest/git/vgotest1.txt#_snippet_0 LANGUAGE: bash CODE: ``` env GIT_AUTHOR_NAME='Russ Cox' env GIT_AUTHOR_EMAIL='rsc@golang.org' env GIT_COMMITTER_NAME=$GIT_AUTHOR_NAME env GIT_COMMITTER_EMAIL=$GIT_AUTHOR_EMAIL git init at 2018-02-19T17:21:09-05:00 git add LICENSE README.md git commit -m 'initial commit' git branch -m master git checkout --detach HEAD at 2018-02-19T18:10:06-05:00 mkdir pkg echo 'package p // pkg/p.go' cp stdout pkg/p.go git add pkg/p.go git commit -m 'add pkg/p.go' git tag v0.0.0 git tag v1.0.0 ``` -------------------------------- TITLE: Go Get Examples DESCRIPTION: Illustrates `go get` behavior with package paths ending in '.go' or '.go/'. It shows that arguments are interpreted as packages or package patterns with versions, not source files, and that versions can be specified with or without a trailing slash. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/mod_get_trailing_slash.txt#_snippet_1 LANGUAGE: go CODE: ``` go get example.com/dotgo.go go get example.com/dotgo.go/ go get example.com/dotgo.go@v1.0.0 go get example.com/dotgo.go/@v1.0.0 ``` -------------------------------- TITLE: Git Initialization and Version Tagging DESCRIPTION: This snippet covers the essential Git commands for setting up a new repository, making initial commits, and tagging specific versions of the project. It includes setting author environment variables, initializing the repository, committing changes, and creating version tags. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/vcstest/git/prefixtagtests.txt#_snippet_0 LANGUAGE: bash CODE: ``` env GIT_AUTHOR_NAME='Jay Conrod' env GIT_AUTHOR_EMAIL='jayconrod@google.com' env GIT_COMMITTER_NAME=$GIT_AUTHOR_NAME env GIT_COMMITTER_EMAIL=$GIT_AUTHOR_EMAIL git init git add sub git commit -m 'create module sub' git branch -m master echo 'v0.1.0' cp stdout status git add status git commit -a -m 'v0.1.0' git tag 'v0.1.0' echo 'sub/v0.0.9' cp stdout status git commit -a -m 'sub/v0.0.9' git tag 'sub/v0.0.9' echo 'sub/v0.0.10' cp stdout status git commit -a -m 'sub/v0.0.10' git tag 'sub/v0.0.10' echo 'v0.2.0' cp stdout status git commit -a -m 'v0.2.0' git tag 'v0.2.0' echo 'after last tag' cp stdout status git commit -a -m 'after last tag' git show-ref --tags --heads cmp stdout .git-refs ``` -------------------------------- TITLE: Go Package Definitions DESCRIPTION: Provides the basic package definitions for the Go source files used in the build examples. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/build_cache_pgo.txt#_snippet_1 LANGUAGE: go CODE: ``` -- lib.go -- package lib ``` LANGUAGE: go CODE: ``` -- lib2.go -- package lib2 ``` -------------------------------- TITLE: Fetching Go Modules with `go get` DESCRIPTION: Illustrates the use of `go get` to retrieve specific versions of a Go module. This command is fundamental for managing dependencies in Go projects. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/badgo.txt#_snippet_0 LANGUAGE: shell CODE: ``` go get example.net/badgo@v1.0.0 go get example.net/badgo@v1.1.0 go get example.net/badgo@v1.2.0 go get example.net/badgo@v1.3.0 go get example.net/badgo@v1.4.0 go get example.net/badgo@v1.5.0 ! go get example.net/badgo@v1.6.0 stderr 'invalid go version .X.Y.: must match format 1.23' ``` -------------------------------- TITLE: Git Initialization and Configuration DESCRIPTION: Initializes a new Git repository, configures case-insensitive file handling, and sets up Unicode pre-composition. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/vcstest/svn/test2-svn-git.txt#_snippet_1 LANGUAGE: git CODE: ``` git init git config --add core.ignorecase true git config --add core.precomposeunicode true ``` -------------------------------- TITLE: Go Get Ignore Tests DESCRIPTION: Demonstrates the default behavior of 'go get' ignoring test dependencies. It shows how 'go get m/a' does not fetch test dependencies, as verified by checking the go.mod file. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/mod_get_test.txt#_snippet_0 LANGUAGE: shell CODE: ``` env GO111MODULE=on # By default, 'go get' should ignore tests cp go.mod.empty go.mod go get m/a ! grep rsc.io/quote go.mod ``` -------------------------------- TITLE: Building a Go Package (No Executable) DESCRIPTION: Compiles the 'sync/atomic' package without creating an executable. This is typical for library packages that are not meant to be run directly. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/build_output.txt#_snippet_9 LANGUAGE: shell CODE: ``` go build sync/atomic ! exists atomic ! exists atomic.exe ``` -------------------------------- TITLE: Go Regex: Matching with Start and End Anchors and Group DESCRIPTION: Demonstrates matching a string that starts and ends with a specific group in Go. This example matches strings that start and end with 'foo', 'bar', or an uppercase letter. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/regexp/testdata/re2-search.txt#_snippet_10 LANGUAGE: go CODE: ``` package main import ( "fmt" "regexp" ) func main() { pattern := "^(?:^(foo|bar|[A-Z])$)$" re, err := regexp.Compile(pattern) if err != nil { fmt.Println("Error compiling regex:", err) return } input := "foo\n" match := re.MatchString(input) fmt.Printf("Does '%s' match '%s'? %t\n", input, pattern, match) } ``` -------------------------------- TITLE: SVN Project Initialization and Checkout DESCRIPTION: This snippet details the initial setup for an SVN repository within a Go project. It includes creating necessary directories, setting permissions, configuring the environment, and performing the SVN checkout command, with platform-specific handling for Windows line endings. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/vcstest/svn/hello.txt#_snippet_0 LANGUAGE: bash CODE: ``` mkdir db/transactions mkdir db/txn-protorevs chmod 0755 hooks/pre-revprop-change env ROOT=$PWD cd .checkout [GOOS:windows] svn checkout file:///$ROOT . [!GOOS:windows] svn checkout file://$ROOT . [GOOS:windows] replace '\n' '\r\n' .svn-log cmp stdout .svn-log ``` -------------------------------- TITLE: Go Module Configuration DESCRIPTION: Example of a go.mod file defining a module and Go version, used in conjunction with the 'go get' tests. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/mod_get_go_file.txt#_snippet_1 LANGUAGE: go CODE: ``` module m go 1.18 ``` -------------------------------- TITLE: List All Modules DESCRIPTION: Lists all modules required by the current module, including their versions. The output '! stdout example.com/bar' indicates the expected output format. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/mod_get_none.txt#_snippet_2 LANGUAGE: bash CODE: ``` go list -m all ! stdout example.com/bar ``` -------------------------------- TITLE: Git References File Content DESCRIPTION: Example content of a .git-refs file showing commit SHAs and their corresponding references. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/vcstest/git/issue47650.txt#_snippet_5 LANGUAGE: git CODE: ``` -- .git-refs -- 21535ef346c3e79fd09edd75bd4725f06c828e43 refs/heads/main 4d237df2dbfc8a443af2f5e84be774f08a2aed0c refs/tags/v0.1.0 ``` -------------------------------- TITLE: Go Get Empty Patterns DESCRIPTION: Demonstrates the 'go get' command with empty patterns within a module. It shows that a warning is issued only once when matching no packages. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/mod_get_nopkgs.txt#_snippet_0 LANGUAGE: shell CODE: ``` cd subdir # 'go get' on empty patterns that are necessarily local to the module # should warn that the patterns are empty, exactly once. go get ./... stderr -count=1 'matched no packages' go get ./... stderr -count=1 'matched no packages' ``` -------------------------------- TITLE: Go Work Vendor and List Commands DESCRIPTION: Basic commands to set up a Go workspace, vendor modules, and list modules to check for inconsistencies. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/work_vendor_modules_txt_consistent.txt#_snippet_0 LANGUAGE: go CODE: ``` go work vendor cmp modules.txt.want vendor/modules.txt go list example.com/a example.com/b ``` -------------------------------- TITLE: Go Project Setup with Vendor Directory DESCRIPTION: This snippet details the process of creating a Go project structure, including setting up a vendor directory and using symlinks to manage dependencies. It configures the GOPATH and then executes `go list` to display the project's dependencies. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/list_symlink_vendor_issue15201.txt#_snippet_0 LANGUAGE: shell CODE: ``` env GO111MODULE=off mkdir $WORK/tmp/gopath/src/x/y/_vendor/src/x symlink $WORK/tmp/gopath/src/x/y/_vendor/src/x/y -> ../../.. mkdir $WORK/tmp/gopath/src/x/y/_vendor/src/x/y/w cp w.go $WORK/tmp/gopath/src/x/y/w/w.go symlink $WORK/tmp/gopath/src/x/y/w/vendor -> ../_vendor/src mkdir $WORK/tmp/gopath/src/x/y/_vendor/src/x/y/z cp z.go $WORK/tmp/gopath/src/x/y/z/z.go env GOPATH=$WORK/tmp/gopath/src/x/y/_vendor${:}$WORK/tmp/gopath cd $WORK/tmp/gopath/src go list ./... ``` -------------------------------- TITLE: Go Get Usage DESCRIPTION: Details the usage of the 'go get' command, which is used to download and install packages and their dependencies, including specific module versions. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/help.txt#_snippet_4 LANGUAGE: go CODE: ``` go help get # Expected output includes: # usage: go get # specific module versions ``` -------------------------------- TITLE: Install Multiple Packages with Same Version DESCRIPTION: Demonstrates the successful installation of multiple packages from the same module with identical version suffixes, verifying that both executables are created. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/mod_install_pkg_version.txt#_snippet_7 LANGUAGE: shell CODE: ``` go install example.com/cmd/a@v1.0.0 example.com/cmd/b@v1.0.0 exists $GOPATH/bin/a$GOEXE exists $GOPATH/bin/b$GOEXE rm $GOPATH/bin env GO111MODULE=on go list -m example.com/cmd@latest stdout '^example.com/cmd v1.0.0$' env GO111MODULE=auto ``` -------------------------------- TITLE: Get Specific Dependency Version DESCRIPTION: Updates or adds a specific dependency to the go.mod file. This example updates `rsc.io/sampler` to v1.3.1 and marks it as indirect. SOURCE: https://github.com/golang/go/blob/go1.24.6/src/cmd/go/testdata/script/mod_vendor_build.txt#_snippet_2 LANGUAGE: go CODE: ``` go get rsc.io/sampler@v1.3.1 ```