================ CODE SNIPPETS ================ TITLE: Add Benign Commit and Go Get DESCRIPTION: Adds a commit to the benign repository and then uses `go get -u` to install it, demonstrating a standard package retrieval. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/get_dotfiles.txt#_snippet_2 LANGUAGE: shell CODE: ``` cd $WORK/_origin/foo cp _ok/main.go main.go exec git add main.go exec git commit -m 'add ok' cd $GOPATH go get -u example.com/foo ``` -------------------------------- TITLE: Install Go Package DESCRIPTION: Installs or updates a Go package using the go get command. This command fetches the specified package and its dependencies. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/get_vcs_error_message.txt#_snippet_0 LANGUAGE: bash CODE: ``` go get -u foo ``` -------------------------------- TITLE: Install Go Package with Git Trace DESCRIPTION: Demonstrates installing a Go package from a remote repository using 'go get' while Git trace logging is enabled. This command fetches the 'golang.org/x/text' package. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/get_with_git_trace.txt#_snippet_2 LANGUAGE: shell CODE: ``` # go get should be success when GIT_TRACE set go get golang.org/x/text ``` -------------------------------- TITLE: Go Project Structure Example DESCRIPTION: A basic Go project structure example, showing a package declaration and import path. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/mod_convert_glockfile.txt#_snippet_1 LANGUAGE: go CODE: ``` package x // import "m/x" ``` -------------------------------- TITLE: Go Build and Test Commands DESCRIPTION: This snippet demonstrates the basic commands for fetching dependencies, building, and testing a Go package. It includes installing dependencies with `go get`, building the project with `go build`, and running tests with `go test`. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/vendor_test_issue14613.txt#_snippet_0 LANGUAGE: shell CODE: ``` cd $GOPATH go get github.com/clsung/go-vendor-issue-14613 go build -o $WORK/a.out -i github.com/clsung/go-vendor-issue-14613 # test folder should work go test -i github.com/clsung/go-vendor-issue-14613 go test github.com/clsung/go-vendor-issue-14613 ``` -------------------------------- TITLE: Fetch Go Dependencies with Verbose Logging DESCRIPTION: Demonstrates fetching Go dependencies using `go get -x`. The `-x` flag enables verbose logging, showing the URLs being fetched. This example specifically targets `golang.org/x/text` and verifies that schemeless URLs are not logged, adhering to a bug fix. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/mod_getx.txt#_snippet_1 LANGUAGE: bash CODE: ``` # 'go get -x' should log URLs with an HTTP or HTTPS scheme. # A bug had caused us to log schemeless URLs instead. go get -x -d golang.org/x/text@v0.1.0 stderr '^# get https://golang.org/x/text\?go-get=1$' stderr '^# get https://golang.org/x/text\?go-get=1: 200 OK \([0-9.]+s\)$' ! stderr '^# get //.*' ``` -------------------------------- TITLE: Go Project Initialization and Dependency Management DESCRIPTION: Demonstrates setting the GO111MODULE environment variable, fetching dependencies with go get, and installing a local package. It also shows the content of a go.mod file and a main.go file with an invalid import path. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/mod_import_v1suffix.txt#_snippet_0 LANGUAGE: shell CODE: ``` env GO111MODULE=on ! go get -d example.com/invalidpath/v1 ! go install . ``` LANGUAGE: go CODE: ``` -- go.mod -- module example.com ``` LANGUAGE: go CODE: ``` -- main.go -- package main import _ "example.com/invalidpath/v1" func main() {} ``` -------------------------------- TITLE: Simple Go Hello World Program DESCRIPTION: A basic Go program that prints 'hello' to the console. This serves as a minimal example for demonstrating the Go build process. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/build_GOTMPDIR.txt#_snippet_1 LANGUAGE: go CODE: ``` package main func main() { println("hello") } ``` -------------------------------- TITLE: Go Project File Example DESCRIPTION: A basic Go source file example for a project, demonstrating package declaration and import paths. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/mod_convert_glide.txt#_snippet_1 LANGUAGE: go CODE: ``` package x // import "m/x" ``` -------------------------------- TITLE: Install/Update Go Dependencies DESCRIPTION: Demonstrates how to install or update Go packages using the `go get` command. The `-u` flag updates the specified package and its dependencies to the latest version. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/get_issue11307.txt#_snippet_0 LANGUAGE: go CODE: ``` env GOPATH=$WORK/tmp/gopath go get github.com/rsc/go-get-issue-11307 go get -u github.com/rsc/go-get-issue-11307 ``` -------------------------------- TITLE: Basic Cross-Compilation and Installation DESCRIPTION: Demonstrates setting environment variables for cross-compilation and installing a Go command. It shows how implicit GOBIN settings affect the installation path. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/install_cross_gobin.txt#_snippet_0 LANGUAGE: bash CODE: ``` env GO111MODULE=off skip # rebuilds std for alternate architecture cd mycmd go build mycmd # cross-compile install with implicit GOBIN=$GOPATH/bin can make subdirectory env GOARCH=386 [386] env GOARCH=amd64 env GOOS=linux go install mycmd exists $GOPATH/bin/linux_$GOARCH/mycmd ``` -------------------------------- TITLE: Installing and Using Additional Go Versions DESCRIPTION: Shows how to install specific Go versions using the 'go get' command and then download and use them. This is useful for testing compatibility across different Go releases. SOURCE: https://github.com/golang/go/blob/go1_15_15/doc/install.html#_snippet_4 LANGUAGE: bash CODE: ``` go get golang.org/dl/go1.10.7 go1.10.7 download go1.10.7 version ``` -------------------------------- TITLE: Go Project File Example DESCRIPTION: A basic Go source file example, demonstrating package declaration and import paths. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/mod_convert_tsv.txt#_snippet_1 LANGUAGE: go CODE: ``` package x // import "m/x" ``` -------------------------------- TITLE: Fetch Go Dependencies DESCRIPTION: Uses 'go get -d' to download the source code for the specified Go package without installing it. The example shows fetching 'golang.org/x/tools' and handling the stderr output indicating no Go files were found in the package. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/get_non_pkg.txt#_snippet_1 LANGUAGE: go CODE: ``` ! go get -d golang.org/x/tools stderr 'golang.org/x/tools: no Go files' ``` LANGUAGE: go CODE: ``` ! go get -d -u golang.org/x/tools stderr 'golang.org/x/tools: no Go files' ``` LANGUAGE: go CODE: ``` ! go get -d golang.org/x/tools stderr 'golang.org/x/tools: no Go files' ``` -------------------------------- TITLE: Basic HTTP Server Setup DESCRIPTION: Sets up a basic HTTP server to handle requests to the web root and listen on port 8080. It uses http.HandleFunc to associate a handler function with a URL path and http.ListenAndServe to start the server. SOURCE: https://github.com/golang/go/blob/go1_15_15/doc/articles/wiki/index.html#_snippet_6 LANGUAGE: go CODE: ``` package main import ( "fmt" "log" "net/http" ) func handler(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:]) } func main() { http.HandleFunc("/", handler) log.Fatal(http.ListenAndServe(":8080", nil)) } ``` -------------------------------- TITLE: Go Module Initialization and Download DESCRIPTION: Initializes Go modules by copying the original go.mod file and then downloads all dependencies specified in the go.mod file. This is a common setup step for Go projects. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/mod_load_badchain.txt#_snippet_0 LANGUAGE: go CODE: ``` env GO111MODULE=on # Download everything to avoid "finding" messages in stderr later. cp go.mod.orig go.mod go mod download go mod download example.com@v1.0.0 go mod download example.com/badchain/a@v1.1.0 go mod download example.com/badchain/b@v1.1.0 go mod download example.com/badchain/c@v1.1.0 ``` -------------------------------- TITLE: Minimal Go Program DESCRIPTION: A basic Go program that does nothing, suitable for testing build and installation processes. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/install_cross_gobin.txt#_snippet_3 LANGUAGE: go CODE: ``` package main func main() {} ``` -------------------------------- TITLE: Installing Go Packages with go get DESCRIPTION: Demonstrates how to use the `go get` command to download and install external Go packages and their dependencies. This command fetches code from version control repositories and places it in the appropriate locations within the `$GOPATH`. SOURCE: https://github.com/golang/go/blob/go1_15_15/doc/articles/go_command.html#_snippet_2 LANGUAGE: bash CODE: ``` go get github.com/google/codesearch/index go get github.com/petar/GoLLRB/llrb ``` -------------------------------- TITLE: Go Module Vendor Setup and Get DESCRIPTION: Sets up the environment for Go modules with vendoring and retrieves a specific version of a dependency. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/mod_getmode_vendor.txt#_snippet_0 LANGUAGE: shell CODE: ``` env GO111MODULE=on go get -d rsc.io/quote@v1.5.1 go mod vendor ``` -------------------------------- TITLE: Basic Go Package Structure DESCRIPTION: Defines a simple Go package named 'p' within the 'empty/pkg' directory. This serves as a minimal example for package creation and testing. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/test_race_install.txt#_snippet_2 LANGUAGE: go CODE: ``` package p ``` -------------------------------- TITLE: Installing godoc and vet DESCRIPTION: Instructions for installing the godoc and vet commands using 'go get' after their source code has been moved to the go.tools subrepository. SOURCE: https://github.com/golang/go/blob/go1_15_15/doc/go1.2.html#_snippet_3 LANGUAGE: bash CODE: ``` $ go get code.google.com/p/go.tools/cmd/godoc $ go get code.google.com/p/go.tools/cmd/vet ``` -------------------------------- TITLE: Install echo command for Windows DESCRIPTION: Installs the 'echo' command for use in environments where it might not be natively available, such as Windows. It sets the GOBIN environment variable and then installs the echo.go program. SOURCE: https://github.com/golang/go/blob/go1_15_15/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 Project Setup and Execution DESCRIPTION: This snippet details the shell commands required to set up a Go project directory structure, copy source files, create symbolic links for internal packages, configure the GOPATH environment variable, and then execute Go commands like `go list`, `go run`, `go build`, and `go install`. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/list_symlink_internal.txt#_snippet_0 LANGUAGE: shell CODE: ``` 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: Example Main Go File in 'x' Directory DESCRIPTION: A basic Go program located in the 'x' directory, defining the main package and an empty main function. This serves as a placeholder for actual application logic. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/mod_init_path.txt#_snippet_3 LANGUAGE: go CODE: ``` -- x/main.go -- package main func main() {} ``` -------------------------------- TITLE: Building a Go Program DESCRIPTION: Compiles a Go program named 'hello.go'. The example also shows a potential error message related to missing libraries during the build process. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/build_arm.txt#_snippet_1 LANGUAGE: shell CODE: ``` go build hello.go ! stderr 'unable to find math.a' ``` LANGUAGE: go CODE: ``` package main func main() {} ``` -------------------------------- TITLE: Add Dotfile Commit and Update DESCRIPTION: Adds a commit to the dotfile repository and then attempts to update the benign repository, showing `go get`'s refusal to handle dotfile paths. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/get_dotfiles.txt#_snippet_3 LANGUAGE: shell CODE: ``` cd $WORK/_origin/.hidden exec git add hidden.go exec git commit -m 'nothing to see here, move along' cd $WORK/_origin/foo cp _sneaky/main.go main.go exec git add main.go exec git commit -m 'fix typo (heh heh heh)' cd $GOPATH/src/example.com/foo ! go get -u example.com/foo stderr 'leading dot' ! exists example.com/.hidden/hidden.go ``` -------------------------------- TITLE: Fetch Go Project Dependencies DESCRIPTION: This command fetches the dependencies for the specified Go module. The `-d` flag tells `go get` to only download the source code and not build or install it. The `-u` flag updates the named packages to their latest version. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/get_update_unknown_protocol.txt#_snippet_1 LANGUAGE: go CODE: ``` go get -d -u -f github.com/golang/example/hello ``` -------------------------------- TITLE: Go Modules Vendoring Example DESCRIPTION: This snippet shows the environment setup and command to list modules in a vendored Go project. It also includes expected stdout and a sample go.mod file. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/mod_patterns_vendor.txt#_snippet_0 LANGUAGE: shell CODE: ``` env GO111MODULE=on go list -mod=vendor example.com/... stdout ^example.com/x$ stdout ^example.com/x/y$ ! stdout ^example.com/x/vendor ``` LANGUAGE: go CODE: ``` -- go.mod -- module example.com/m ``` -------------------------------- TITLE: Go Get Command Usage DESCRIPTION: Illustrates the use of the 'go get' command for fetching and installing packages, emphasizing its simplicity for users. SOURCE: https://github.com/golang/go/blob/go1_15_15/doc/articles/go_command.html#_snippet_7 LANGUAGE: go CODE: ``` go get ``` -------------------------------- TITLE: Go Module Initialization and Dependency Retrieval DESCRIPTION: Demonstrates setting up Go modules and retrieving dependencies. It shows how to set the module environment, copy a go.mod file, get dependencies recursively, and verify the go.mod content. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/mod_get_patterns.txt#_snippet_0 LANGUAGE: bash CODE: ``` env GO111MODULE=on cp go.mod.orig go.mod go get -d rsc.io/quote/... grep 'require rsc.io/quote' go.mod ``` -------------------------------- TITLE: Standard Command Installation Path DESCRIPTION: Shows the expected installation directory for a cross-compiled standard Go command, which includes the GOARCH in its path. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/install_cross_gobin.txt#_snippet_2 LANGUAGE: bash 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: Testing Go Installation DESCRIPTION: A simple Go program to verify that the Go installation is working correctly. It prints "hello, world" to the console. SOURCE: https://github.com/golang/go/blob/go1_15_15/doc/install-source.html#_snippet_6 LANGUAGE: go CODE: ``` package main import "fmt" func main() { fmt.Printf("hello, world\n") } ``` -------------------------------- TITLE: Initialize Git Repositories DESCRIPTION: Initializes two Git repositories: one benign and one with a dotfile in its name. Sets user name and email for commits. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/get_dotfiles.txt#_snippet_0 LANGUAGE: shell CODE: ``` cd $WORK/_origin/foo exec git init exec git config user.name 'Nameless Gopher' exec git config user.email 'nobody@golang.org' exec git commit --allow-empty -m 'create master branch' cd $WORK/_origin/.hidden exec git init exec git config user.name 'Nameless Gopher' exec git config user.email 'nobody@golang.org' exec git commit --allow-empty -m 'create master branch' ``` -------------------------------- TITLE: Clone Repositories into GOPATH DESCRIPTION: Clones the initialized Git repositories into the specified GOPATH, simulating how Go commands find external packages. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/get_dotfiles.txt#_snippet_1 LANGUAGE: shell CODE: ``` mkdir $GOPATH/src/example.com cd $GOPATH/src/example.com exec git clone $WORK/_origin/foo exec git clone $WORK/_origin/.hidden ``` -------------------------------- TITLE: Go Module Setup and Build DESCRIPTION: Demonstrates setting up Go modules, fetching dependencies, and building the project executable and test binary. It shows how to verify the default naming conventions for the generated binaries. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/mod_build_versioned.txt#_snippet_0 LANGUAGE: shell CODE: ``` env GO111MODULE=on go get -d rsc.io/fortune/v2 # The default executable name shouldn't be v2$GOEXE go build rsc.io/fortune/v2 ! exists v2$GOEXE exists fortune$GOEXE # The default test binary name shouldn't be v2.test$GOEXE go test -c rsc.io/fortune/v2 ! exists v2.test$GOEXE exists fortune.test$GOEXE ``` LANGUAGE: go CODE: ``` -- go.mod -- module scratch ``` -------------------------------- TITLE: Go Module File Example DESCRIPTION: Provides a sample `go.mod` file content, demonstrating a module declaration and a require directive for a specific package version. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/mod_get_trailing_slash.txt#_snippet_2 LANGUAGE: go CODE: ``` -- go.mod -- module m go 1.13 require example.com/dotgo.go v1.0.0 ``` -------------------------------- TITLE: Building and Running a Go Program DESCRIPTION: Demonstrates how to build and execute a simple 'hello, world' Go program. This involves creating a .go file, compiling it using the 'go build' command, and then running the resulting executable. SOURCE: https://github.com/golang/go/blob/go1_15_15/doc/install.html#_snippet_3 LANGUAGE: go CODE: ``` package main import "fmt" func main() { fmt.Printf("hello, world\n") } ``` LANGUAGE: bash CODE: ``` $ go build hello.go ./hello ``` -------------------------------- TITLE: Installing a Package with go install DESCRIPTION: Explains how the `go install` command compiles and installs a package, placing the compiled output in the `pkg` directory. It also handles recursive installation of dependencies if they are out of date. SOURCE: https://github.com/golang/go/blob/go1_15_15/doc/articles/go_command.html#_snippet_5 LANGUAGE: bash CODE: ``` cd github.com/google/codesearch/regexp go install ``` -------------------------------- TITLE: Architecture-Specific Assembly Instructions (ARM Example) DESCRIPTION: The Go toolchain defines assembly instructions for various architectures. These are listed as constants in the `obj` support library for each architecture, typically starting with 'A'. For example, in `src/cmd/internal/obj/arm/a.out.go`. SOURCE: https://github.com/golang/go/blob/go1_15_15/doc/asm.html#_snippet_16 LANGUAGE: assembly CODE: ``` // Example constants from src/cmd/internal/obj/arm/a.out.go const ( AAND = obj.ABaseARM + obj.A_ARCHSPECIFIC + iota AEOR ASUB ARSB AADD ) // In assembly source, these are written without the 'A' prefix: // AND // EOR // SUB // RSB // ADD ``` -------------------------------- TITLE: Go Project Initialization and Dependency Fetching DESCRIPTION: This snippet shows the initial steps for setting up a Go project. It involves enabling Go modules, copying a base go.mod file, and fetching dependencies, including an unstable version of a package. SOURCE: https://github.com/golang/go/blob/go1_15_15/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 -d gopkg.in/dummy.v2-unstable cp x.go.txt x.go cp go.mod.empty go.mod go list ``` -------------------------------- TITLE: Go Build and Install Workflow DESCRIPTION: Illustrates the process of building and installing a Go package (`p1`) and then checking for stale packages (`stale p1 p2`). It shows how modifying a dependency (`p2`) affects the perceived staleness of `p1`. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/install_rebuild_gopath.txt#_snippet_1 LANGUAGE: shell CODE: ``` # build & install p1 go install -i p1 ! stale p1 p2 # modify p2 - p1 should appear stale cp $WORK/p2x.go $WORK/d2/src/p2/p2.go stale p1 p2 # build & install p1 again go install -i p1 ! stale p1 p2 ``` -------------------------------- TITLE: Go Project Setup and Verification DESCRIPTION: This snippet details the steps to set up a Go project environment, including creating directories, copying source files, setting the GOPATH, and verifying the output of the `go list` command against expected results. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/list_dedup_packages.txt#_snippet_0 LANGUAGE: bash CODE: ``` 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 go list xtestonly ./tmp/testdata/src/xtestonly/... cmp stdout $WORK/gopath/src/wantstdout ``` -------------------------------- TITLE: Example Main Go File in 'y' Directory DESCRIPTION: A basic Go program located in the 'y' directory, defining the main package and an empty main function. This serves as a placeholder for actual application logic. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/mod_init_path.txt#_snippet_4 LANGUAGE: go CODE: ``` -- y/main.go -- package main func main() {} ``` -------------------------------- TITLE: Simple HTTP Server Example DESCRIPTION: A basic Go program that sets up and runs a simple HTTP server. SOURCE: https://github.com/golang/go/blob/go1_15_15/doc/articles/wiki/index.html#_snippet_5 LANGUAGE: go CODE: ``` package main import ( "fmt" "log" "net/http" ) func handler(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:]) } func main() { http.HandleFunc("/", handler) log.Fatal(http.ListenAndServe(":8080", nil)) } ``` -------------------------------- TITLE: Go Install After Get DESCRIPTION: Demonstrates that after a 'go get' operation, a subsequent 'go install' for the same package does not re-run the compiler if the package is not stale. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/mod_get_commit.txt#_snippet_1 LANGUAGE: shell CODE: ``` # install after get should not run the compiler again. go install -x golang.org/x/text/language ! stderr 'compile|cp|gccgo .*language\.a$' ``` -------------------------------- TITLE: Install goimports Tool DESCRIPTION: Fetches and installs the goimports tool, which automatically formats Go source files. The command uses '-x' for verbose output, '-v' for progress, and '-d' to download dependencies without installing. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/mod_get_fallback.txt#_snippet_1 LANGUAGE: bash CODE: ``` go get -x -v -d golang.org/x/tools/cmd/goimports ``` -------------------------------- TITLE: Cross-Compilation with Explicit GOBIN DESCRIPTION: Illustrates cross-compilation and installation when GOBIN is explicitly set. This method does not create subdirectories for different architectures. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/install_cross_gobin.txt#_snippet_1 LANGUAGE: bash CODE: ``` # cross-compile install with explicit GOBIN cannot make subdirectory env GOBIN=$WORK/bin ! go install mycmd ! exists $GOBIN/linux_$GOARCH ``` -------------------------------- TITLE: Go Project Setup and Listing DESCRIPTION: This snippet shows how to set up a Go project directory structure, create a symbolic link, copy a Go file into the new structure, and then use the `go list` command with a specific format to display the project root based on the `GOPATH` environment variable. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/list_symlink.txt#_snippet_0 LANGUAGE: shell CODE: ``` 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'$' ``` LANGUAGE: go CODE: ``` package p ``` -------------------------------- TITLE: Go Main Package with Dotfile Import DESCRIPTION: A Go program that imports a package from a dotfile-named repository, intended to test Go's handling of such paths. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/get_dotfiles.txt#_snippet_5 LANGUAGE: go CODE: ``` package main import _ "example.com/.hidden" func main() {} ``` -------------------------------- TITLE: Executing Go Program DESCRIPTION: Instructions for compiling and running a Go program. It shows how to navigate to the project directory and execute the Go file using the `go run` command. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/run_hello_pkg.txt#_snippet_1 LANGUAGE: bash CODE: ``` cd $GOPATH go run hello stderr 'hello, world' ``` LANGUAGE: bash CODE: ``` cd src/hello go run . stderr 'hello, world' ``` -------------------------------- TITLE: Download Go Dependencies DESCRIPTION: This command downloads the dependencies for a Go project without installing them. It's useful for CI/CD pipelines or when you only need the source code. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/get_insecure_custom_domain.txt#_snippet_0 LANGUAGE: go CODE: ``` go get -d -insecure insecure.go-get-issue-15410.appspot.com/pkg/p ``` -------------------------------- TITLE: Go Project Initialization and Build DESCRIPTION: Demonstrates the commands to initialize a Go module, set the environment for module usage, and build the project. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/mod_string_alias.txt#_snippet_0 LANGUAGE: shell CODE: ``` env GO111MODULE=on go mod init golang.org/issue/27584 go build . ``` -------------------------------- TITLE: Install Go Package DESCRIPTION: Installs a Go package and its dependencies using `go get`. This command is fundamental for managing external libraries in Go projects. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/vendor_list_issue11977.txt#_snippet_0 LANGUAGE: go CODE: ``` go get github.com/rsc/go-get-issue-11864 ``` -------------------------------- TITLE: Benign Go Main Package DESCRIPTION: A simple Go program that serves as a benign package for demonstration purposes. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/get_dotfiles.txt#_snippet_4 LANGUAGE: go CODE: ``` package main func main() {} ``` -------------------------------- TITLE: Basic Dependency Fetching and Module Initialization DESCRIPTION: Demonstrates setting up the Go module environment and fetching dependencies. It includes copying a module file and fetching a dependency. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/mod_get_main.txt#_snippet_0 LANGUAGE: bash CODE: ``` env GO111MODULE=on cp go.mod.orig go.mod go get -d .. go get -d $WORK go get -d ../... go get -d $WORK/... go get -d rsc.io/x grep 'rsc.io/quote v1.5.2' go.mod go get -d rsc.io/x@upgrade grep 'rsc.io/quote v1.5.2' go.mod cp go.mod.orig go.mod go get -d rsc.io/x@patch grep 'rsc.io/quote v1.5.2' go.mod cp go.mod.orig go.mod ``` -------------------------------- TITLE: Go Module Exclusion Setup DESCRIPTION: This snippet shows the Go module files (`go.mod`) used in the examples, demonstrating how to define exclusions and requirements for dependencies. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/mod_require_exclude.txt#_snippet_3 LANGUAGE: go CODE: ``` -- x.go -- package x import _ "rsc.io/quote" -- go.mod -- module x exclude rsc.io/sampler latest require rsc.io/sampler latest -- go.mod2 -- module x exclude rsc.io/quote v1.5.1 require rsc.io/quote v1.5.1 -- go.mod3 -- module x exclude rsc.io/quote v1.5.2 require rsc.io/quote v1.5.1 ``` -------------------------------- TITLE: Go Get and Path Validation DESCRIPTION: Demonstrates the behavior of `go get` with invalid import paths and checks for the existence of a confusingly named repository. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/get_brace.txt#_snippet_3 LANGUAGE: bash CODE: ``` # 'go get' should refuse to download or update the confusingly-named repo. cd $GOPATH/src/example.com/foo ! go get -u 'example.com/{confusing}' stderr 'invalid char' ! go get -u example.com/foo stderr 'invalid import path' ! exists example.com/{confusing} ``` -------------------------------- TITLE: Go Package Definition Example DESCRIPTION: A simple Go package definition for 'mypkg'. This snippet shows the basic structure of a Go source file. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/pattern_syntax_error.txt#_snippet_2 LANGUAGE: go CODE: ``` package mypkg ``` -------------------------------- TITLE: Install Go from MSI Installer (Windows) DESCRIPTION: This describes the process of installing Go on Windows using the MSI installer, which automatically configures the Go distribution and adds it to the system's PATH. SOURCE: https://github.com/golang/go/blob/go1_15_15/doc/install.html#_snippet_1 LANGUAGE: powershell CODE: ``` c:\Go\bin ``` -------------------------------- TITLE: Install rsc.io/pdf Package DESCRIPTION: This command downloads and installs the rsc.io/pdf package and its dependencies. The `-u` flag ensures that you get the latest version. After installation, the executable `pdfpasswd` will be available in your Go binary path. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/get_custom_domain_wildcard.txt#_snippet_0 LANGUAGE: bash CODE: ``` go get -u rsc.io/pdf/... # Expected installation path: # $GOPATH/bin/pdfpasswd$GOEXE ``` -------------------------------- TITLE: Initialize Go Module in Subdirectory 'x' DESCRIPTION: Navigates into the 'x' subdirectory and initializes a Go module with the specified path 'example.com/x'. This is useful for creating separate modules within a larger project structure. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/mod_init_path.txt#_snippet_1 LANGUAGE: bash CODE: ``` cd x go mod init example.com/x ``` -------------------------------- TITLE: Basic Go Test File DESCRIPTION: A simple Go test file (`main_test.go`) that defines a basic test function. This serves as a minimal example for Go testing. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/test_go111module_cache.txt#_snippet_1 LANGUAGE: go CODE: ``` package main import "testing" func TestF(t *testing.T) {} ``` -------------------------------- TITLE: Running Go Tests DESCRIPTION: Executes Go tests using the 'go test' command. It shows how to list tests, benchmarks, and examples. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/list_test_simple.txt#_snippet_0 LANGUAGE: bash CODE: ``` # Test go test './gopath/src/testlist/...' -list=Test stdout TestSimple # Benchmark go test './gopath/src/testlist/...' -list=Benchmark stdout BenchmarkSimple # Examples go test './gopath/src/testlist/...' -list=Example stdout ExampleSimple stdout ExampleWithEmptyOutput ``` -------------------------------- TITLE: Go Get Path Resolution with Tildes DESCRIPTION: These examples demonstrate scenarios where `go get` attempts to resolve paths containing tildes, such as those with a tilde followed by a name or a single tilde, and the expected error messages when the path is not found. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/get_tilde.txt#_snippet_1 LANGUAGE: shell CODE: ``` # A path containing an element that is just a tilde, or a tilde followed by non-digits, # should attempt to resolve. ! go get example.com/~glenda/notfound ! stderr 'trailing tilde and digits' stderr 'unrecognized import path' ! go get example.com/~glenda2/notfound ! stderr 'trailing tilde and digits' stderr 'unrecognized import path' ! go get example.com/~/notfound ! stderr 'trailing tilde and digits' stderr 'unrecognized import path' ``` -------------------------------- TITLE: Go Project Initialization and CGO Usage DESCRIPTION: This snippet demonstrates how to set up a Go module, enable module support, fetch the CGO package, and build the project. It's essential for projects that interact with C code. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/mod_case_cgo.txt#_snippet_0 LANGUAGE: shell CODE: ``` env GO111MODULE=on go get rsc.io/CGO go build rsc.io/CGO ``` LANGUAGE: go CODE: ``` -- go.mod -- module x ``` -------------------------------- TITLE: Go Get Package Retrieval DESCRIPTION: Demonstrates the behavior of `go get -d` and `go get` commands when retrieving packages with paths ending in '.go' or '.go/', including versioned and unversioned requests. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/mod_get_trailing_slash.txt#_snippet_1 LANGUAGE: go CODE: ``` # go get -d should succeed in either case, with or without a version. # Arguments are interpreted as packages or package patterns with versions, # not source files. go get -d example.com/dotgo.go go get -d example.com/dotgo.go/ go get -d example.com/dotgo.go@v1.0.0 go get -d example.com/dotgo.go/@v1.0.0 # go get (without -d) should also succeed in either case. [short] skip 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: Go Package Installation with Race Detector DESCRIPTION: Installs Go standard library packages with race detection enabled, specifying a custom package directory. This is useful for managing cached build artifacts. SOURCE: https://github.com/golang/go/blob/go1_15_15/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 ``` -------------------------------- TITLE: Go Build and Execution Workflow DESCRIPTION: This snippet details the process of setting up the Go build cache, compiling a Go program, executing it, and performing verification checks. It includes commands for creating directories, setting environment variables, building the Go executable, copying output files, and comparing results. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/build_dash_x.txt#_snippet_0 LANGUAGE: shell 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 exec 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 and List Commands for VCS Testing DESCRIPTION: Demonstrates fetching a module from a specific version and listing all modules in the current project. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/mod_get_pseudo_other_branch.txt#_snippet_1 LANGUAGE: bash CODE: ``` go get -d vcs-test.golang.org/git/tagtests.git@master go list -m all ``` -------------------------------- TITLE: Go Get - Exclude Imported Test Dependencies DESCRIPTION: Illustrates that 'go get -t' does not consider test dependencies of imported packages, including those imported by tests. This example fetches a package and verifies that its imported test dependencies are not included. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/mod_get_test.txt#_snippet_2 LANGUAGE: bash 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 -d -t m/b ! grep rsc.io/quote go.mod ``` -------------------------------- TITLE: Go Get - Update Imported Test Dependencies DESCRIPTION: Explains that 'go get -t -u' does not add or update test dependencies of imported packages. This example shows fetching a package and verifying that its imported test dependencies are not updated. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/mod_get_test.txt#_snippet_4 LANGUAGE: bash 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 get -d -t -u m/b ! grep rsc.io/quote go.mod go mod edit -require=rsc.io/quote@v1.5.1 go get -d -t -u m/b grep 'rsc.io/quote v1.5.1$' go.mod ``` -------------------------------- TITLE: Basic Go Main Function DESCRIPTION: A minimal Go program with an empty main function. This serves as a starting point for Go applications. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/mod_init_empty.txt#_snippet_4 LANGUAGE: go CODE: ``` package main func main() {} ``` -------------------------------- TITLE: Go Get Path Rejection with Tildes and Digits DESCRIPTION: These examples show `go get` commands that are rejected due to invalid path formats, specifically those ending with a tilde followed by digits, or containing elements that are just a tilde followed by non-digits. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/get_tilde.txt#_snippet_0 LANGUAGE: shell CODE: ``` env GO111MODULE=off # Paths containing windows short names should be rejected before attempting to fetch. ! go get example.com/longna~1.dir/thing stderr 'trailing tilde and digits' ! go get example.com/longna~1/thing stderr 'trailing tilde and digits' ! go get example.com/~9999999/thing stderr 'trailing tilde and digits' ``` -------------------------------- TITLE: Go Module Initialization and Dependency Listing DESCRIPTION: This snippet shows the steps to initialize a Go module and list all project dependencies. It includes setting the GO111MODULE environment variable and executing `go mod init` followed by `go list -m all`. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/mod_convert_godeps.txt#_snippet_0 LANGUAGE: shell CODE: ``` env GO111MODULE=on cd $WORK/test/x ! go list . stderr 'found Godeps/Godeps.json in .*[/\]test' stderr '\s*cd \.\. && go mod init' cd .. go mod init go list -m all stdout '^m$' ``` -------------------------------- TITLE: Running the Test Program DESCRIPTION: Executes the `hello.go` program using the `go run` command to confirm the Go installation. SOURCE: https://github.com/golang/go/blob/go1_15_15/doc/install-source.html#_snippet_7 LANGUAGE: bash CODE: ``` go run hello.go ``` -------------------------------- TITLE: godoc Installation and Usage DESCRIPTION: The godoc webserver is no longer included in the main binary distribution. To run it locally, you need to install it manually using 'go get' and then run the 'godoc' command. SOURCE: https://github.com/golang/go/blob/go1_15_15/doc/go1.13.html#_snippet_14 LANGUAGE: bash CODE: ``` go get golang.org/x/tools/cmd/godoc godoc ``` -------------------------------- TITLE: Go Module Path Resolution Example DESCRIPTION: This example shows the environment variable and command used to build a Go project where the module path is a domain root. It highlights the setup for correct module resolution. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/mod_domain_root.txt#_snippet_0 LANGUAGE: shell CODE: ``` env GO111MODULE=on go build ``` LANGUAGE: go CODE: ``` -- go.mod -- module x -- x.go -- package x import _ "example.com" ``` -------------------------------- TITLE: Preventing Version Downgrade with go get -u DESCRIPTION: This example demonstrates that 'go get -u' does not downgrade a dependency from a pseudo-version to an earlier tag and verifies the go.mod. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/mod_get_upgrade.txt#_snippet_4 LANGUAGE: shell CODE: ``` # get -u should not jump off newer pseudo-version to earlier tag go get -d -u grep 'rsc.io/quote v0.0.0-20180628003336-dd9747d19b04' go.mod ``` -------------------------------- TITLE: Initialize Git Repositories DESCRIPTION: Initializes two empty Git repositories, 'foo' and '{confusing}', sets user information, and creates an initial commit for each. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/get_brace.txt#_snippet_0 LANGUAGE: bash CODE: ``` env GO111MODULE=off [!exec:git] skip # Set up some empty repositories. cd $WORK/_origin/foo exec git init exec git config user.name 'Nameless Gopher' exec git config user.email 'nobody@golang.org' exec git commit --allow-empty -m 'create master branch' cd $WORK cd '_origin/{confusing}' exec git init exec git config user.name 'Nameless Gopher' exec git config user.email 'nobody@golang.org' exec git commit --allow-empty -m 'create master branch' ``` -------------------------------- TITLE: Installing Go Tour Locally DESCRIPTION: Instructions for manually installing and running the Go tour locally, as it is no longer included in the main binary distribution. SOURCE: https://github.com/golang/go/blob/go1_15_15/doc/go1.12.html#_snippet_1 LANGUAGE: go CODE: ``` go get -u golang.org/x/tour tour ``` -------------------------------- TITLE: Go Install Command Usage DESCRIPTION: Demonstrates the usage of the 'go install' command, highlighting its ability to infer package names from directory conventions. SOURCE: https://github.com/golang/go/blob/go1_15_15/doc/articles/go_command.html#_snippet_6 LANGUAGE: go CODE: ``` go install ``` -------------------------------- TITLE: Go Module Initialization and Dependency Fetching DESCRIPTION: This snippet shows how to enable Go modules and fetch external packages. It includes commands to get packages and demonstrates expected error outputs for various malformed archive scenarios. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/mod_bad_filenames.txt#_snippet_0 LANGUAGE: bash CODE: ``` env GO111MODULE=on ! go get rsc.io/badfile1 rsc.io/badfile2 rsc.io/badfile3 rsc.io/badfile4 rsc.io/badfile5 ! stderr 'unzip.*badfile1' stderr 'unzip.*badfile2[\/]@v[\/]v1.0.0.zip:.*malformed file path "☺.go": invalid char ''☺''' stderr 'unzip.*badfile3[\/]@v[\/]v1.0.0.zip: malformed file path "x\?y.go": invalid char ''\?''' stderr 'unzip.*badfile4[\/]@v[\/]v1.0.0.zip: case-insensitive file name collision: "x/Y.go" and "x/y.go"' stderr 'unzip.*badfile5[\/]@v[\/]v1.0.0.zip: case-insensitive file name collision: "x/y" and "x/Y"' ``` -------------------------------- TITLE: Testing 'go get' Binary Deletion DESCRIPTION: Tests that 'go get' does not delete binaries after installation when run from $GOBIN, verifying golang.org/issue/32766. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/mod_get_cmd.txt#_snippet_1 LANGUAGE: shell CODE: ``` # 'go get' should not delete the command when run from $GOPATH/bin cd $GOPATH/bin exists hello$GOEXE go get example.com/tools/cmd/hello exists hello$GOEXE ``` LANGUAGE: shell CODE: ``` # 'go get' should not delete the command when run from a different $GOBIN mkdir $WORK/bin cd $WORK/bin env GOBIN=$WORK/bin go get example.com/tools/cmd/hello exists hello$GOEXE ``` -------------------------------- TITLE: Basic Go Program Structure DESCRIPTION: A minimal Go program demonstrating the 'main' package and the 'main' function, which serves as the entry point for execution. This is the most basic structure for any executable Go application. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/install_relative_gobin_fail.txt#_snippet_1 LANGUAGE: go CODE: ``` package main func main() {} ``` -------------------------------- TITLE: Hello World Program DESCRIPTION: A simple Go program that prints 'hello' to standard output. This is a basic entry point for a Go application. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/mod/example.com_tools_v1.0.0.txt#_snippet_0 LANGUAGE: go CODE: ``` package main import "fmt" func main() { fmt.Println("hello") } ``` -------------------------------- TITLE: Initialization Panic on Missing Environment Variable DESCRIPTION: Shows an example of using `panic` during program initialization if a required environment variable (`USER`) is not set. This indicates a critical setup failure. SOURCE: https://github.com/golang/go/blob/go1_15_15/doc/effective_go.html#_snippet_105 LANGUAGE: go CODE: ``` import ( "os" ) var user = os.Getenv("USER") func init() { if user == "" { panic("no value for $USER") } } ``` -------------------------------- TITLE: Go Hello World Program DESCRIPTION: A minimal Go program that prints the string 'hello, world' to the console. This serves as a fundamental example for beginners. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/run_hello_pkg.txt#_snippet_0 LANGUAGE: go CODE: ``` package main func main() { println("hello, world") } ``` -------------------------------- TITLE: Empty go.mod file content DESCRIPTION: This represents the content of an empty go.mod file, typically used as a starting point for a new Go module. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/mod_gopkg_unstable.txt#_snippet_2 LANGUAGE: go CODE: ``` module m ``` -------------------------------- TITLE: Compiling and Testing Go Packages with Build Tags DESCRIPTION: Demonstrates how to compile a Go package for testing and how to filter tests using build tags. The example shows a test file with a build tag '+build foo' which will only be included when the 'foo' build tag is active. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/test_compile_binary.txt#_snippet_1 LANGUAGE: bash CODE: ``` go test -c compile_binary/... stderr 'build comment' ``` LANGUAGE: go CODE: ``` -- compile_binary/foo_test.go -- // +build foo package foo ``` -------------------------------- TITLE: Build and Execute Utility Programs DESCRIPTION: This snippet demonstrates the process of installing utility programs ('mtime', 'sametime'), executing them to compare file modification times, and capturing the output for verification. It sets up the environment and uses the compiled binaries in a sequence of operations. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/test_race_install_cgo.txt#_snippet_0 LANGUAGE: shell CODE: ``` env GOBIN=$WORK/bin go install mtime sametime go tool -n cgo cp stdout cgopath.txt exec $GOBIN/mtime cgopath.txt # get the mtime of the file whose name is in cgopath.txt cp stdout cgotime_before.txt # For this test, we don't actually care whether 'go test -race -i' succeeds. # It may fail if GOROOT is read-only (perhaps it was installed as root). # We only care that it does not overwrite cmd/cgo regardless. ? go test -race -i runtime/race exec $GOBIN/mtime cgopath.txt # get the mtime of the file whose name is in cgopath.txt cp stdout cgotime_after.txt exec $GOBIN/sametime cgotime_before.txt cgotime_after.txt ``` -------------------------------- TITLE: GCCGO Build and Install Sequence DESCRIPTION: This snippet outlines the typical steps to build and install GCCGO from source, including cloning the repository, configuring the build with specific options, and performing the make and install steps. It highlights the use of the --with-ld option for the gold linker. SOURCE: https://github.com/golang/go/blob/go1_15_15/doc/gccgo_install.html#_snippet_5 LANGUAGE: bash CODE: ``` git clone --branch devel/gccgo git://gcc.gnu.org/git/gcc.git gccgo mkdir objdir cd objdir ../gccgo/configure --prefix=/opt/gccgo --enable-languages=c,c++,go --with-ld=/opt/gold/bin/ld make make install ``` -------------------------------- TITLE: Go Module Content Example DESCRIPTION: Provides the content of a `go.mod.orig` file, which is used in the examples to set up the initial module state. SOURCE: https://github.com/golang/go/blob/go1_15_15/src/cmd/go/testdata/script/mod_get_patterns.txt#_snippet_3 LANGUAGE: go CODE: ``` module m go 1.13 ```