github.com/megatontech/mynoteforgo@v0.0.0-20200507084910-5d0c6ea6e890/源码/cmd/go/alldocs.go (about) 1 // Copyright 2011 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Code generated by mkalldocs.sh; DO NOT EDIT. 6 // Edit the documentation in other files and rerun mkalldocs.sh to generate this one. 7 8 // Go is a tool for managing Go source code. 9 // 10 // Usage: 11 // 12 // go <command> [arguments] 13 // 14 // The commands are: 15 // 16 // bug start a bug report 17 // build compile packages and dependencies 18 // clean remove object files and cached files 19 // doc show documentation for package or symbol 20 // env print Go environment information 21 // fix update packages to use new APIs 22 // fmt gofmt (reformat) package sources 23 // generate generate Go files by processing source 24 // get download and install packages and dependencies 25 // install compile and install packages and dependencies 26 // list list packages or modules 27 // mod module maintenance 28 // run compile and run Go program 29 // test test packages 30 // tool run specified go tool 31 // version print Go version 32 // vet report likely mistakes in packages 33 // 34 // Use "go help <command>" for more information about a command. 35 // 36 // Additional help topics: 37 // 38 // buildmode build modes 39 // c calling between Go and C 40 // cache build and test caching 41 // environment environment variables 42 // filetype file types 43 // go.mod the go.mod file 44 // gopath GOPATH environment variable 45 // gopath-get legacy GOPATH go get 46 // goproxy module proxy protocol 47 // importpath import path syntax 48 // modules modules, module versions, and more 49 // module-get module-aware go get 50 // packages package lists and patterns 51 // testflag testing flags 52 // testfunc testing functions 53 // 54 // Use "go help <topic>" for more information about that topic. 55 // 56 // 57 // Start a bug report 58 // 59 // Usage: 60 // 61 // go bug 62 // 63 // Bug opens the default browser and starts a new bug report. 64 // The report includes useful system information. 65 // 66 // 67 // Compile packages and dependencies 68 // 69 // Usage: 70 // 71 // go build [-o output] [-i] [build flags] [packages] 72 // 73 // Build compiles the packages named by the import paths, 74 // along with their dependencies, but it does not install the results. 75 // 76 // If the arguments to build are a list of .go files, build treats 77 // them as a list of source files specifying a single package. 78 // 79 // When compiling a single main package, build writes 80 // the resulting executable to an output file named after 81 // the first source file ('go build ed.go rx.go' writes 'ed' or 'ed.exe') 82 // or the source code directory ('go build unix/sam' writes 'sam' or 'sam.exe'). 83 // The '.exe' suffix is added when writing a Windows executable. 84 // 85 // When compiling multiple packages or a single non-main package, 86 // build compiles the packages but discards the resulting object, 87 // serving only as a check that the packages can be built. 88 // 89 // When compiling packages, build ignores files that end in '_test.go'. 90 // 91 // The -o flag, only allowed when compiling a single package, 92 // forces build to write the resulting executable or object 93 // to the named output file, instead of the default behavior described 94 // in the last two paragraphs. 95 // 96 // The -i flag installs the packages that are dependencies of the target. 97 // 98 // The build flags are shared by the build, clean, get, install, list, run, 99 // and test commands: 100 // 101 // -a 102 // force rebuilding of packages that are already up-to-date. 103 // -n 104 // print the commands but do not run them. 105 // -p n 106 // the number of programs, such as build commands or 107 // test binaries, that can be run in parallel. 108 // The default is the number of CPUs available. 109 // -race 110 // enable data race detection. 111 // Supported only on linux/amd64, freebsd/amd64, darwin/amd64 and windows/amd64. 112 // -msan 113 // enable interoperation with memory sanitizer. 114 // Supported only on linux/amd64, linux/arm64 115 // and only with Clang/LLVM as the host C compiler. 116 // -v 117 // print the names of packages as they are compiled. 118 // -work 119 // print the name of the temporary work directory and 120 // do not delete it when exiting. 121 // -x 122 // print the commands. 123 // 124 // -asmflags '[pattern=]arg list' 125 // arguments to pass on each go tool asm invocation. 126 // -buildmode mode 127 // build mode to use. See 'go help buildmode' for more. 128 // -compiler name 129 // name of compiler to use, as in runtime.Compiler (gccgo or gc). 130 // -gccgoflags '[pattern=]arg list' 131 // arguments to pass on each gccgo compiler/linker invocation. 132 // -gcflags '[pattern=]arg list' 133 // arguments to pass on each go tool compile invocation. 134 // -installsuffix suffix 135 // a suffix to use in the name of the package installation directory, 136 // in order to keep output separate from default builds. 137 // If using the -race flag, the install suffix is automatically set to race 138 // or, if set explicitly, has _race appended to it. Likewise for the -msan 139 // flag. Using a -buildmode option that requires non-default compile flags 140 // has a similar effect. 141 // -ldflags '[pattern=]arg list' 142 // arguments to pass on each go tool link invocation. 143 // -linkshared 144 // link against shared libraries previously created with 145 // -buildmode=shared. 146 // -mod mode 147 // module download mode to use: readonly or vendor. 148 // See 'go help modules' for more. 149 // -pkgdir dir 150 // install and load all packages from dir instead of the usual locations. 151 // For example, when building with a non-standard configuration, 152 // use -pkgdir to keep generated packages in a separate location. 153 // -tags 'tag list' 154 // a space-separated list of build tags to consider satisfied during the 155 // build. For more information about build tags, see the description of 156 // build constraints in the documentation for the go/build package. 157 // -toolexec 'cmd args' 158 // a program to use to invoke toolchain programs like vet and asm. 159 // For example, instead of running asm, the go command will run 160 // 'cmd args /path/to/asm <arguments for asm>'. 161 // 162 // The -asmflags, -gccgoflags, -gcflags, and -ldflags flags accept a 163 // space-separated list of arguments to pass to an underlying tool 164 // during the build. To embed spaces in an element in the list, surround 165 // it with either single or double quotes. The argument list may be 166 // preceded by a package pattern and an equal sign, which restricts 167 // the use of that argument list to the building of packages matching 168 // that pattern (see 'go help packages' for a description of package 169 // patterns). Without a pattern, the argument list applies only to the 170 // packages named on the command line. The flags may be repeated 171 // with different patterns in order to specify different arguments for 172 // different sets of packages. If a package matches patterns given in 173 // multiple flags, the latest match on the command line wins. 174 // For example, 'go build -gcflags=-S fmt' prints the disassembly 175 // only for package fmt, while 'go build -gcflags=all=-S fmt' 176 // prints the disassembly for fmt and all its dependencies. 177 // 178 // For more about specifying packages, see 'go help packages'. 179 // For more about where packages and binaries are installed, 180 // run 'go help gopath'. 181 // For more about calling between Go and C/C++, run 'go help c'. 182 // 183 // Note: Build adheres to certain conventions such as those described 184 // by 'go help gopath'. Not all projects can follow these conventions, 185 // however. Installations that have their own conventions or that use 186 // a separate software build system may choose to use lower-level 187 // invocations such as 'go tool compile' and 'go tool link' to avoid 188 // some of the overheads and design decisions of the build tool. 189 // 190 // See also: go install, go get, go clean. 191 // 192 // 193 // Remove object files and cached files 194 // 195 // Usage: 196 // 197 // go clean [clean flags] [build flags] [packages] 198 // 199 // Clean removes object files from package source directories. 200 // The go command builds most objects in a temporary directory, 201 // so go clean is mainly concerned with object files left by other 202 // tools or by manual invocations of go build. 203 // 204 // Specifically, clean removes the following files from each of the 205 // source directories corresponding to the import paths: 206 // 207 // _obj/ old object directory, left from Makefiles 208 // _test/ old test directory, left from Makefiles 209 // _testmain.go old gotest file, left from Makefiles 210 // test.out old test log, left from Makefiles 211 // build.out old test log, left from Makefiles 212 // *.[568ao] object files, left from Makefiles 213 // 214 // DIR(.exe) from go build 215 // DIR.test(.exe) from go test -c 216 // MAINFILE(.exe) from go build MAINFILE.go 217 // *.so from SWIG 218 // 219 // In the list, DIR represents the final path element of the 220 // directory, and MAINFILE is the base name of any Go source 221 // file in the directory that is not included when building 222 // the package. 223 // 224 // The -i flag causes clean to remove the corresponding installed 225 // archive or binary (what 'go install' would create). 226 // 227 // The -n flag causes clean to print the remove commands it would execute, 228 // but not run them. 229 // 230 // The -r flag causes clean to be applied recursively to all the 231 // dependencies of the packages named by the import paths. 232 // 233 // The -x flag causes clean to print remove commands as it executes them. 234 // 235 // The -cache flag causes clean to remove the entire go build cache. 236 // 237 // The -testcache flag causes clean to expire all test results in the 238 // go build cache. 239 // 240 // The -modcache flag causes clean to remove the entire module 241 // download cache, including unpacked source code of versioned 242 // dependencies. 243 // 244 // For more about build flags, see 'go help build'. 245 // 246 // For more about specifying packages, see 'go help packages'. 247 // 248 // 249 // Show documentation for package or symbol 250 // 251 // Usage: 252 // 253 // go doc [-u] [-c] [package|[package.]symbol[.methodOrField]] 254 // 255 // Doc prints the documentation comments associated with the item identified by its 256 // arguments (a package, const, func, type, var, method, or struct field) 257 // followed by a one-line summary of each of the first-level items "under" 258 // that item (package-level declarations for a package, methods for a type, 259 // etc.). 260 // 261 // Doc accepts zero, one, or two arguments. 262 // 263 // Given no arguments, that is, when run as 264 // 265 // go doc 266 // 267 // it prints the package documentation for the package in the current directory. 268 // If the package is a command (package main), the exported symbols of the package 269 // are elided from the presentation unless the -cmd flag is provided. 270 // 271 // When run with one argument, the argument is treated as a Go-syntax-like 272 // representation of the item to be documented. What the argument selects depends 273 // on what is installed in GOROOT and GOPATH, as well as the form of the argument, 274 // which is schematically one of these: 275 // 276 // go doc <pkg> 277 // go doc <sym>[.<methodOrField>] 278 // go doc [<pkg>.]<sym>[.<methodOrField>] 279 // go doc [<pkg>.][<sym>.]<methodOrField> 280 // 281 // The first item in this list matched by the argument is the one whose documentation 282 // is printed. (See the examples below.) However, if the argument starts with a capital 283 // letter it is assumed to identify a symbol or method in the current directory. 284 // 285 // For packages, the order of scanning is determined lexically in breadth-first order. 286 // That is, the package presented is the one that matches the search and is nearest 287 // the root and lexically first at its level of the hierarchy. The GOROOT tree is 288 // always scanned in its entirety before GOPATH. 289 // 290 // If there is no package specified or matched, the package in the current 291 // directory is selected, so "go doc Foo" shows the documentation for symbol Foo in 292 // the current package. 293 // 294 // The package path must be either a qualified path or a proper suffix of a 295 // path. The go tool's usual package mechanism does not apply: package path 296 // elements like . and ... are not implemented by go doc. 297 // 298 // When run with two arguments, the first must be a full package path (not just a 299 // suffix), and the second is a symbol, or symbol with method or struct field. 300 // This is similar to the syntax accepted by godoc: 301 // 302 // go doc <pkg> <sym>[.<methodOrField>] 303 // 304 // In all forms, when matching symbols, lower-case letters in the argument match 305 // either case but upper-case letters match exactly. This means that there may be 306 // multiple matches of a lower-case argument in a package if different symbols have 307 // different cases. If this occurs, documentation for all matches is printed. 308 // 309 // Examples: 310 // go doc 311 // Show documentation for current package. 312 // go doc Foo 313 // Show documentation for Foo in the current package. 314 // (Foo starts with a capital letter so it cannot match 315 // a package path.) 316 // go doc encoding/json 317 // Show documentation for the encoding/json package. 318 // go doc json 319 // Shorthand for encoding/json. 320 // go doc json.Number (or go doc json.number) 321 // Show documentation and method summary for json.Number. 322 // go doc json.Number.Int64 (or go doc json.number.int64) 323 // Show documentation for json.Number's Int64 method. 324 // go doc cmd/doc 325 // Show package docs for the doc command. 326 // go doc -cmd cmd/doc 327 // Show package docs and exported symbols within the doc command. 328 // go doc template.new 329 // Show documentation for html/template's New function. 330 // (html/template is lexically before text/template) 331 // go doc text/template.new # One argument 332 // Show documentation for text/template's New function. 333 // go doc text/template new # Two arguments 334 // Show documentation for text/template's New function. 335 // 336 // At least in the current tree, these invocations all print the 337 // documentation for json.Decoder's Decode method: 338 // 339 // go doc json.Decoder.Decode 340 // go doc json.decoder.decode 341 // go doc json.decode 342 // cd go/src/encoding/json; go doc decode 343 // 344 // Flags: 345 // -all 346 // Show all the documentation for the package. 347 // -c 348 // Respect case when matching symbols. 349 // -cmd 350 // Treat a command (package main) like a regular package. 351 // Otherwise package main's exported symbols are hidden 352 // when showing the package's top-level documentation. 353 // -src 354 // Show the full source code for the symbol. This will 355 // display the full Go source of its declaration and 356 // definition, such as a function definition (including 357 // the body), type declaration or enclosing const 358 // block. The output may therefore include unexported 359 // details. 360 // -u 361 // Show documentation for unexported as well as exported 362 // symbols, methods, and fields. 363 // 364 // 365 // Print Go environment information 366 // 367 // Usage: 368 // 369 // go env [-json] [var ...] 370 // 371 // Env prints Go environment information. 372 // 373 // By default env prints information as a shell script 374 // (on Windows, a batch file). If one or more variable 375 // names is given as arguments, env prints the value of 376 // each named variable on its own line. 377 // 378 // The -json flag prints the environment in JSON format 379 // instead of as a shell script. 380 // 381 // For more about environment variables, see 'go help environment'. 382 // 383 // 384 // Update packages to use new APIs 385 // 386 // Usage: 387 // 388 // go fix [packages] 389 // 390 // Fix runs the Go fix command on the packages named by the import paths. 391 // 392 // For more about fix, see 'go doc cmd/fix'. 393 // For more about specifying packages, see 'go help packages'. 394 // 395 // To run fix with specific options, run 'go tool fix'. 396 // 397 // See also: go fmt, go vet. 398 // 399 // 400 // Gofmt (reformat) package sources 401 // 402 // Usage: 403 // 404 // go fmt [-n] [-x] [packages] 405 // 406 // Fmt runs the command 'gofmt -l -w' on the packages named 407 // by the import paths. It prints the names of the files that are modified. 408 // 409 // For more about gofmt, see 'go doc cmd/gofmt'. 410 // For more about specifying packages, see 'go help packages'. 411 // 412 // The -n flag prints commands that would be executed. 413 // The -x flag prints commands as they are executed. 414 // 415 // To run gofmt with specific options, run gofmt itself. 416 // 417 // See also: go fix, go vet. 418 // 419 // 420 // Generate Go files by processing source 421 // 422 // Usage: 423 // 424 // go generate [-run regexp] [-n] [-v] [-x] [build flags] [file.go... | packages] 425 // 426 // Generate runs commands described by directives within existing 427 // files. Those commands can run any process but the intent is to 428 // create or update Go source files. 429 // 430 // Go generate is never run automatically by go build, go get, go test, 431 // and so on. It must be run explicitly. 432 // 433 // Go generate scans the file for directives, which are lines of 434 // the form, 435 // 436 // //go:generate command argument... 437 // 438 // (note: no leading spaces and no space in "//go") where command 439 // is the generator to be run, corresponding to an executable file 440 // that can be run locally. It must either be in the shell path 441 // (gofmt), a fully qualified path (/usr/you/bin/mytool), or a 442 // command alias, described below. 443 // 444 // To convey to humans and machine tools that code is generated, 445 // generated source should have a line that matches the following 446 // regular expression (in Go syntax): 447 // 448 // ^// Code generated .* DO NOT EDIT\.$ 449 // 450 // The line may appear anywhere in the file, but is typically 451 // placed near the beginning so it is easy to find. 452 // 453 // Note that go generate does not parse the file, so lines that look 454 // like directives in comments or multiline strings will be treated 455 // as directives. 456 // 457 // The arguments to the directive are space-separated tokens or 458 // double-quoted strings passed to the generator as individual 459 // arguments when it is run. 460 // 461 // Quoted strings use Go syntax and are evaluated before execution; a 462 // quoted string appears as a single argument to the generator. 463 // 464 // Go generate sets several variables when it runs the generator: 465 // 466 // $GOARCH 467 // The execution architecture (arm, amd64, etc.) 468 // $GOOS 469 // The execution operating system (linux, windows, etc.) 470 // $GOFILE 471 // The base name of the file. 472 // $GOLINE 473 // The line number of the directive in the source file. 474 // $GOPACKAGE 475 // The name of the package of the file containing the directive. 476 // $DOLLAR 477 // A dollar sign. 478 // 479 // Other than variable substitution and quoted-string evaluation, no 480 // special processing such as "globbing" is performed on the command 481 // line. 482 // 483 // As a last step before running the command, any invocations of any 484 // environment variables with alphanumeric names, such as $GOFILE or 485 // $HOME, are expanded throughout the command line. The syntax for 486 // variable expansion is $NAME on all operating systems. Due to the 487 // order of evaluation, variables are expanded even inside quoted 488 // strings. If the variable NAME is not set, $NAME expands to the 489 // empty string. 490 // 491 // A directive of the form, 492 // 493 // //go:generate -command xxx args... 494 // 495 // specifies, for the remainder of this source file only, that the 496 // string xxx represents the command identified by the arguments. This 497 // can be used to create aliases or to handle multiword generators. 498 // For example, 499 // 500 // //go:generate -command foo go tool foo 501 // 502 // specifies that the command "foo" represents the generator 503 // "go tool foo". 504 // 505 // Generate processes packages in the order given on the command line, 506 // one at a time. If the command line lists .go files, they are treated 507 // as a single package. Within a package, generate processes the 508 // source files in a package in file name order, one at a time. Within 509 // a source file, generate runs generators in the order they appear 510 // in the file, one at a time. 511 // 512 // If any generator returns an error exit status, "go generate" skips 513 // all further processing for that package. 514 // 515 // The generator is run in the package's source directory. 516 // 517 // Go generate accepts one specific flag: 518 // 519 // -run="" 520 // if non-empty, specifies a regular expression to select 521 // directives whose full original source text (excluding 522 // any trailing spaces and final newline) matches the 523 // expression. 524 // 525 // It also accepts the standard build flags including -v, -n, and -x. 526 // The -v flag prints the names of packages and files as they are 527 // processed. 528 // The -n flag prints commands that would be executed. 529 // The -x flag prints commands as they are executed. 530 // 531 // For more about build flags, see 'go help build'. 532 // 533 // For more about specifying packages, see 'go help packages'. 534 // 535 // 536 // Download and install packages and dependencies 537 // 538 // Usage: 539 // 540 // go get [-d] [-f] [-t] [-u] [-v] [-fix] [-insecure] [build flags] [packages] 541 // 542 // Get downloads the packages named by the import paths, along with their 543 // dependencies. It then installs the named packages, like 'go install'. 544 // 545 // The -d flag instructs get to stop after downloading the packages; that is, 546 // it instructs get not to install the packages. 547 // 548 // The -f flag, valid only when -u is set, forces get -u not to verify that 549 // each package has been checked out from the source control repository 550 // implied by its import path. This can be useful if the source is a local fork 551 // of the original. 552 // 553 // The -fix flag instructs get to run the fix tool on the downloaded packages 554 // before resolving dependencies or building the code. 555 // 556 // The -insecure flag permits fetching from repositories and resolving 557 // custom domains using insecure schemes such as HTTP. Use with caution. 558 // 559 // The -t flag instructs get to also download the packages required to build 560 // the tests for the specified packages. 561 // 562 // The -u flag instructs get to use the network to update the named packages 563 // and their dependencies. By default, get uses the network to check out 564 // missing packages but does not use it to look for updates to existing packages. 565 // 566 // The -v flag enables verbose progress and debug output. 567 // 568 // Get also accepts build flags to control the installation. See 'go help build'. 569 // 570 // When checking out a new package, get creates the target directory 571 // GOPATH/src/<import-path>. If the GOPATH contains multiple entries, 572 // get uses the first one. For more details see: 'go help gopath'. 573 // 574 // When checking out or updating a package, get looks for a branch or tag 575 // that matches the locally installed version of Go. The most important 576 // rule is that if the local installation is running version "go1", get 577 // searches for a branch or tag named "go1". If no such version exists 578 // it retrieves the default branch of the package. 579 // 580 // When go get checks out or updates a Git repository, 581 // it also updates any git submodules referenced by the repository. 582 // 583 // Get never checks out or updates code stored in vendor directories. 584 // 585 // For more about specifying packages, see 'go help packages'. 586 // 587 // For more about how 'go get' finds source code to 588 // download, see 'go help importpath'. 589 // 590 // This text describes the behavior of get when using GOPATH 591 // to manage source code and dependencies. 592 // If instead the go command is running in module-aware mode, 593 // the details of get's flags and effects change, as does 'go help get'. 594 // See 'go help modules' and 'go help module-get'. 595 // 596 // See also: go build, go install, go clean. 597 // 598 // 599 // Compile and install packages and dependencies 600 // 601 // Usage: 602 // 603 // go install [-i] [build flags] [packages] 604 // 605 // Install compiles and installs the packages named by the import paths. 606 // 607 // The -i flag installs the dependencies of the named packages as well. 608 // 609 // For more about the build flags, see 'go help build'. 610 // For more about specifying packages, see 'go help packages'. 611 // 612 // See also: go build, go get, go clean. 613 // 614 // 615 // List packages or modules 616 // 617 // Usage: 618 // 619 // go list [-f format] [-json] [-m] [list flags] [build flags] [packages] 620 // 621 // List lists the named packages, one per line. 622 // The most commonly-used flags are -f and -json, which control the form 623 // of the output printed for each package. Other list flags, documented below, 624 // control more specific details. 625 // 626 // The default output shows the package import path: 627 // 628 // bytes 629 // encoding/json 630 // github.com/gorilla/mux 631 // golang.org/x/net/html 632 // 633 // The -f flag specifies an alternate format for the list, using the 634 // syntax of package template. The default output is equivalent 635 // to -f '{{.ImportPath}}'. The struct being passed to the template is: 636 // 637 // type Package struct { 638 // Dir string // directory containing package sources 639 // ImportPath string // import path of package in dir 640 // ImportComment string // path in import comment on package statement 641 // Name string // package name 642 // Doc string // package documentation string 643 // Target string // install path 644 // Shlib string // the shared library that contains this package (only set when -linkshared) 645 // Goroot bool // is this package in the Go root? 646 // Standard bool // is this package part of the standard Go library? 647 // Stale bool // would 'go install' do anything for this package? 648 // StaleReason string // explanation for Stale==true 649 // Root string // Go root or Go path dir containing this package 650 // ConflictDir string // this directory shadows Dir in $GOPATH 651 // BinaryOnly bool // binary-only package: cannot be recompiled from sources 652 // ForTest string // package is only for use in named test 653 // Export string // file containing export data (when using -export) 654 // Module *Module // info about package's containing module, if any (can be nil) 655 // Match []string // command-line patterns matching this package 656 // DepOnly bool // package is only a dependency, not explicitly listed 657 // 658 // // Source files 659 // GoFiles []string // .go source files (excluding CgoFiles, TestGoFiles, XTestGoFiles) 660 // CgoFiles []string // .go source files that import "C" 661 // CompiledGoFiles []string // .go files presented to compiler (when using -compiled) 662 // IgnoredGoFiles []string // .go source files ignored due to build constraints 663 // CFiles []string // .c source files 664 // CXXFiles []string // .cc, .cxx and .cpp source files 665 // MFiles []string // .m source files 666 // HFiles []string // .h, .hh, .hpp and .hxx source files 667 // FFiles []string // .f, .F, .for and .f90 Fortran source files 668 // SFiles []string // .s source files 669 // SwigFiles []string // .swig files 670 // SwigCXXFiles []string // .swigcxx files 671 // SysoFiles []string // .syso object files to add to archive 672 // TestGoFiles []string // _test.go files in package 673 // XTestGoFiles []string // _test.go files outside package 674 // 675 // // Cgo directives 676 // CgoCFLAGS []string // cgo: flags for C compiler 677 // CgoCPPFLAGS []string // cgo: flags for C preprocessor 678 // CgoCXXFLAGS []string // cgo: flags for C++ compiler 679 // CgoFFLAGS []string // cgo: flags for Fortran compiler 680 // CgoLDFLAGS []string // cgo: flags for linker 681 // CgoPkgConfig []string // cgo: pkg-config names 682 // 683 // // Dependency information 684 // Imports []string // import paths used by this package 685 // ImportMap map[string]string // map from source import to ImportPath (identity entries omitted) 686 // Deps []string // all (recursively) imported dependencies 687 // TestImports []string // imports from TestGoFiles 688 // XTestImports []string // imports from XTestGoFiles 689 // 690 // // Error information 691 // Incomplete bool // this package or a dependency has an error 692 // Error *PackageError // error loading package 693 // DepsErrors []*PackageError // errors loading dependencies 694 // } 695 // 696 // Packages stored in vendor directories report an ImportPath that includes the 697 // path to the vendor directory (for example, "d/vendor/p" instead of "p"), 698 // so that the ImportPath uniquely identifies a given copy of a package. 699 // The Imports, Deps, TestImports, and XTestImports lists also contain these 700 // expanded import paths. See golang.org/s/go15vendor for more about vendoring. 701 // 702 // The error information, if any, is 703 // 704 // type PackageError struct { 705 // ImportStack []string // shortest path from package named on command line to this one 706 // Pos string // position of error (if present, file:line:col) 707 // Err string // the error itself 708 // } 709 // 710 // The module information is a Module struct, defined in the discussion 711 // of list -m below. 712 // 713 // The template function "join" calls strings.Join. 714 // 715 // The template function "context" returns the build context, defined as: 716 // 717 // type Context struct { 718 // GOARCH string // target architecture 719 // GOOS string // target operating system 720 // GOROOT string // Go root 721 // GOPATH string // Go path 722 // CgoEnabled bool // whether cgo can be used 723 // UseAllFiles bool // use files regardless of +build lines, file names 724 // Compiler string // compiler to assume when computing target paths 725 // BuildTags []string // build constraints to match in +build lines 726 // ReleaseTags []string // releases the current release is compatible with 727 // InstallSuffix string // suffix to use in the name of the install dir 728 // } 729 // 730 // For more information about the meaning of these fields see the documentation 731 // for the go/build package's Context type. 732 // 733 // The -json flag causes the package data to be printed in JSON format 734 // instead of using the template format. 735 // 736 // The -compiled flag causes list to set CompiledGoFiles to the Go source 737 // files presented to the compiler. Typically this means that it repeats 738 // the files listed in GoFiles and then also adds the Go code generated 739 // by processing CgoFiles and SwigFiles. The Imports list contains the 740 // union of all imports from both GoFiles and CompiledGoFiles. 741 // 742 // The -deps flag causes list to iterate over not just the named packages 743 // but also all their dependencies. It visits them in a depth-first post-order 744 // traversal, so that a package is listed only after all its dependencies. 745 // Packages not explicitly listed on the command line will have the DepOnly 746 // field set to true. 747 // 748 // The -e flag changes the handling of erroneous packages, those that 749 // cannot be found or are malformed. By default, the list command 750 // prints an error to standard error for each erroneous package and 751 // omits the packages from consideration during the usual printing. 752 // With the -e flag, the list command never prints errors to standard 753 // error and instead processes the erroneous packages with the usual 754 // printing. Erroneous packages will have a non-empty ImportPath and 755 // a non-nil Error field; other information may or may not be missing 756 // (zeroed). 757 // 758 // The -export flag causes list to set the Export field to the name of a 759 // file containing up-to-date export information for the given package. 760 // 761 // The -find flag causes list to identify the named packages but not 762 // resolve their dependencies: the Imports and Deps lists will be empty. 763 // 764 // The -test flag causes list to report not only the named packages 765 // but also their test binaries (for packages with tests), to convey to 766 // source code analysis tools exactly how test binaries are constructed. 767 // The reported import path for a test binary is the import path of 768 // the package followed by a ".test" suffix, as in "math/rand.test". 769 // When building a test, it is sometimes necessary to rebuild certain 770 // dependencies specially for that test (most commonly the tested 771 // package itself). The reported import path of a package recompiled 772 // for a particular test binary is followed by a space and the name of 773 // the test binary in brackets, as in "math/rand [math/rand.test]" 774 // or "regexp [sort.test]". The ForTest field is also set to the name 775 // of the package being tested ("math/rand" or "sort" in the previous 776 // examples). 777 // 778 // The Dir, Target, Shlib, Root, ConflictDir, and Export file paths 779 // are all absolute paths. 780 // 781 // By default, the lists GoFiles, CgoFiles, and so on hold names of files in Dir 782 // (that is, paths relative to Dir, not absolute paths). 783 // The generated files added when using the -compiled and -test flags 784 // are absolute paths referring to cached copies of generated Go source files. 785 // Although they are Go source files, the paths may not end in ".go". 786 // 787 // The -m flag causes list to list modules instead of packages. 788 // 789 // When listing modules, the -f flag still specifies a format template 790 // applied to a Go struct, but now a Module struct: 791 // 792 // type Module struct { 793 // Path string // module path 794 // Version string // module version 795 // Versions []string // available module versions (with -versions) 796 // Replace *Module // replaced by this module 797 // Time *time.Time // time version was created 798 // Update *Module // available update, if any (with -u) 799 // Main bool // is this the main module? 800 // Indirect bool // is this module only an indirect dependency of main module? 801 // Dir string // directory holding files for this module, if any 802 // GoMod string // path to go.mod file for this module, if any 803 // Error *ModuleError // error loading module 804 // } 805 // 806 // type ModuleError struct { 807 // Err string // the error itself 808 // } 809 // 810 // The default output is to print the module path and then 811 // information about the version and replacement if any. 812 // For example, 'go list -m all' might print: 813 // 814 // my/main/module 815 // golang.org/x/text v0.3.0 => /tmp/text 816 // rsc.io/pdf v0.1.1 817 // 818 // The Module struct has a String method that formats this 819 // line of output, so that the default format is equivalent 820 // to -f '{{.String}}'. 821 // 822 // Note that when a module has been replaced, its Replace field 823 // describes the replacement module, and its Dir field is set to 824 // the replacement's source code, if present. (That is, if Replace 825 // is non-nil, then Dir is set to Replace.Dir, with no access to 826 // the replaced source code.) 827 // 828 // The -u flag adds information about available upgrades. 829 // When the latest version of a given module is newer than 830 // the current one, list -u sets the Module's Update field 831 // to information about the newer module. 832 // The Module's String method indicates an available upgrade by 833 // formatting the newer version in brackets after the current version. 834 // For example, 'go list -m -u all' might print: 835 // 836 // my/main/module 837 // golang.org/x/text v0.3.0 [v0.4.0] => /tmp/text 838 // rsc.io/pdf v0.1.1 [v0.1.2] 839 // 840 // (For tools, 'go list -m -u -json all' may be more convenient to parse.) 841 // 842 // The -versions flag causes list to set the Module's Versions field 843 // to a list of all known versions of that module, ordered according 844 // to semantic versioning, earliest to latest. The flag also changes 845 // the default output format to display the module path followed by the 846 // space-separated version list. 847 // 848 // The arguments to list -m are interpreted as a list of modules, not packages. 849 // The main module is the module containing the current directory. 850 // The active modules are the main module and its dependencies. 851 // With no arguments, list -m shows the main module. 852 // With arguments, list -m shows the modules specified by the arguments. 853 // Any of the active modules can be specified by its module path. 854 // The special pattern "all" specifies all the active modules, first the main 855 // module and then dependencies sorted by module path. 856 // A pattern containing "..." specifies the active modules whose 857 // module paths match the pattern. 858 // A query of the form path@version specifies the result of that query, 859 // which is not limited to active modules. 860 // See 'go help modules' for more about module queries. 861 // 862 // The template function "module" takes a single string argument 863 // that must be a module path or query and returns the specified 864 // module as a Module struct. If an error occurs, the result will 865 // be a Module struct with a non-nil Error field. 866 // 867 // For more about build flags, see 'go help build'. 868 // 869 // For more about specifying packages, see 'go help packages'. 870 // 871 // For more about modules, see 'go help modules'. 872 // 873 // 874 // Module maintenance 875 // 876 // Go mod provides access to operations on modules. 877 // 878 // Note that support for modules is built into all the go commands, 879 // not just 'go mod'. For example, day-to-day adding, removing, upgrading, 880 // and downgrading of dependencies should be done using 'go get'. 881 // See 'go help modules' for an overview of module functionality. 882 // 883 // Usage: 884 // 885 // go mod <command> [arguments] 886 // 887 // The commands are: 888 // 889 // download download modules to local cache 890 // edit edit go.mod from tools or scripts 891 // graph print module requirement graph 892 // init initialize new module in current directory 893 // tidy add missing and remove unused modules 894 // vendor make vendored copy of dependencies 895 // verify verify dependencies have expected content 896 // why explain why packages or modules are needed 897 // 898 // Use "go help mod <command>" for more information about a command. 899 // 900 // Download modules to local cache 901 // 902 // Usage: 903 // 904 // go mod download [-json] [modules] 905 // 906 // Download downloads the named modules, which can be module patterns selecting 907 // dependencies of the main module or module queries of the form path@version. 908 // With no arguments, download applies to all dependencies of the main module. 909 // 910 // The go command will automatically download modules as needed during ordinary 911 // execution. The "go mod download" command is useful mainly for pre-filling 912 // the local cache or to compute the answers for a Go module proxy. 913 // 914 // By default, download reports errors to standard error but is otherwise silent. 915 // The -json flag causes download to print a sequence of JSON objects 916 // to standard output, describing each downloaded module (or failure), 917 // corresponding to this Go struct: 918 // 919 // type Module struct { 920 // Path string // module path 921 // Version string // module version 922 // Error string // error loading module 923 // Info string // absolute path to cached .info file 924 // GoMod string // absolute path to cached .mod file 925 // Zip string // absolute path to cached .zip file 926 // Dir string // absolute path to cached source root directory 927 // Sum string // checksum for path, version (as in go.sum) 928 // GoModSum string // checksum for go.mod (as in go.sum) 929 // } 930 // 931 // See 'go help modules' for more about module queries. 932 // 933 // 934 // Edit go.mod from tools or scripts 935 // 936 // Usage: 937 // 938 // go mod edit [editing flags] [go.mod] 939 // 940 // Edit provides a command-line interface for editing go.mod, 941 // for use primarily by tools or scripts. It reads only go.mod; 942 // it does not look up information about the modules involved. 943 // By default, edit reads and writes the go.mod file of the main module, 944 // but a different target file can be specified after the editing flags. 945 // 946 // The editing flags specify a sequence of editing operations. 947 // 948 // The -fmt flag reformats the go.mod file without making other changes. 949 // This reformatting is also implied by any other modifications that use or 950 // rewrite the go.mod file. The only time this flag is needed is if no other 951 // flags are specified, as in 'go mod edit -fmt'. 952 // 953 // The -module flag changes the module's path (the go.mod file's module line). 954 // 955 // The -require=path@version and -droprequire=path flags 956 // add and drop a requirement on the given module path and version. 957 // Note that -require overrides any existing requirements on path. 958 // These flags are mainly for tools that understand the module graph. 959 // Users should prefer 'go get path@version' or 'go get path@none', 960 // which make other go.mod adjustments as needed to satisfy 961 // constraints imposed by other modules. 962 // 963 // The -exclude=path@version and -dropexclude=path@version flags 964 // add and drop an exclusion for the given module path and version. 965 // Note that -exclude=path@version is a no-op if that exclusion already exists. 966 // 967 // The -replace=old[@v]=new[@v] and -dropreplace=old[@v] flags 968 // add and drop a replacement of the given module path and version pair. 969 // If the @v in old@v is omitted, the replacement applies to all versions 970 // with the old module path. If the @v in new@v is omitted, the new path 971 // should be a local module root directory, not a module path. 972 // Note that -replace overrides any existing replacements for old[@v]. 973 // 974 // The -require, -droprequire, -exclude, -dropexclude, -replace, 975 // and -dropreplace editing flags may be repeated, and the changes 976 // are applied in the order given. 977 // 978 // The -go=version flag sets the expected Go language version. 979 // 980 // The -print flag prints the final go.mod in its text format instead of 981 // writing it back to go.mod. 982 // 983 // The -json flag prints the final go.mod file in JSON format instead of 984 // writing it back to go.mod. The JSON output corresponds to these Go types: 985 // 986 // type Module struct { 987 // Path string 988 // Version string 989 // } 990 // 991 // type GoMod struct { 992 // Module Module 993 // Go string 994 // Require []Require 995 // Exclude []Module 996 // Replace []Replace 997 // } 998 // 999 // type Require struct { 1000 // Path string 1001 // Version string 1002 // Indirect bool 1003 // } 1004 // 1005 // type Replace struct { 1006 // Old Module 1007 // New Module 1008 // } 1009 // 1010 // Note that this only describes the go.mod file itself, not other modules 1011 // referred to indirectly. For the full set of modules available to a build, 1012 // use 'go list -m -json all'. 1013 // 1014 // For example, a tool can obtain the go.mod as a data structure by 1015 // parsing the output of 'go mod edit -json' and can then make changes 1016 // by invoking 'go mod edit' with -require, -exclude, and so on. 1017 // 1018 // 1019 // Print module requirement graph 1020 // 1021 // Usage: 1022 // 1023 // go mod graph 1024 // 1025 // Graph prints the module requirement graph (with replacements applied) 1026 // in text form. Each line in the output has two space-separated fields: a module 1027 // and one of its requirements. Each module is identified as a string of the form 1028 // path@version, except for the main module, which has no @version suffix. 1029 // 1030 // 1031 // Initialize new module in current directory 1032 // 1033 // Usage: 1034 // 1035 // go mod init [module] 1036 // 1037 // Init initializes and writes a new go.mod to the current directory, 1038 // in effect creating a new module rooted at the current directory. 1039 // The file go.mod must not already exist. 1040 // If possible, init will guess the module path from import comments 1041 // (see 'go help importpath') or from version control configuration. 1042 // To override this guess, supply the module path as an argument. 1043 // 1044 // 1045 // Add missing and remove unused modules 1046 // 1047 // Usage: 1048 // 1049 // go mod tidy [-v] 1050 // 1051 // Tidy makes sure go.mod matches the source code in the module. 1052 // It adds any missing modules necessary to build the current module's 1053 // packages and dependencies, and it removes unused modules that 1054 // don't provide any relevant packages. It also adds any missing entries 1055 // to go.sum and removes any unnecessary ones. 1056 // 1057 // The -v flag causes tidy to print information about removed modules 1058 // to standard error. 1059 // 1060 // 1061 // Make vendored copy of dependencies 1062 // 1063 // Usage: 1064 // 1065 // go mod vendor [-v] 1066 // 1067 // Vendor resets the main module's vendor directory to include all packages 1068 // needed to build and test all the main module's packages. 1069 // It does not include test code for vendored packages. 1070 // 1071 // The -v flag causes vendor to print the names of vendored 1072 // modules and packages to standard error. 1073 // 1074 // 1075 // Verify dependencies have expected content 1076 // 1077 // Usage: 1078 // 1079 // go mod verify 1080 // 1081 // Verify checks that the dependencies of the current module, 1082 // which are stored in a local downloaded source cache, have not been 1083 // modified since being downloaded. If all the modules are unmodified, 1084 // verify prints "all modules verified." Otherwise it reports which 1085 // modules have been changed and causes 'go mod' to exit with a 1086 // non-zero status. 1087 // 1088 // 1089 // Explain why packages or modules are needed 1090 // 1091 // Usage: 1092 // 1093 // go mod why [-m] [-vendor] packages... 1094 // 1095 // Why shows a shortest path in the import graph from the main module to 1096 // each of the listed packages. If the -m flag is given, why treats the 1097 // arguments as a list of modules and finds a path to any package in each 1098 // of the modules. 1099 // 1100 // By default, why queries the graph of packages matched by "go list all", 1101 // which includes tests for reachable packages. The -vendor flag causes why 1102 // to exclude tests of dependencies. 1103 // 1104 // The output is a sequence of stanzas, one for each package or module 1105 // name on the command line, separated by blank lines. Each stanza begins 1106 // with a comment line "# package" or "# module" giving the target 1107 // package or module. Subsequent lines give a path through the import 1108 // graph, one package per line. If the package or module is not 1109 // referenced from the main module, the stanza will display a single 1110 // parenthesized note indicating that fact. 1111 // 1112 // For example: 1113 // 1114 // $ go mod why golang.org/x/text/language golang.org/x/text/encoding 1115 // # golang.org/x/text/language 1116 // rsc.io/quote 1117 // rsc.io/sampler 1118 // golang.org/x/text/language 1119 // 1120 // # golang.org/x/text/encoding 1121 // (main module does not need package golang.org/x/text/encoding) 1122 // $ 1123 // 1124 // 1125 // Compile and run Go program 1126 // 1127 // Usage: 1128 // 1129 // go run [build flags] [-exec xprog] package [arguments...] 1130 // 1131 // Run compiles and runs the named main Go package. 1132 // Typically the package is specified as a list of .go source files, 1133 // but it may also be an import path, file system path, or pattern 1134 // matching a single known package, as in 'go run .' or 'go run my/cmd'. 1135 // 1136 // By default, 'go run' runs the compiled binary directly: 'a.out arguments...'. 1137 // If the -exec flag is given, 'go run' invokes the binary using xprog: 1138 // 'xprog a.out arguments...'. 1139 // If the -exec flag is not given, GOOS or GOARCH is different from the system 1140 // default, and a program named go_$GOOS_$GOARCH_exec can be found 1141 // on the current search path, 'go run' invokes the binary using that program, 1142 // for example 'go_nacl_386_exec a.out arguments...'. This allows execution of 1143 // cross-compiled programs when a simulator or other execution method is 1144 // available. 1145 // 1146 // The exit status of Run is not the exit status of the compiled binary. 1147 // 1148 // For more about build flags, see 'go help build'. 1149 // For more about specifying packages, see 'go help packages'. 1150 // 1151 // See also: go build. 1152 // 1153 // 1154 // Test packages 1155 // 1156 // Usage: 1157 // 1158 // go test [build/test flags] [packages] [build/test flags & test binary flags] 1159 // 1160 // 'Go test' automates testing the packages named by the import paths. 1161 // It prints a summary of the test results in the format: 1162 // 1163 // ok archive/tar 0.011s 1164 // FAIL archive/zip 0.022s 1165 // ok compress/gzip 0.033s 1166 // ... 1167 // 1168 // followed by detailed output for each failed package. 1169 // 1170 // 'Go test' recompiles each package along with any files with names matching 1171 // the file pattern "*_test.go". 1172 // These additional files can contain test functions, benchmark functions, and 1173 // example functions. See 'go help testfunc' for more. 1174 // Each listed package causes the execution of a separate test binary. 1175 // Files whose names begin with "_" (including "_test.go") or "." are ignored. 1176 // 1177 // Test files that declare a package with the suffix "_test" will be compiled as a 1178 // separate package, and then linked and run with the main test binary. 1179 // 1180 // The go tool will ignore a directory named "testdata", making it available 1181 // to hold ancillary data needed by the tests. 1182 // 1183 // As part of building a test binary, go test runs go vet on the package 1184 // and its test source files to identify significant problems. If go vet 1185 // finds any problems, go test reports those and does not run the test 1186 // binary. Only a high-confidence subset of the default go vet checks are 1187 // used. That subset is: 'atomic', 'bool', 'buildtags', 'nilfunc', and 1188 // 'printf'. You can see the documentation for these and other vet tests 1189 // via "go doc cmd/vet". To disable the running of go vet, use the 1190 // -vet=off flag. 1191 // 1192 // All test output and summary lines are printed to the go command's 1193 // standard output, even if the test printed them to its own standard 1194 // error. (The go command's standard error is reserved for printing 1195 // errors building the tests.) 1196 // 1197 // Go test runs in two different modes: 1198 // 1199 // The first, called local directory mode, occurs when go test is 1200 // invoked with no package arguments (for example, 'go test' or 'go 1201 // test -v'). In this mode, go test compiles the package sources and 1202 // tests found in the current directory and then runs the resulting 1203 // test binary. In this mode, caching (discussed below) is disabled. 1204 // After the package test finishes, go test prints a summary line 1205 // showing the test status ('ok' or 'FAIL'), package name, and elapsed 1206 // time. 1207 // 1208 // The second, called package list mode, occurs when go test is invoked 1209 // with explicit package arguments (for example 'go test math', 'go 1210 // test ./...', and even 'go test .'). In this mode, go test compiles 1211 // and tests each of the packages listed on the command line. If a 1212 // package test passes, go test prints only the final 'ok' summary 1213 // line. If a package test fails, go test prints the full test output. 1214 // If invoked with the -bench or -v flag, go test prints the full 1215 // output even for passing package tests, in order to display the 1216 // requested benchmark results or verbose logging. 1217 // 1218 // In package list mode only, go test caches successful package test 1219 // results to avoid unnecessary repeated running of tests. When the 1220 // result of a test can be recovered from the cache, go test will 1221 // redisplay the previous output instead of running the test binary 1222 // again. When this happens, go test prints '(cached)' in place of the 1223 // elapsed time in the summary line. 1224 // 1225 // The rule for a match in the cache is that the run involves the same 1226 // test binary and the flags on the command line come entirely from a 1227 // restricted set of 'cacheable' test flags, defined as -cpu, -list, 1228 // -parallel, -run, -short, and -v. If a run of go test has any test 1229 // or non-test flags outside this set, the result is not cached. To 1230 // disable test caching, use any test flag or argument other than the 1231 // cacheable flags. The idiomatic way to disable test caching explicitly 1232 // is to use -count=1. Tests that open files within the package's source 1233 // root (usually $GOPATH) or that consult environment variables only 1234 // match future runs in which the files and environment variables are unchanged. 1235 // A cached test result is treated as executing in no time at all, 1236 // so a successful package test result will be cached and reused 1237 // regardless of -timeout setting. 1238 // 1239 // In addition to the build flags, the flags handled by 'go test' itself are: 1240 // 1241 // -args 1242 // Pass the remainder of the command line (everything after -args) 1243 // to the test binary, uninterpreted and unchanged. 1244 // Because this flag consumes the remainder of the command line, 1245 // the package list (if present) must appear before this flag. 1246 // 1247 // -c 1248 // Compile the test binary to pkg.test but do not run it 1249 // (where pkg is the last element of the package's import path). 1250 // The file name can be changed with the -o flag. 1251 // 1252 // -exec xprog 1253 // Run the test binary using xprog. The behavior is the same as 1254 // in 'go run'. See 'go help run' for details. 1255 // 1256 // -i 1257 // Install packages that are dependencies of the test. 1258 // Do not run the test. 1259 // 1260 // -json 1261 // Convert test output to JSON suitable for automated processing. 1262 // See 'go doc test2json' for the encoding details. 1263 // 1264 // -o file 1265 // Compile the test binary to the named file. 1266 // The test still runs (unless -c or -i is specified). 1267 // 1268 // The test binary also accepts flags that control execution of the test; these 1269 // flags are also accessible by 'go test'. See 'go help testflag' for details. 1270 // 1271 // For more about build flags, see 'go help build'. 1272 // For more about specifying packages, see 'go help packages'. 1273 // 1274 // See also: go build, go vet. 1275 // 1276 // 1277 // Run specified go tool 1278 // 1279 // Usage: 1280 // 1281 // go tool [-n] command [args...] 1282 // 1283 // Tool runs the go tool command identified by the arguments. 1284 // With no arguments it prints the list of known tools. 1285 // 1286 // The -n flag causes tool to print the command that would be 1287 // executed but not execute it. 1288 // 1289 // For more about each tool command, see 'go doc cmd/<command>'. 1290 // 1291 // 1292 // Print Go version 1293 // 1294 // Usage: 1295 // 1296 // go version 1297 // 1298 // Version prints the Go version, as reported by runtime.Version. 1299 // 1300 // 1301 // Report likely mistakes in packages 1302 // 1303 // Usage: 1304 // 1305 // go vet [-n] [-x] [-vettool prog] [build flags] [vet flags] [packages] 1306 // 1307 // Vet runs the Go vet command on the packages named by the import paths. 1308 // 1309 // For more about vet and its flags, see 'go doc cmd/vet'. 1310 // For more about specifying packages, see 'go help packages'. 1311 // For a list of checkers and their flags, see 'go tool vet help'. 1312 // For details of a specific checker such as 'printf', see 'go tool vet help printf'. 1313 // 1314 // The -n flag prints commands that would be executed. 1315 // The -x flag prints commands as they are executed. 1316 // 1317 // The -vettool=prog flag selects a different analysis tool with alternative 1318 // or additional checks. 1319 // For example, the 'shadow' analyzer can be built and run using these commands: 1320 // 1321 // go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow 1322 // go vet -vettool=$(which shadow) 1323 // 1324 // The build flags supported by go vet are those that control package resolution 1325 // and execution, such as -n, -x, -v, -tags, and -toolexec. 1326 // For more about these flags, see 'go help build'. 1327 // 1328 // See also: go fmt, go fix. 1329 // 1330 // 1331 // Build modes 1332 // 1333 // The 'go build' and 'go install' commands take a -buildmode argument which 1334 // indicates which kind of object file is to be built. Currently supported values 1335 // are: 1336 // 1337 // -buildmode=archive 1338 // Build the listed non-main packages into .a files. Packages named 1339 // main are ignored. 1340 // 1341 // -buildmode=c-archive 1342 // Build the listed main package, plus all packages it imports, 1343 // into a C archive file. The only callable symbols will be those 1344 // functions exported using a cgo //export comment. Requires 1345 // exactly one main package to be listed. 1346 // 1347 // -buildmode=c-shared 1348 // Build the listed main package, plus all packages it imports, 1349 // into a C shared library. The only callable symbols will 1350 // be those functions exported using a cgo //export comment. 1351 // Requires exactly one main package to be listed. 1352 // 1353 // -buildmode=default 1354 // Listed main packages are built into executables and listed 1355 // non-main packages are built into .a files (the default 1356 // behavior). 1357 // 1358 // -buildmode=shared 1359 // Combine all the listed non-main packages into a single shared 1360 // library that will be used when building with the -linkshared 1361 // option. Packages named main are ignored. 1362 // 1363 // -buildmode=exe 1364 // Build the listed main packages and everything they import into 1365 // executables. Packages not named main are ignored. 1366 // 1367 // -buildmode=pie 1368 // Build the listed main packages and everything they import into 1369 // position independent executables (PIE). Packages not named 1370 // main are ignored. 1371 // 1372 // -buildmode=plugin 1373 // Build the listed main packages, plus all packages that they 1374 // import, into a Go plugin. Packages not named main are ignored. 1375 // 1376 // 1377 // Calling between Go and C 1378 // 1379 // There are two different ways to call between Go and C/C++ code. 1380 // 1381 // The first is the cgo tool, which is part of the Go distribution. For 1382 // information on how to use it see the cgo documentation (go doc cmd/cgo). 1383 // 1384 // The second is the SWIG program, which is a general tool for 1385 // interfacing between languages. For information on SWIG see 1386 // http://swig.org/. When running go build, any file with a .swig 1387 // extension will be passed to SWIG. Any file with a .swigcxx extension 1388 // will be passed to SWIG with the -c++ option. 1389 // 1390 // When either cgo or SWIG is used, go build will pass any .c, .m, .s, 1391 // or .S files to the C compiler, and any .cc, .cpp, .cxx files to the C++ 1392 // compiler. The CC or CXX environment variables may be set to determine 1393 // the C or C++ compiler, respectively, to use. 1394 // 1395 // 1396 // Build and test caching 1397 // 1398 // The go command caches build outputs for reuse in future builds. 1399 // The default location for cache data is a subdirectory named go-build 1400 // in the standard user cache directory for the current operating system. 1401 // Setting the GOCACHE environment variable overrides this default, 1402 // and running 'go env GOCACHE' prints the current cache directory. 1403 // 1404 // The go command periodically deletes cached data that has not been 1405 // used recently. Running 'go clean -cache' deletes all cached data. 1406 // 1407 // The build cache correctly accounts for changes to Go source files, 1408 // compilers, compiler options, and so on: cleaning the cache explicitly 1409 // should not be necessary in typical use. However, the build cache 1410 // does not detect changes to C libraries imported with cgo. 1411 // If you have made changes to the C libraries on your system, you 1412 // will need to clean the cache explicitly or else use the -a build flag 1413 // (see 'go help build') to force rebuilding of packages that 1414 // depend on the updated C libraries. 1415 // 1416 // The go command also caches successful package test results. 1417 // See 'go help test' for details. Running 'go clean -testcache' removes 1418 // all cached test results (but not cached build results). 1419 // 1420 // The GODEBUG environment variable can enable printing of debugging 1421 // information about the state of the cache: 1422 // 1423 // GODEBUG=gocacheverify=1 causes the go command to bypass the 1424 // use of any cache entries and instead rebuild everything and check 1425 // that the results match existing cache entries. 1426 // 1427 // GODEBUG=gocachehash=1 causes the go command to print the inputs 1428 // for all of the content hashes it uses to construct cache lookup keys. 1429 // The output is voluminous but can be useful for debugging the cache. 1430 // 1431 // GODEBUG=gocachetest=1 causes the go command to print details of its 1432 // decisions about whether to reuse a cached test result. 1433 // 1434 // 1435 // Environment variables 1436 // 1437 // The go command, and the tools it invokes, examine a few different 1438 // environment variables. For many of these, you can see the default 1439 // value of on your system by running 'go env NAME', where NAME is the 1440 // name of the variable. 1441 // 1442 // General-purpose environment variables: 1443 // 1444 // GCCGO 1445 // The gccgo command to run for 'go build -compiler=gccgo'. 1446 // GOARCH 1447 // The architecture, or processor, for which to compile code. 1448 // Examples are amd64, 386, arm, ppc64. 1449 // GOBIN 1450 // The directory where 'go install' will install a command. 1451 // GOCACHE 1452 // The directory where the go command will store cached 1453 // information for reuse in future builds. 1454 // GOFLAGS 1455 // A space-separated list of -flag=value settings to apply 1456 // to go commands by default, when the given flag is known by 1457 // the current command. Flags listed on the command-line 1458 // are applied after this list and therefore override it. 1459 // GOOS 1460 // The operating system for which to compile code. 1461 // Examples are linux, darwin, windows, netbsd. 1462 // GOPATH 1463 // For more details see: 'go help gopath'. 1464 // GOPROXY 1465 // URL of Go module proxy. See 'go help goproxy'. 1466 // GORACE 1467 // Options for the race detector. 1468 // See https://golang.org/doc/articles/race_detector.html. 1469 // GOROOT 1470 // The root of the go tree. 1471 // GOTMPDIR 1472 // The directory where the go command will write 1473 // temporary source files, packages, and binaries. 1474 // 1475 // Each entry in the GOFLAGS list must be a standalone flag. 1476 // Because the entries are space-separated, flag values must 1477 // not contain spaces. 1478 // 1479 // Environment variables for use with cgo: 1480 // 1481 // CC 1482 // The command to use to compile C code. 1483 // CGO_ENABLED 1484 // Whether the cgo command is supported. Either 0 or 1. 1485 // CGO_CFLAGS 1486 // Flags that cgo will pass to the compiler when compiling 1487 // C code. 1488 // CGO_CFLAGS_ALLOW 1489 // A regular expression specifying additional flags to allow 1490 // to appear in #cgo CFLAGS source code directives. 1491 // Does not apply to the CGO_CFLAGS environment variable. 1492 // CGO_CFLAGS_DISALLOW 1493 // A regular expression specifying flags that must be disallowed 1494 // from appearing in #cgo CFLAGS source code directives. 1495 // Does not apply to the CGO_CFLAGS environment variable. 1496 // CGO_CPPFLAGS, CGO_CPPFLAGS_ALLOW, CGO_CPPFLAGS_DISALLOW 1497 // Like CGO_CFLAGS, CGO_CFLAGS_ALLOW, and CGO_CFLAGS_DISALLOW, 1498 // but for the C preprocessor. 1499 // CGO_CXXFLAGS, CGO_CXXFLAGS_ALLOW, CGO_CXXFLAGS_DISALLOW 1500 // Like CGO_CFLAGS, CGO_CFLAGS_ALLOW, and CGO_CFLAGS_DISALLOW, 1501 // but for the C++ compiler. 1502 // CGO_FFLAGS, CGO_FFLAGS_ALLOW, CGO_FFLAGS_DISALLOW 1503 // Like CGO_CFLAGS, CGO_CFLAGS_ALLOW, and CGO_CFLAGS_DISALLOW, 1504 // but for the Fortran compiler. 1505 // CGO_LDFLAGS, CGO_LDFLAGS_ALLOW, CGO_LDFLAGS_DISALLOW 1506 // Like CGO_CFLAGS, CGO_CFLAGS_ALLOW, and CGO_CFLAGS_DISALLOW, 1507 // but for the linker. 1508 // CXX 1509 // The command to use to compile C++ code. 1510 // PKG_CONFIG 1511 // Path to pkg-config tool. 1512 // AR 1513 // The command to use to manipulate library archives when 1514 // building with the gccgo compiler. 1515 // The default is 'ar'. 1516 // 1517 // Architecture-specific environment variables: 1518 // 1519 // GOARM 1520 // For GOARCH=arm, the ARM architecture for which to compile. 1521 // Valid values are 5, 6, 7. 1522 // GO386 1523 // For GOARCH=386, the floating point instruction set. 1524 // Valid values are 387, sse2. 1525 // GOMIPS 1526 // For GOARCH=mips{,le}, whether to use floating point instructions. 1527 // Valid values are hardfloat (default), softfloat. 1528 // GOMIPS64 1529 // For GOARCH=mips64{,le}, whether to use floating point instructions. 1530 // Valid values are hardfloat (default), softfloat. 1531 // 1532 // Special-purpose environment variables: 1533 // 1534 // GCCGOTOOLDIR 1535 // If set, where to find gccgo tools, such as cgo. 1536 // The default is based on how gccgo was configured. 1537 // GOROOT_FINAL 1538 // The root of the installed Go tree, when it is 1539 // installed in a location other than where it is built. 1540 // File names in stack traces are rewritten from GOROOT to 1541 // GOROOT_FINAL. 1542 // GO_EXTLINK_ENABLED 1543 // Whether the linker should use external linking mode 1544 // when using -linkmode=auto with code that uses cgo. 1545 // Set to 0 to disable external linking mode, 1 to enable it. 1546 // GIT_ALLOW_PROTOCOL 1547 // Defined by Git. A colon-separated list of schemes that are allowed to be used 1548 // with git fetch/clone. If set, any scheme not explicitly mentioned will be 1549 // considered insecure by 'go get'. 1550 // 1551 // Additional information available from 'go env' but not read from the environment: 1552 // 1553 // GOEXE 1554 // The executable file name suffix (".exe" on Windows, "" on other systems). 1555 // GOHOSTARCH 1556 // The architecture (GOARCH) of the Go toolchain binaries. 1557 // GOHOSTOS 1558 // The operating system (GOOS) of the Go toolchain binaries. 1559 // GOMOD 1560 // The absolute path to the go.mod of the main module, 1561 // or the empty string if not using modules. 1562 // GOTOOLDIR 1563 // The directory where the go tools (compile, cover, doc, etc...) are installed. 1564 // 1565 // 1566 // File types 1567 // 1568 // The go command examines the contents of a restricted set of files 1569 // in each directory. It identifies which files to examine based on 1570 // the extension of the file name. These extensions are: 1571 // 1572 // .go 1573 // Go source files. 1574 // .c, .h 1575 // C source files. 1576 // If the package uses cgo or SWIG, these will be compiled with the 1577 // OS-native compiler (typically gcc); otherwise they will 1578 // trigger an error. 1579 // .cc, .cpp, .cxx, .hh, .hpp, .hxx 1580 // C++ source files. Only useful with cgo or SWIG, and always 1581 // compiled with the OS-native compiler. 1582 // .m 1583 // Objective-C source files. Only useful with cgo, and always 1584 // compiled with the OS-native compiler. 1585 // .s, .S 1586 // Assembler source files. 1587 // If the package uses cgo or SWIG, these will be assembled with the 1588 // OS-native assembler (typically gcc (sic)); otherwise they 1589 // will be assembled with the Go assembler. 1590 // .swig, .swigcxx 1591 // SWIG definition files. 1592 // .syso 1593 // System object files. 1594 // 1595 // Files of each of these types except .syso may contain build 1596 // constraints, but the go command stops scanning for build constraints 1597 // at the first item in the file that is not a blank line or //-style 1598 // line comment. See the go/build package documentation for 1599 // more details. 1600 // 1601 // Through the Go 1.12 release, non-test Go source files can also include 1602 // a //go:binary-only-package comment, indicating that the package 1603 // sources are included for documentation only and must not be used to 1604 // build the package binary. This enables distribution of Go packages in 1605 // their compiled form alone. Even binary-only packages require accurate 1606 // import blocks listing required dependencies, so that those 1607 // dependencies can be supplied when linking the resulting command. 1608 // Note that this feature is scheduled to be removed after the Go 1.12 release. 1609 // 1610 // 1611 // The go.mod file 1612 // 1613 // A module version is defined by a tree of source files, with a go.mod 1614 // file in its root. When the go command is run, it looks in the current 1615 // directory and then successive parent directories to find the go.mod 1616 // marking the root of the main (current) module. 1617 // 1618 // The go.mod file itself is line-oriented, with // comments but 1619 // no /* */ comments. Each line holds a single directive, made up of a 1620 // verb followed by arguments. For example: 1621 // 1622 // module my/thing 1623 // go 1.12 1624 // require other/thing v1.0.2 1625 // require new/thing/v2 v2.3.4 1626 // exclude old/thing v1.2.3 1627 // replace bad/thing v1.4.5 => good/thing v1.4.5 1628 // 1629 // The verbs are 1630 // module, to define the module path; 1631 // go, to set the expected language version; 1632 // require, to require a particular module at a given version or later; 1633 // exclude, to exclude a particular module version from use; and 1634 // replace, to replace a module version with a different module version. 1635 // Exclude and replace apply only in the main module's go.mod and are ignored 1636 // in dependencies. See https://research.swtch.com/vgo-mvs for details. 1637 // 1638 // The leading verb can be factored out of adjacent lines to create a block, 1639 // like in Go imports: 1640 // 1641 // require ( 1642 // new/thing v2.3.4 1643 // old/thing v1.2.3 1644 // ) 1645 // 1646 // The go.mod file is designed both to be edited directly and to be 1647 // easily updated by tools. The 'go mod edit' command can be used to 1648 // parse and edit the go.mod file from programs and tools. 1649 // See 'go help mod edit'. 1650 // 1651 // The go command automatically updates go.mod each time it uses the 1652 // module graph, to make sure go.mod always accurately reflects reality 1653 // and is properly formatted. For example, consider this go.mod file: 1654 // 1655 // module M 1656 // 1657 // require ( 1658 // A v1 1659 // B v1.0.0 1660 // C v1.0.0 1661 // D v1.2.3 1662 // E dev 1663 // ) 1664 // 1665 // exclude D v1.2.3 1666 // 1667 // The update rewrites non-canonical version identifiers to semver form, 1668 // so A's v1 becomes v1.0.0 and E's dev becomes the pseudo-version for the 1669 // latest commit on the dev branch, perhaps v0.0.0-20180523231146-b3f5c0f6e5f1. 1670 // 1671 // The update modifies requirements to respect exclusions, so the 1672 // requirement on the excluded D v1.2.3 is updated to use the next 1673 // available version of D, perhaps D v1.2.4 or D v1.3.0. 1674 // 1675 // The update removes redundant or misleading requirements. 1676 // For example, if A v1.0.0 itself requires B v1.2.0 and C v1.0.0, 1677 // then go.mod's requirement of B v1.0.0 is misleading (superseded by 1678 // A's need for v1.2.0), and its requirement of C v1.0.0 is redundant 1679 // (implied by A's need for the same version), so both will be removed. 1680 // If module M contains packages that directly import packages from B or 1681 // C, then the requirements will be kept but updated to the actual 1682 // versions being used. 1683 // 1684 // Finally, the update reformats the go.mod in a canonical formatting, so 1685 // that future mechanical changes will result in minimal diffs. 1686 // 1687 // Because the module graph defines the meaning of import statements, any 1688 // commands that load packages also use and therefore update go.mod, 1689 // including go build, go get, go install, go list, go test, go mod graph, 1690 // go mod tidy, and go mod why. 1691 // 1692 // 1693 // GOPATH environment variable 1694 // 1695 // The Go path is used to resolve import statements. 1696 // It is implemented by and documented in the go/build package. 1697 // 1698 // The GOPATH environment variable lists places to look for Go code. 1699 // On Unix, the value is a colon-separated string. 1700 // On Windows, the value is a semicolon-separated string. 1701 // On Plan 9, the value is a list. 1702 // 1703 // If the environment variable is unset, GOPATH defaults 1704 // to a subdirectory named "go" in the user's home directory 1705 // ($HOME/go on Unix, %USERPROFILE%\go on Windows), 1706 // unless that directory holds a Go distribution. 1707 // Run "go env GOPATH" to see the current GOPATH. 1708 // 1709 // See https://golang.org/wiki/SettingGOPATH to set a custom GOPATH. 1710 // 1711 // Each directory listed in GOPATH must have a prescribed structure: 1712 // 1713 // The src directory holds source code. The path below src 1714 // determines the import path or executable name. 1715 // 1716 // The pkg directory holds installed package objects. 1717 // As in the Go tree, each target operating system and 1718 // architecture pair has its own subdirectory of pkg 1719 // (pkg/GOOS_GOARCH). 1720 // 1721 // If DIR is a directory listed in the GOPATH, a package with 1722 // source in DIR/src/foo/bar can be imported as "foo/bar" and 1723 // has its compiled form installed to "DIR/pkg/GOOS_GOARCH/foo/bar.a". 1724 // 1725 // The bin directory holds compiled commands. 1726 // Each command is named for its source directory, but only 1727 // the final element, not the entire path. That is, the 1728 // command with source in DIR/src/foo/quux is installed into 1729 // DIR/bin/quux, not DIR/bin/foo/quux. The "foo/" prefix is stripped 1730 // so that you can add DIR/bin to your PATH to get at the 1731 // installed commands. If the GOBIN environment variable is 1732 // set, commands are installed to the directory it names instead 1733 // of DIR/bin. GOBIN must be an absolute path. 1734 // 1735 // Here's an example directory layout: 1736 // 1737 // GOPATH=/home/user/go 1738 // 1739 // /home/user/go/ 1740 // src/ 1741 // foo/ 1742 // bar/ (go code in package bar) 1743 // x.go 1744 // quux/ (go code in package main) 1745 // y.go 1746 // bin/ 1747 // quux (installed command) 1748 // pkg/ 1749 // linux_amd64/ 1750 // foo/ 1751 // bar.a (installed package object) 1752 // 1753 // Go searches each directory listed in GOPATH to find source code, 1754 // but new packages are always downloaded into the first directory 1755 // in the list. 1756 // 1757 // See https://golang.org/doc/code.html for an example. 1758 // 1759 // GOPATH and Modules 1760 // 1761 // When using modules, GOPATH is no longer used for resolving imports. 1762 // However, it is still used to store downloaded source code (in GOPATH/pkg/mod) 1763 // and compiled commands (in GOPATH/bin). 1764 // 1765 // Internal Directories 1766 // 1767 // Code in or below a directory named "internal" is importable only 1768 // by code in the directory tree rooted at the parent of "internal". 1769 // Here's an extended version of the directory layout above: 1770 // 1771 // /home/user/go/ 1772 // src/ 1773 // crash/ 1774 // bang/ (go code in package bang) 1775 // b.go 1776 // foo/ (go code in package foo) 1777 // f.go 1778 // bar/ (go code in package bar) 1779 // x.go 1780 // internal/ 1781 // baz/ (go code in package baz) 1782 // z.go 1783 // quux/ (go code in package main) 1784 // y.go 1785 // 1786 // 1787 // The code in z.go is imported as "foo/internal/baz", but that 1788 // import statement can only appear in source files in the subtree 1789 // rooted at foo. The source files foo/f.go, foo/bar/x.go, and 1790 // foo/quux/y.go can all import "foo/internal/baz", but the source file 1791 // crash/bang/b.go cannot. 1792 // 1793 // See https://golang.org/s/go14internal for details. 1794 // 1795 // Vendor Directories 1796 // 1797 // Go 1.6 includes support for using local copies of external dependencies 1798 // to satisfy imports of those dependencies, often referred to as vendoring. 1799 // 1800 // Code below a directory named "vendor" is importable only 1801 // by code in the directory tree rooted at the parent of "vendor", 1802 // and only using an import path that omits the prefix up to and 1803 // including the vendor element. 1804 // 1805 // Here's the example from the previous section, 1806 // but with the "internal" directory renamed to "vendor" 1807 // and a new foo/vendor/crash/bang directory added: 1808 // 1809 // /home/user/go/ 1810 // src/ 1811 // crash/ 1812 // bang/ (go code in package bang) 1813 // b.go 1814 // foo/ (go code in package foo) 1815 // f.go 1816 // bar/ (go code in package bar) 1817 // x.go 1818 // vendor/ 1819 // crash/ 1820 // bang/ (go code in package bang) 1821 // b.go 1822 // baz/ (go code in package baz) 1823 // z.go 1824 // quux/ (go code in package main) 1825 // y.go 1826 // 1827 // The same visibility rules apply as for internal, but the code 1828 // in z.go is imported as "baz", not as "foo/vendor/baz". 1829 // 1830 // Code in vendor directories deeper in the source tree shadows 1831 // code in higher directories. Within the subtree rooted at foo, an import 1832 // of "crash/bang" resolves to "foo/vendor/crash/bang", not the 1833 // top-level "crash/bang". 1834 // 1835 // Code in vendor directories is not subject to import path 1836 // checking (see 'go help importpath'). 1837 // 1838 // When 'go get' checks out or updates a git repository, it now also 1839 // updates submodules. 1840 // 1841 // Vendor directories do not affect the placement of new repositories 1842 // being checked out for the first time by 'go get': those are always 1843 // placed in the main GOPATH, never in a vendor subtree. 1844 // 1845 // See https://golang.org/s/go15vendor for details. 1846 // 1847 // 1848 // Module proxy protocol 1849 // 1850 // The go command by default downloads modules from version control systems 1851 // directly, just as 'go get' always has. The GOPROXY environment variable allows 1852 // further control over the download source. If GOPROXY is unset, is the empty string, 1853 // or is the string "direct", downloads use the default direct connection to version 1854 // control systems. Setting GOPROXY to "off" disallows downloading modules from 1855 // any source. Otherwise, GOPROXY is expected to be the URL of a module proxy, 1856 // in which case the go command will fetch all modules from that proxy. 1857 // No matter the source of the modules, downloaded modules must match existing 1858 // entries in go.sum (see 'go help modules' for discussion of verification). 1859 // 1860 // A Go module proxy is any web server that can respond to GET requests for 1861 // URLs of a specified form. The requests have no query parameters, so even 1862 // a site serving from a fixed file system (including a file:/// URL) 1863 // can be a module proxy. 1864 // 1865 // The GET requests sent to a Go module proxy are: 1866 // 1867 // GET $GOPROXY/<module>/@v/list returns a list of all known versions of the 1868 // given module, one per line. 1869 // 1870 // GET $GOPROXY/<module>/@v/<version>.info returns JSON-formatted metadata 1871 // about that version of the given module. 1872 // 1873 // GET $GOPROXY/<module>/@v/<version>.mod returns the go.mod file 1874 // for that version of the given module. 1875 // 1876 // GET $GOPROXY/<module>/@v/<version>.zip returns the zip archive 1877 // for that version of the given module. 1878 // 1879 // To avoid problems when serving from case-sensitive file systems, 1880 // the <module> and <version> elements are case-encoded, replacing every 1881 // uppercase letter with an exclamation mark followed by the corresponding 1882 // lower-case letter: github.com/Azure encodes as github.com/!azure. 1883 // 1884 // The JSON-formatted metadata about a given module corresponds to 1885 // this Go data structure, which may be expanded in the future: 1886 // 1887 // type Info struct { 1888 // Version string // version string 1889 // Time time.Time // commit time 1890 // } 1891 // 1892 // The zip archive for a specific version of a given module is a 1893 // standard zip file that contains the file tree corresponding 1894 // to the module's source code and related files. The archive uses 1895 // slash-separated paths, and every file path in the archive must 1896 // begin with <module>@<version>/, where the module and version are 1897 // substituted directly, not case-encoded. The root of the module 1898 // file tree corresponds to the <module>@<version>/ prefix in the 1899 // archive. 1900 // 1901 // Even when downloading directly from version control systems, 1902 // the go command synthesizes explicit info, mod, and zip files 1903 // and stores them in its local cache, $GOPATH/pkg/mod/cache/download, 1904 // the same as if it had downloaded them directly from a proxy. 1905 // The cache layout is the same as the proxy URL space, so 1906 // serving $GOPATH/pkg/mod/cache/download at (or copying it to) 1907 // https://example.com/proxy would let other users access those 1908 // cached module versions with GOPROXY=https://example.com/proxy. 1909 // 1910 // 1911 // Import path syntax 1912 // 1913 // An import path (see 'go help packages') denotes a package stored in the local 1914 // file system. In general, an import path denotes either a standard package (such 1915 // as "unicode/utf8") or a package found in one of the work spaces (For more 1916 // details see: 'go help gopath'). 1917 // 1918 // Relative import paths 1919 // 1920 // An import path beginning with ./ or ../ is called a relative path. 1921 // The toolchain supports relative import paths as a shortcut in two ways. 1922 // 1923 // First, a relative path can be used as a shorthand on the command line. 1924 // If you are working in the directory containing the code imported as 1925 // "unicode" and want to run the tests for "unicode/utf8", you can type 1926 // "go test ./utf8" instead of needing to specify the full path. 1927 // Similarly, in the reverse situation, "go test .." will test "unicode" from 1928 // the "unicode/utf8" directory. Relative patterns are also allowed, like 1929 // "go test ./..." to test all subdirectories. See 'go help packages' for details 1930 // on the pattern syntax. 1931 // 1932 // Second, if you are compiling a Go program not in a work space, 1933 // you can use a relative path in an import statement in that program 1934 // to refer to nearby code also not in a work space. 1935 // This makes it easy to experiment with small multipackage programs 1936 // outside of the usual work spaces, but such programs cannot be 1937 // installed with "go install" (there is no work space in which to install them), 1938 // so they are rebuilt from scratch each time they are built. 1939 // To avoid ambiguity, Go programs cannot use relative import paths 1940 // within a work space. 1941 // 1942 // Remote import paths 1943 // 1944 // Certain import paths also 1945 // describe how to obtain the source code for the package using 1946 // a revision control system. 1947 // 1948 // A few common code hosting sites have special syntax: 1949 // 1950 // Bitbucket (Git, Mercurial) 1951 // 1952 // import "bitbucket.org/user/project" 1953 // import "bitbucket.org/user/project/sub/directory" 1954 // 1955 // GitHub (Git) 1956 // 1957 // import "github.com/user/project" 1958 // import "github.com/user/project/sub/directory" 1959 // 1960 // Launchpad (Bazaar) 1961 // 1962 // import "launchpad.net/project" 1963 // import "launchpad.net/project/series" 1964 // import "launchpad.net/project/series/sub/directory" 1965 // 1966 // import "launchpad.net/~user/project/branch" 1967 // import "launchpad.net/~user/project/branch/sub/directory" 1968 // 1969 // IBM DevOps Services (Git) 1970 // 1971 // import "hub.jazz.net/git/user/project" 1972 // import "hub.jazz.net/git/user/project/sub/directory" 1973 // 1974 // For code hosted on other servers, import paths may either be qualified 1975 // with the version control type, or the go tool can dynamically fetch 1976 // the import path over https/http and discover where the code resides 1977 // from a <meta> tag in the HTML. 1978 // 1979 // To declare the code location, an import path of the form 1980 // 1981 // repository.vcs/path 1982 // 1983 // specifies the given repository, with or without the .vcs suffix, 1984 // using the named version control system, and then the path inside 1985 // that repository. The supported version control systems are: 1986 // 1987 // Bazaar .bzr 1988 // Fossil .fossil 1989 // Git .git 1990 // Mercurial .hg 1991 // Subversion .svn 1992 // 1993 // For example, 1994 // 1995 // import "example.org/user/foo.hg" 1996 // 1997 // denotes the root directory of the Mercurial repository at 1998 // example.org/user/foo or foo.hg, and 1999 // 2000 // import "example.org/repo.git/foo/bar" 2001 // 2002 // denotes the foo/bar directory of the Git repository at 2003 // example.org/repo or repo.git. 2004 // 2005 // When a version control system supports multiple protocols, 2006 // each is tried in turn when downloading. For example, a Git 2007 // download tries https://, then git+ssh://. 2008 // 2009 // By default, downloads are restricted to known secure protocols 2010 // (e.g. https, ssh). To override this setting for Git downloads, the 2011 // GIT_ALLOW_PROTOCOL environment variable can be set (For more details see: 2012 // 'go help environment'). 2013 // 2014 // If the import path is not a known code hosting site and also lacks a 2015 // version control qualifier, the go tool attempts to fetch the import 2016 // over https/http and looks for a <meta> tag in the document's HTML 2017 // <head>. 2018 // 2019 // The meta tag has the form: 2020 // 2021 // <meta name="go-import" content="import-prefix vcs repo-root"> 2022 // 2023 // The import-prefix is the import path corresponding to the repository 2024 // root. It must be a prefix or an exact match of the package being 2025 // fetched with "go get". If it's not an exact match, another http 2026 // request is made at the prefix to verify the <meta> tags match. 2027 // 2028 // The meta tag should appear as early in the file as possible. 2029 // In particular, it should appear before any raw JavaScript or CSS, 2030 // to avoid confusing the go command's restricted parser. 2031 // 2032 // The vcs is one of "bzr", "fossil", "git", "hg", "svn". 2033 // 2034 // The repo-root is the root of the version control system 2035 // containing a scheme and not containing a .vcs qualifier. 2036 // 2037 // For example, 2038 // 2039 // import "example.org/pkg/foo" 2040 // 2041 // will result in the following requests: 2042 // 2043 // https://example.org/pkg/foo?go-get=1 (preferred) 2044 // http://example.org/pkg/foo?go-get=1 (fallback, only with -insecure) 2045 // 2046 // If that page contains the meta tag 2047 // 2048 // <meta name="go-import" content="example.org git https://code.org/r/p/exproj"> 2049 // 2050 // the go tool will verify that https://example.org/?go-get=1 contains the 2051 // same meta tag and then git clone https://code.org/r/p/exproj into 2052 // GOPATH/src/example.org. 2053 // 2054 // When using GOPATH, downloaded packages are written to the first directory 2055 // listed in the GOPATH environment variable. 2056 // (See 'go help gopath-get' and 'go help gopath'.) 2057 // 2058 // When using modules, downloaded packages are stored in the module cache. 2059 // (See 'go help module-get' and 'go help goproxy'.) 2060 // 2061 // When using modules, an additional variant of the go-import meta tag is 2062 // recognized and is preferred over those listing version control systems. 2063 // That variant uses "mod" as the vcs in the content value, as in: 2064 // 2065 // <meta name="go-import" content="example.org mod https://code.org/moduleproxy"> 2066 // 2067 // This tag means to fetch modules with paths beginning with example.org 2068 // from the module proxy available at the URL https://code.org/moduleproxy. 2069 // See 'go help goproxy' for details about the proxy protocol. 2070 // 2071 // Import path checking 2072 // 2073 // When the custom import path feature described above redirects to a 2074 // known code hosting site, each of the resulting packages has two possible 2075 // import paths, using the custom domain or the known hosting site. 2076 // 2077 // A package statement is said to have an "import comment" if it is immediately 2078 // followed (before the next newline) by a comment of one of these two forms: 2079 // 2080 // package math // import "path" 2081 // package math /* import "path" */ 2082 // 2083 // The go command will refuse to install a package with an import comment 2084 // unless it is being referred to by that import path. In this way, import comments 2085 // let package authors make sure the custom import path is used and not a 2086 // direct path to the underlying code hosting site. 2087 // 2088 // Import path checking is disabled for code found within vendor trees. 2089 // This makes it possible to copy code into alternate locations in vendor trees 2090 // without needing to update import comments. 2091 // 2092 // Import path checking is also disabled when using modules. 2093 // Import path comments are obsoleted by the go.mod file's module statement. 2094 // 2095 // See https://golang.org/s/go14customimport for details. 2096 // 2097 // 2098 // Modules, module versions, and more 2099 // 2100 // A module is a collection of related Go packages. 2101 // Modules are the unit of source code interchange and versioning. 2102 // The go command has direct support for working with modules, 2103 // including recording and resolving dependencies on other modules. 2104 // Modules replace the old GOPATH-based approach to specifying 2105 // which source files are used in a given build. 2106 // 2107 // Preliminary module support 2108 // 2109 // Go 1.11 includes preliminary support for Go modules, 2110 // including a new module-aware 'go get' command. 2111 // We intend to keep revising this support, while preserving compatibility, 2112 // until it can be declared official (no longer preliminary), 2113 // and then at a later point we may remove support for work 2114 // in GOPATH and the old 'go get' command. 2115 // 2116 // The quickest way to take advantage of the new Go 1.11 module support 2117 // is to check out your repository into a directory outside GOPATH/src, 2118 // create a go.mod file (described in the next section) there, and run 2119 // go commands from within that file tree. 2120 // 2121 // For more fine-grained control, the module support in Go 1.11 respects 2122 // a temporary environment variable, GO111MODULE, which can be set to one 2123 // of three string values: off, on, or auto (the default). 2124 // If GO111MODULE=off, then the go command never uses the 2125 // new module support. Instead it looks in vendor directories and GOPATH 2126 // to find dependencies; we now refer to this as "GOPATH mode." 2127 // If GO111MODULE=on, then the go command requires the use of modules, 2128 // never consulting GOPATH. We refer to this as the command being 2129 // module-aware or running in "module-aware mode". 2130 // If GO111MODULE=auto or is unset, then the go command enables or 2131 // disables module support based on the current directory. 2132 // Module support is enabled only when the current directory is outside 2133 // GOPATH/src and itself contains a go.mod file or is below a directory 2134 // containing a go.mod file. 2135 // 2136 // In module-aware mode, GOPATH no longer defines the meaning of imports 2137 // during a build, but it still stores downloaded dependencies (in GOPATH/pkg/mod) 2138 // and installed commands (in GOPATH/bin, unless GOBIN is set). 2139 // 2140 // Defining a module 2141 // 2142 // A module is defined by a tree of Go source files with a go.mod file 2143 // in the tree's root directory. The directory containing the go.mod file 2144 // is called the module root. Typically the module root will also correspond 2145 // to a source code repository root (but in general it need not). 2146 // The module is the set of all Go packages in the module root and its 2147 // subdirectories, but excluding subtrees with their own go.mod files. 2148 // 2149 // The "module path" is the import path prefix corresponding to the module root. 2150 // The go.mod file defines the module path and lists the specific versions 2151 // of other modules that should be used when resolving imports during a build, 2152 // by giving their module paths and versions. 2153 // 2154 // For example, this go.mod declares that the directory containing it is the root 2155 // of the module with path example.com/m, and it also declares that the module 2156 // depends on specific versions of golang.org/x/text and gopkg.in/yaml.v2: 2157 // 2158 // module example.com/m 2159 // 2160 // require ( 2161 // golang.org/x/text v0.3.0 2162 // gopkg.in/yaml.v2 v2.1.0 2163 // ) 2164 // 2165 // The go.mod file can also specify replacements and excluded versions 2166 // that only apply when building the module directly; they are ignored 2167 // when the module is incorporated into a larger build. 2168 // For more about the go.mod file, see 'go help go.mod'. 2169 // 2170 // To start a new module, simply create a go.mod file in the root of the 2171 // module's directory tree, containing only a module statement. 2172 // The 'go mod init' command can be used to do this: 2173 // 2174 // go mod init example.com/m 2175 // 2176 // In a project already using an existing dependency management tool like 2177 // godep, glide, or dep, 'go mod init' will also add require statements 2178 // matching the existing configuration. 2179 // 2180 // Once the go.mod file exists, no additional steps are required: 2181 // go commands like 'go build', 'go test', or even 'go list' will automatically 2182 // add new dependencies as needed to satisfy imports. 2183 // 2184 // The main module and the build list 2185 // 2186 // The "main module" is the module containing the directory where the go command 2187 // is run. The go command finds the module root by looking for a go.mod in the 2188 // current directory, or else the current directory's parent directory, 2189 // or else the parent's parent directory, and so on. 2190 // 2191 // The main module's go.mod file defines the precise set of packages available 2192 // for use by the go command, through require, replace, and exclude statements. 2193 // Dependency modules, found by following require statements, also contribute 2194 // to the definition of that set of packages, but only through their go.mod 2195 // files' require statements: any replace and exclude statements in dependency 2196 // modules are ignored. The replace and exclude statements therefore allow the 2197 // main module complete control over its own build, without also being subject 2198 // to complete control by dependencies. 2199 // 2200 // The set of modules providing packages to builds is called the "build list". 2201 // The build list initially contains only the main module. Then the go command 2202 // adds to the list the exact module versions required by modules already 2203 // on the list, recursively, until there is nothing left to add to the list. 2204 // If multiple versions of a particular module are added to the list, 2205 // then at the end only the latest version (according to semantic version 2206 // ordering) is kept for use in the build. 2207 // 2208 // The 'go list' command provides information about the main module 2209 // and the build list. For example: 2210 // 2211 // go list -m # print path of main module 2212 // go list -m -f={{.Dir}} # print root directory of main module 2213 // go list -m all # print build list 2214 // 2215 // Maintaining module requirements 2216 // 2217 // The go.mod file is meant to be readable and editable by both 2218 // programmers and tools. The go command itself automatically updates the go.mod file 2219 // to maintain a standard formatting and the accuracy of require statements. 2220 // 2221 // Any go command that finds an unfamiliar import will look up the module 2222 // containing that import and add the latest version of that module 2223 // to go.mod automatically. In most cases, therefore, it suffices to 2224 // add an import to source code and run 'go build', 'go test', or even 'go list': 2225 // as part of analyzing the package, the go command will discover 2226 // and resolve the import and update the go.mod file. 2227 // 2228 // Any go command can determine that a module requirement is 2229 // missing and must be added, even when considering only a single 2230 // package from the module. On the other hand, determining that a module requirement 2231 // is no longer necessary and can be deleted requires a full view of 2232 // all packages in the module, across all possible build configurations 2233 // (architectures, operating systems, build tags, and so on). 2234 // The 'go mod tidy' command builds that view and then 2235 // adds any missing module requirements and removes unnecessary ones. 2236 // 2237 // As part of maintaining the require statements in go.mod, the go command 2238 // tracks which ones provide packages imported directly by the current module 2239 // and which ones provide packages only used indirectly by other module 2240 // dependencies. Requirements needed only for indirect uses are marked with a 2241 // "// indirect" comment in the go.mod file. Indirect requirements are 2242 // automatically removed from the go.mod file once they are implied by other 2243 // direct requirements. Indirect requirements only arise when using modules 2244 // that fail to state some of their own dependencies or when explicitly 2245 // upgrading a module's dependencies ahead of its own stated requirements. 2246 // 2247 // Because of this automatic maintenance, the information in go.mod is an 2248 // up-to-date, readable description of the build. 2249 // 2250 // The 'go get' command updates go.mod to change the module versions used in a 2251 // build. An upgrade of one module may imply upgrading others, and similarly a 2252 // downgrade of one module may imply downgrading others. The 'go get' command 2253 // makes these implied changes as well. If go.mod is edited directly, commands 2254 // like 'go build' or 'go list' will assume that an upgrade is intended and 2255 // automatically make any implied upgrades and update go.mod to reflect them. 2256 // 2257 // The 'go mod' command provides other functionality for use in maintaining 2258 // and understanding modules and go.mod files. See 'go help mod'. 2259 // 2260 // The -mod build flag provides additional control over updating and use of go.mod. 2261 // 2262 // If invoked with -mod=readonly, the go command is disallowed from the implicit 2263 // automatic updating of go.mod described above. Instead, it fails when any changes 2264 // to go.mod are needed. This setting is most useful to check that go.mod does 2265 // not need updates, such as in a continuous integration and testing system. 2266 // The "go get" command remains permitted to update go.mod even with -mod=readonly, 2267 // and the "go mod" commands do not take the -mod flag (or any other build flags). 2268 // 2269 // If invoked with -mod=vendor, the go command assumes that the vendor 2270 // directory holds the correct copies of dependencies and ignores 2271 // the dependency descriptions in go.mod. 2272 // 2273 // Pseudo-versions 2274 // 2275 // The go.mod file and the go command more generally use semantic versions as 2276 // the standard form for describing module versions, so that versions can be 2277 // compared to determine which should be considered earlier or later than another. 2278 // A module version like v1.2.3 is introduced by tagging a revision in the 2279 // underlying source repository. Untagged revisions can be referred to 2280 // using a "pseudo-version" like v0.0.0-yyyymmddhhmmss-abcdefabcdef, 2281 // where the time is the commit time in UTC and the final suffix is the prefix 2282 // of the commit hash. The time portion ensures that two pseudo-versions can 2283 // be compared to determine which happened later, the commit hash identifes 2284 // the underlying commit, and the prefix (v0.0.0- in this example) is derived from 2285 // the most recent tagged version in the commit graph before this commit. 2286 // 2287 // There are three pseudo-version forms: 2288 // 2289 // vX.0.0-yyyymmddhhmmss-abcdefabcdef is used when there is no earlier 2290 // versioned commit with an appropriate major version before the target commit. 2291 // (This was originally the only form, so some older go.mod files use this form 2292 // even for commits that do follow tags.) 2293 // 2294 // vX.Y.Z-pre.0.yyyymmddhhmmss-abcdefabcdef is used when the most 2295 // recent versioned commit before the target commit is vX.Y.Z-pre. 2296 // 2297 // vX.Y.(Z+1)-0.yyyymmddhhmmss-abcdefabcdef is used when the most 2298 // recent versioned commit before the target commit is vX.Y.Z. 2299 // 2300 // Pseudo-versions never need to be typed by hand: the go command will accept 2301 // the plain commit hash and translate it into a pseudo-version (or a tagged 2302 // version if available) automatically. This conversion is an example of a 2303 // module query. 2304 // 2305 // Module queries 2306 // 2307 // The go command accepts a "module query" in place of a module version 2308 // both on the command line and in the main module's go.mod file. 2309 // (After evaluating a query found in the main module's go.mod file, 2310 // the go command updates the file to replace the query with its result.) 2311 // 2312 // A fully-specified semantic version, such as "v1.2.3", 2313 // evaluates to that specific version. 2314 // 2315 // A semantic version prefix, such as "v1" or "v1.2", 2316 // evaluates to the latest available tagged version with that prefix. 2317 // 2318 // A semantic version comparison, such as "<v1.2.3" or ">=v1.5.6", 2319 // evaluates to the available tagged version nearest to the comparison target 2320 // (the latest version for < and <=, the earliest version for > and >=). 2321 // 2322 // The string "latest" matches the latest available tagged version, 2323 // or else the underlying source repository's latest untagged revision. 2324 // 2325 // A revision identifier for the underlying source repository, 2326 // such as a commit hash prefix, revision tag, or branch name, 2327 // selects that specific code revision. If the revision is 2328 // also tagged with a semantic version, the query evaluates to 2329 // that semantic version. Otherwise the query evaluates to a 2330 // pseudo-version for the commit. 2331 // 2332 // All queries prefer release versions to pre-release versions. 2333 // For example, "<v1.2.3" will prefer to return "v1.2.2" 2334 // instead of "v1.2.3-pre1", even though "v1.2.3-pre1" is nearer 2335 // to the comparison target. 2336 // 2337 // Module versions disallowed by exclude statements in the 2338 // main module's go.mod are considered unavailable and cannot 2339 // be returned by queries. 2340 // 2341 // For example, these commands are all valid: 2342 // 2343 // go get github.com/gorilla/mux@latest # same (@latest is default for 'go get') 2344 // go get github.com/gorilla/mux@v1.6.2 # records v1.6.2 2345 // go get github.com/gorilla/mux@e3702bed2 # records v1.6.2 2346 // go get github.com/gorilla/mux@c856192 # records v0.0.0-20180517173623-c85619274f5d 2347 // go get github.com/gorilla/mux@master # records current meaning of master 2348 // 2349 // Module compatibility and semantic versioning 2350 // 2351 // The go command requires that modules use semantic versions and expects that 2352 // the versions accurately describe compatibility: it assumes that v1.5.4 is a 2353 // backwards-compatible replacement for v1.5.3, v1.4.0, and even v1.0.0. 2354 // More generally the go command expects that packages follow the 2355 // "import compatibility rule", which says: 2356 // 2357 // "If an old package and a new package have the same import path, 2358 // the new package must be backwards compatible with the old package." 2359 // 2360 // Because the go command assumes the import compatibility rule, 2361 // a module definition can only set the minimum required version of one 2362 // of its dependencies: it cannot set a maximum or exclude selected versions. 2363 // Still, the import compatibility rule is not a guarantee: it may be that 2364 // v1.5.4 is buggy and not a backwards-compatible replacement for v1.5.3. 2365 // Because of this, the go command never updates from an older version 2366 // to a newer version of a module unasked. 2367 // 2368 // In semantic versioning, changing the major version number indicates a lack 2369 // of backwards compatibility with earlier versions. To preserve import 2370 // compatibility, the go command requires that modules with major version v2 2371 // or later use a module path with that major version as the final element. 2372 // For example, version v2.0.0 of example.com/m must instead use module path 2373 // example.com/m/v2, and packages in that module would use that path as 2374 // their import path prefix, as in example.com/m/v2/sub/pkg. Including the 2375 // major version number in the module path and import paths in this way is 2376 // called "semantic import versioning". Pseudo-versions for modules with major 2377 // version v2 and later begin with that major version instead of v0, as in 2378 // v2.0.0-20180326061214-4fc5987536ef. 2379 // 2380 // As a special case, module paths beginning with gopkg.in/ continue to use the 2381 // conventions established on that system: the major version is always present, 2382 // and it is preceded by a dot instead of a slash: gopkg.in/yaml.v1 2383 // and gopkg.in/yaml.v2, not gopkg.in/yaml and gopkg.in/yaml/v2. 2384 // 2385 // The go command treats modules with different module paths as unrelated: 2386 // it makes no connection between example.com/m and example.com/m/v2. 2387 // Modules with different major versions can be used together in a build 2388 // and are kept separate by the fact that their packages use different 2389 // import paths. 2390 // 2391 // In semantic versioning, major version v0 is for initial development, 2392 // indicating no expectations of stability or backwards compatibility. 2393 // Major version v0 does not appear in the module path, because those 2394 // versions are preparation for v1.0.0, and v1 does not appear in the 2395 // module path either. 2396 // 2397 // Code written before the semantic import versioning convention 2398 // was introduced may use major versions v2 and later to describe 2399 // the same set of unversioned import paths as used in v0 and v1. 2400 // To accommodate such code, if a source code repository has a 2401 // v2.0.0 or later tag for a file tree with no go.mod, the version is 2402 // considered to be part of the v1 module's available versions 2403 // and is given an +incompatible suffix when converted to a module 2404 // version, as in v2.0.0+incompatible. The +incompatible tag is also 2405 // applied to pseudo-versions derived from such versions, as in 2406 // v2.0.1-0.yyyymmddhhmmss-abcdefabcdef+incompatible. 2407 // 2408 // In general, having a dependency in the build list (as reported by 'go list -m all') 2409 // on a v0 version, pre-release version, pseudo-version, or +incompatible version 2410 // is an indication that problems are more likely when upgrading that 2411 // dependency, since there is no expectation of compatibility for those. 2412 // 2413 // See https://research.swtch.com/vgo-import for more information about 2414 // semantic import versioning, and see https://semver.org/ for more about 2415 // semantic versioning. 2416 // 2417 // Module code layout 2418 // 2419 // For now, see https://research.swtch.com/vgo-module for information 2420 // about how source code in version control systems is mapped to 2421 // module file trees. 2422 // 2423 // Module downloading and verification 2424 // 2425 // The go command maintains, in the main module's root directory alongside 2426 // go.mod, a file named go.sum containing the expected cryptographic checksums 2427 // of the content of specific module versions. Each time a dependency is 2428 // used, its checksum is added to go.sum if missing or else required to match 2429 // the existing entry in go.sum. 2430 // 2431 // The go command maintains a cache of downloaded packages and computes 2432 // and records the cryptographic checksum of each package at download time. 2433 // In normal operation, the go command checks these pre-computed checksums 2434 // against the main module's go.sum file, instead of recomputing them on 2435 // each command invocation. The 'go mod verify' command checks that 2436 // the cached copies of module downloads still match both their recorded 2437 // checksums and the entries in go.sum. 2438 // 2439 // The go command can fetch modules from a proxy instead of connecting 2440 // to source control systems directly, according to the setting of the GOPROXY 2441 // environment variable. 2442 // 2443 // See 'go help goproxy' for details about the proxy and also the format of 2444 // the cached downloaded packages. 2445 // 2446 // Modules and vendoring 2447 // 2448 // When using modules, the go command completely ignores vendor directories. 2449 // 2450 // By default, the go command satisfies dependencies by downloading modules 2451 // from their sources and using those downloaded copies (after verification, 2452 // as described in the previous section). To allow interoperation with older 2453 // versions of Go, or to ensure that all files used for a build are stored 2454 // together in a single file tree, 'go mod vendor' creates a directory named 2455 // vendor in the root directory of the main module and stores there all the 2456 // packages from dependency modules that are needed to support builds and 2457 // tests of packages in the main module. 2458 // 2459 // To build using the main module's top-level vendor directory to satisfy 2460 // dependencies (disabling use of the usual network sources and local 2461 // caches), use 'go build -mod=vendor'. Note that only the main module's 2462 // top-level vendor directory is used; vendor directories in other locations 2463 // are still ignored. 2464 // 2465 // 2466 // Module-aware go get 2467 // 2468 // The 'go get' command changes behavior depending on whether the 2469 // go command is running in module-aware mode or legacy GOPATH mode. 2470 // This help text, accessible as 'go help module-get' even in legacy GOPATH mode, 2471 // describes 'go get' as it operates in module-aware mode. 2472 // 2473 // Usage: go get [-d] [-m] [-u] [-v] [-insecure] [build flags] [packages] 2474 // 2475 // Get resolves and adds dependencies to the current development module 2476 // and then builds and installs them. 2477 // 2478 // The first step is to resolve which dependencies to add. 2479 // 2480 // For each named package or package pattern, get must decide which version of 2481 // the corresponding module to use. By default, get chooses the latest tagged 2482 // release version, such as v0.4.5 or v1.2.3. If there are no tagged release 2483 // versions, get chooses the latest tagged prerelease version, such as 2484 // v0.0.1-pre1. If there are no tagged versions at all, get chooses the latest 2485 // known commit. 2486 // 2487 // This default version selection can be overridden by adding an @version 2488 // suffix to the package argument, as in 'go get golang.org/x/text@v0.3.0'. 2489 // For modules stored in source control repositories, the version suffix can 2490 // also be a commit hash, branch identifier, or other syntax known to the 2491 // source control system, as in 'go get golang.org/x/text@master'. 2492 // The version suffix @latest explicitly requests the default behavior 2493 // described above. 2494 // 2495 // If a module under consideration is already a dependency of the current 2496 // development module, then get will update the required version. 2497 // Specifying a version earlier than the current required version is valid and 2498 // downgrades the dependency. The version suffix @none indicates that the 2499 // dependency should be removed entirely, downgrading or removing modules 2500 // depending on it as needed. 2501 // 2502 // Although get defaults to using the latest version of the module containing 2503 // a named package, it does not use the latest version of that module's 2504 // dependencies. Instead it prefers to use the specific dependency versions 2505 // requested by that module. For example, if the latest A requires module 2506 // B v1.2.3, while B v1.2.4 and v1.3.1 are also available, then 'go get A' 2507 // will use the latest A but then use B v1.2.3, as requested by A. (If there 2508 // are competing requirements for a particular module, then 'go get' resolves 2509 // those requirements by taking the maximum requested version.) 2510 // 2511 // The -u flag instructs get to update dependencies to use newer minor or 2512 // patch releases when available. Continuing the previous example, 2513 // 'go get -u A' will use the latest A with B v1.3.1 (not B v1.2.3). 2514 // 2515 // The -u=patch flag (not -u patch) instructs get to update dependencies 2516 // to use newer patch releases when available. Continuing the previous example, 2517 // 'go get -u=patch A' will use the latest A with B v1.2.4 (not B v1.2.3). 2518 // 2519 // In general, adding a new dependency may require upgrading 2520 // existing dependencies to keep a working build, and 'go get' does 2521 // this automatically. Similarly, downgrading one dependency may 2522 // require downgrading other dependencies, and 'go get' does 2523 // this automatically as well. 2524 // 2525 // The -m flag instructs get to stop here, after resolving, upgrading, 2526 // and downgrading modules and updating go.mod. When using -m, 2527 // each specified package path must be a module path as well, 2528 // not the import path of a package below the module root. 2529 // 2530 // The -insecure flag permits fetching from repositories and resolving 2531 // custom domains using insecure schemes such as HTTP. Use with caution. 2532 // 2533 // The second step is to download (if needed), build, and install 2534 // the named packages. 2535 // 2536 // If an argument names a module but not a package (because there is no 2537 // Go source code in the module's root directory), then the install step 2538 // is skipped for that argument, instead of causing a build failure. 2539 // For example 'go get golang.org/x/perf' succeeds even though there 2540 // is no code corresponding to that import path. 2541 // 2542 // Note that package patterns are allowed and are expanded after resolving 2543 // the module versions. For example, 'go get golang.org/x/perf/cmd/...' 2544 // adds the latest golang.org/x/perf and then installs the commands in that 2545 // latest version. 2546 // 2547 // The -d flag instructs get to download the source code needed to build 2548 // the named packages, including downloading necessary dependencies, 2549 // but not to build and install them. 2550 // 2551 // With no package arguments, 'go get' applies to the main module, 2552 // and to the Go package in the current directory, if any. In particular, 2553 // 'go get -u' and 'go get -u=patch' update all the dependencies of the 2554 // main module. With no package arguments and also without -u, 2555 // 'go get' is not much more than 'go install', and 'go get -d' not much 2556 // more than 'go list'. 2557 // 2558 // For more about modules, see 'go help modules'. 2559 // 2560 // For more about specifying packages, see 'go help packages'. 2561 // 2562 // This text describes the behavior of get using modules to manage source 2563 // code and dependencies. If instead the go command is running in GOPATH 2564 // mode, the details of get's flags and effects change, as does 'go help get'. 2565 // See 'go help modules' and 'go help gopath-get'. 2566 // 2567 // See also: go build, go install, go clean, go mod. 2568 // 2569 // 2570 // Package lists and patterns 2571 // 2572 // Many commands apply to a set of packages: 2573 // 2574 // go action [packages] 2575 // 2576 // Usually, [packages] is a list of import paths. 2577 // 2578 // An import path that is a rooted path or that begins with 2579 // a . or .. element is interpreted as a file system path and 2580 // denotes the package in that directory. 2581 // 2582 // Otherwise, the import path P denotes the package found in 2583 // the directory DIR/src/P for some DIR listed in the GOPATH 2584 // environment variable (For more details see: 'go help gopath'). 2585 // 2586 // If no import paths are given, the action applies to the 2587 // package in the current directory. 2588 // 2589 // There are four reserved names for paths that should not be used 2590 // for packages to be built with the go tool: 2591 // 2592 // - "main" denotes the top-level package in a stand-alone executable. 2593 // 2594 // - "all" expands to all packages found in all the GOPATH 2595 // trees. For example, 'go list all' lists all the packages on the local 2596 // system. When using modules, "all" expands to all packages in 2597 // the main module and their dependencies, including dependencies 2598 // needed by tests of any of those. 2599 // 2600 // - "std" is like all but expands to just the packages in the standard 2601 // Go library. 2602 // 2603 // - "cmd" expands to the Go repository's commands and their 2604 // internal libraries. 2605 // 2606 // Import paths beginning with "cmd/" only match source code in 2607 // the Go repository. 2608 // 2609 // An import path is a pattern if it includes one or more "..." wildcards, 2610 // each of which can match any string, including the empty string and 2611 // strings containing slashes. Such a pattern expands to all package 2612 // directories found in the GOPATH trees with names matching the 2613 // patterns. 2614 // 2615 // To make common patterns more convenient, there are two special cases. 2616 // First, /... at the end of the pattern can match an empty string, 2617 // so that net/... matches both net and packages in its subdirectories, like net/http. 2618 // Second, any slash-separated pattern element containing a wildcard never 2619 // participates in a match of the "vendor" element in the path of a vendored 2620 // package, so that ./... does not match packages in subdirectories of 2621 // ./vendor or ./mycode/vendor, but ./vendor/... and ./mycode/vendor/... do. 2622 // Note, however, that a directory named vendor that itself contains code 2623 // is not a vendored package: cmd/vendor would be a command named vendor, 2624 // and the pattern cmd/... matches it. 2625 // See golang.org/s/go15vendor for more about vendoring. 2626 // 2627 // An import path can also name a package to be downloaded from 2628 // a remote repository. Run 'go help importpath' for details. 2629 // 2630 // Every package in a program must have a unique import path. 2631 // By convention, this is arranged by starting each path with a 2632 // unique prefix that belongs to you. For example, paths used 2633 // internally at Google all begin with 'google', and paths 2634 // denoting remote repositories begin with the path to the code, 2635 // such as 'github.com/user/repo'. 2636 // 2637 // Packages in a program need not have unique package names, 2638 // but there are two reserved package names with special meaning. 2639 // The name main indicates a command, not a library. 2640 // Commands are built into binaries and cannot be imported. 2641 // The name documentation indicates documentation for 2642 // a non-Go program in the directory. Files in package documentation 2643 // are ignored by the go command. 2644 // 2645 // As a special case, if the package list is a list of .go files from a 2646 // single directory, the command is applied to a single synthesized 2647 // package made up of exactly those files, ignoring any build constraints 2648 // in those files and ignoring any other files in the directory. 2649 // 2650 // Directory and file names that begin with "." or "_" are ignored 2651 // by the go tool, as are directories named "testdata". 2652 // 2653 // 2654 // Testing flags 2655 // 2656 // The 'go test' command takes both flags that apply to 'go test' itself 2657 // and flags that apply to the resulting test binary. 2658 // 2659 // Several of the flags control profiling and write an execution profile 2660 // suitable for "go tool pprof"; run "go tool pprof -h" for more 2661 // information. The --alloc_space, --alloc_objects, and --show_bytes 2662 // options of pprof control how the information is presented. 2663 // 2664 // The following flags are recognized by the 'go test' command and 2665 // control the execution of any test: 2666 // 2667 // -bench regexp 2668 // Run only those benchmarks matching a regular expression. 2669 // By default, no benchmarks are run. 2670 // To run all benchmarks, use '-bench .' or '-bench=.'. 2671 // The regular expression is split by unbracketed slash (/) 2672 // characters into a sequence of regular expressions, and each 2673 // part of a benchmark's identifier must match the corresponding 2674 // element in the sequence, if any. Possible parents of matches 2675 // are run with b.N=1 to identify sub-benchmarks. For example, 2676 // given -bench=X/Y, top-level benchmarks matching X are run 2677 // with b.N=1 to find any sub-benchmarks matching Y, which are 2678 // then run in full. 2679 // 2680 // -benchtime t 2681 // Run enough iterations of each benchmark to take t, specified 2682 // as a time.Duration (for example, -benchtime 1h30s). 2683 // The default is 1 second (1s). 2684 // The special syntax Nx means to run the benchmark N times 2685 // (for example, -benchtime 100x). 2686 // 2687 // -count n 2688 // Run each test and benchmark n times (default 1). 2689 // If -cpu is set, run n times for each GOMAXPROCS value. 2690 // Examples are always run once. 2691 // 2692 // -cover 2693 // Enable coverage analysis. 2694 // Note that because coverage works by annotating the source 2695 // code before compilation, compilation and test failures with 2696 // coverage enabled may report line numbers that don't correspond 2697 // to the original sources. 2698 // 2699 // -covermode set,count,atomic 2700 // Set the mode for coverage analysis for the package[s] 2701 // being tested. The default is "set" unless -race is enabled, 2702 // in which case it is "atomic". 2703 // The values: 2704 // set: bool: does this statement run? 2705 // count: int: how many times does this statement run? 2706 // atomic: int: count, but correct in multithreaded tests; 2707 // significantly more expensive. 2708 // Sets -cover. 2709 // 2710 // -coverpkg pattern1,pattern2,pattern3 2711 // Apply coverage analysis in each test to packages matching the patterns. 2712 // The default is for each test to analyze only the package being tested. 2713 // See 'go help packages' for a description of package patterns. 2714 // Sets -cover. 2715 // 2716 // -cpu 1,2,4 2717 // Specify a list of GOMAXPROCS values for which the tests or 2718 // benchmarks should be executed. The default is the current value 2719 // of GOMAXPROCS. 2720 // 2721 // -failfast 2722 // Do not start new tests after the first test failure. 2723 // 2724 // -list regexp 2725 // List tests, benchmarks, or examples matching the regular expression. 2726 // No tests, benchmarks or examples will be run. This will only 2727 // list top-level tests. No subtest or subbenchmarks will be shown. 2728 // 2729 // -parallel n 2730 // Allow parallel execution of test functions that call t.Parallel. 2731 // The value of this flag is the maximum number of tests to run 2732 // simultaneously; by default, it is set to the value of GOMAXPROCS. 2733 // Note that -parallel only applies within a single test binary. 2734 // The 'go test' command may run tests for different packages 2735 // in parallel as well, according to the setting of the -p flag 2736 // (see 'go help build'). 2737 // 2738 // -run regexp 2739 // Run only those tests and examples matching the regular expression. 2740 // For tests, the regular expression is split by unbracketed slash (/) 2741 // characters into a sequence of regular expressions, and each part 2742 // of a test's identifier must match the corresponding element in 2743 // the sequence, if any. Note that possible parents of matches are 2744 // run too, so that -run=X/Y matches and runs and reports the result 2745 // of all tests matching X, even those without sub-tests matching Y, 2746 // because it must run them to look for those sub-tests. 2747 // 2748 // -short 2749 // Tell long-running tests to shorten their run time. 2750 // It is off by default but set during all.bash so that installing 2751 // the Go tree can run a sanity check but not spend time running 2752 // exhaustive tests. 2753 // 2754 // -timeout d 2755 // If a test binary runs longer than duration d, panic. 2756 // If d is 0, the timeout is disabled. 2757 // The default is 10 minutes (10m). 2758 // 2759 // -v 2760 // Verbose output: log all tests as they are run. Also print all 2761 // text from Log and Logf calls even if the test succeeds. 2762 // 2763 // -vet list 2764 // Configure the invocation of "go vet" during "go test" 2765 // to use the comma-separated list of vet checks. 2766 // If list is empty, "go test" runs "go vet" with a curated list of 2767 // checks believed to be always worth addressing. 2768 // If list is "off", "go test" does not run "go vet" at all. 2769 // 2770 // The following flags are also recognized by 'go test' and can be used to 2771 // profile the tests during execution: 2772 // 2773 // -benchmem 2774 // Print memory allocation statistics for benchmarks. 2775 // 2776 // -blockprofile block.out 2777 // Write a goroutine blocking profile to the specified file 2778 // when all tests are complete. 2779 // Writes test binary as -c would. 2780 // 2781 // -blockprofilerate n 2782 // Control the detail provided in goroutine blocking profiles by 2783 // calling runtime.SetBlockProfileRate with n. 2784 // See 'go doc runtime.SetBlockProfileRate'. 2785 // The profiler aims to sample, on average, one blocking event every 2786 // n nanoseconds the program spends blocked. By default, 2787 // if -test.blockprofile is set without this flag, all blocking events 2788 // are recorded, equivalent to -test.blockprofilerate=1. 2789 // 2790 // -coverprofile cover.out 2791 // Write a coverage profile to the file after all tests have passed. 2792 // Sets -cover. 2793 // 2794 // -cpuprofile cpu.out 2795 // Write a CPU profile to the specified file before exiting. 2796 // Writes test binary as -c would. 2797 // 2798 // -memprofile mem.out 2799 // Write an allocation profile to the file after all tests have passed. 2800 // Writes test binary as -c would. 2801 // 2802 // -memprofilerate n 2803 // Enable more precise (and expensive) memory allocation profiles by 2804 // setting runtime.MemProfileRate. See 'go doc runtime.MemProfileRate'. 2805 // To profile all memory allocations, use -test.memprofilerate=1. 2806 // 2807 // -mutexprofile mutex.out 2808 // Write a mutex contention profile to the specified file 2809 // when all tests are complete. 2810 // Writes test binary as -c would. 2811 // 2812 // -mutexprofilefraction n 2813 // Sample 1 in n stack traces of goroutines holding a 2814 // contended mutex. 2815 // 2816 // -outputdir directory 2817 // Place output files from profiling in the specified directory, 2818 // by default the directory in which "go test" is running. 2819 // 2820 // -trace trace.out 2821 // Write an execution trace to the specified file before exiting. 2822 // 2823 // Each of these flags is also recognized with an optional 'test.' prefix, 2824 // as in -test.v. When invoking the generated test binary (the result of 2825 // 'go test -c') directly, however, the prefix is mandatory. 2826 // 2827 // The 'go test' command rewrites or removes recognized flags, 2828 // as appropriate, both before and after the optional package list, 2829 // before invoking the test binary. 2830 // 2831 // For instance, the command 2832 // 2833 // go test -v -myflag testdata -cpuprofile=prof.out -x 2834 // 2835 // will compile the test binary and then run it as 2836 // 2837 // pkg.test -test.v -myflag testdata -test.cpuprofile=prof.out 2838 // 2839 // (The -x flag is removed because it applies only to the go command's 2840 // execution, not to the test itself.) 2841 // 2842 // The test flags that generate profiles (other than for coverage) also 2843 // leave the test binary in pkg.test for use when analyzing the profiles. 2844 // 2845 // When 'go test' runs a test binary, it does so from within the 2846 // corresponding package's source code directory. Depending on the test, 2847 // it may be necessary to do the same when invoking a generated test 2848 // binary directly. 2849 // 2850 // The command-line package list, if present, must appear before any 2851 // flag not known to the go test command. Continuing the example above, 2852 // the package list would have to appear before -myflag, but could appear 2853 // on either side of -v. 2854 // 2855 // When 'go test' runs in package list mode, 'go test' caches successful 2856 // package test results to avoid unnecessary repeated running of tests. To 2857 // disable test caching, use any test flag or argument other than the 2858 // cacheable flags. The idiomatic way to disable test caching explicitly 2859 // is to use -count=1. 2860 // 2861 // To keep an argument for a test binary from being interpreted as a 2862 // known flag or a package name, use -args (see 'go help test') which 2863 // passes the remainder of the command line through to the test binary 2864 // uninterpreted and unaltered. 2865 // 2866 // For instance, the command 2867 // 2868 // go test -v -args -x -v 2869 // 2870 // will compile the test binary and then run it as 2871 // 2872 // pkg.test -test.v -x -v 2873 // 2874 // Similarly, 2875 // 2876 // go test -args math 2877 // 2878 // will compile the test binary and then run it as 2879 // 2880 // pkg.test math 2881 // 2882 // In the first example, the -x and the second -v are passed through to the 2883 // test binary unchanged and with no effect on the go command itself. 2884 // In the second example, the argument math is passed through to the test 2885 // binary, instead of being interpreted as the package list. 2886 // 2887 // 2888 // Testing functions 2889 // 2890 // The 'go test' command expects to find test, benchmark, and example functions 2891 // in the "*_test.go" files corresponding to the package under test. 2892 // 2893 // A test function is one named TestXxx (where Xxx does not start with a 2894 // lower case letter) and should have the signature, 2895 // 2896 // func TestXxx(t *testing.T) { ... } 2897 // 2898 // A benchmark function is one named BenchmarkXxx and should have the signature, 2899 // 2900 // func BenchmarkXxx(b *testing.B) { ... } 2901 // 2902 // An example function is similar to a test function but, instead of using 2903 // *testing.T to report success or failure, prints output to os.Stdout. 2904 // If the last comment in the function starts with "Output:" then the output 2905 // is compared exactly against the comment (see examples below). If the last 2906 // comment begins with "Unordered output:" then the output is compared to the 2907 // comment, however the order of the lines is ignored. An example with no such 2908 // comment is compiled but not executed. An example with no text after 2909 // "Output:" is compiled, executed, and expected to produce no output. 2910 // 2911 // Godoc displays the body of ExampleXxx to demonstrate the use 2912 // of the function, constant, or variable Xxx. An example of a method M with 2913 // receiver type T or *T is named ExampleT_M. There may be multiple examples 2914 // for a given function, constant, or variable, distinguished by a trailing _xxx, 2915 // where xxx is a suffix not beginning with an upper case letter. 2916 // 2917 // Here is an example of an example: 2918 // 2919 // func ExamplePrintln() { 2920 // Println("The output of\nthis example.") 2921 // // Output: The output of 2922 // // this example. 2923 // } 2924 // 2925 // Here is another example where the ordering of the output is ignored: 2926 // 2927 // func ExamplePerm() { 2928 // for _, value := range Perm(4) { 2929 // fmt.Println(value) 2930 // } 2931 // 2932 // // Unordered output: 4 2933 // // 2 2934 // // 1 2935 // // 3 2936 // // 0 2937 // } 2938 // 2939 // The entire test file is presented as the example when it contains a single 2940 // example function, at least one other function, type, variable, or constant 2941 // declaration, and no test or benchmark functions. 2942 // 2943 // See the documentation of the testing package for more information. 2944 // 2945 // 2946 package main