rsc.io/go@v0.0.0-20150416155037-e040fd465409/src/cmd/go/doc.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 // DO NOT EDIT THIS FILE. GENERATED BY mkdoc.sh. 6 // Edit the documentation in other files and rerun mkdoc.sh to generate this one. 7 8 /* 9 Go is a tool for managing Go source code. 10 11 Usage: 12 13 go command [arguments] 14 15 The commands are: 16 17 build compile packages and dependencies 18 clean remove object files 19 env print Go environment information 20 fix run go tool fix on packages 21 fmt run gofmt on package sources 22 generate generate Go files by processing source 23 get download and install packages and dependencies 24 install compile and install packages and dependencies 25 list list packages 26 run compile and run Go program 27 test test packages 28 tool run specified go tool 29 version print Go version 30 vet run go tool vet on packages 31 32 Use "go help [command]" for more information about a command. 33 34 Additional help topics: 35 36 c calling between Go and C 37 buildmode description of build modes 38 filetype file types 39 gopath GOPATH environment variable 40 importpath import path syntax 41 packages description of package lists 42 testflag description of testing flags 43 testfunc description of testing functions 44 45 Use "go help [topic]" for more information about that topic. 46 47 48 Compile packages and dependencies 49 50 Usage: 51 52 go build [-o output] [-i] [build flags] [packages] 53 54 Build compiles the packages named by the import paths, 55 along with their dependencies, but it does not install the results. 56 57 If the arguments are a list of .go files, build treats them as a list 58 of source files specifying a single package. 59 60 When the command line specifies a single main package, 61 build writes the resulting executable to output. 62 Otherwise build compiles the packages but discards the results, 63 serving only as a check that the packages can be built. 64 65 The -o flag specifies the output file name. If not specified, the 66 output file name depends on the arguments and derives from the name 67 of the package, such as p.a for package p, unless p is 'main'. If 68 the package is main and file names are provided, the file name 69 derives from the first file name mentioned, such as f1 for 'go build 70 f1.go f2.go'; with no files provided ('go build'), the output file 71 name is the base name of the containing directory. 72 73 The -i flag installs the packages that are dependencies of the target. 74 75 The build flags are shared by the build, clean, get, install, list, run, 76 and test commands: 77 78 -a 79 force rebuilding of packages that are already up-to-date. 80 In Go releases, does not apply to the standard library. 81 -n 82 print the commands but do not run them. 83 -p n 84 the number of builds that can be run in parallel. 85 The default is the number of CPUs available, except 86 on darwin/arm which defaults to 1. 87 -race 88 enable data race detection. 89 Supported only on linux/amd64, freebsd/amd64, darwin/amd64 and windows/amd64. 90 -v 91 print the names of packages as they are compiled. 92 -work 93 print the name of the temporary work directory and 94 do not delete it when exiting. 95 -x 96 print the commands. 97 98 -buildmode mode 99 build mode to use. See 'go help buildmode' for more. 100 -linkshared 101 link against shared libraries previously created with 102 -buildmode=shared 103 -compiler name 104 name of compiler to use, as in runtime.Compiler (gccgo or gc). 105 -gccgoflags 'arg list' 106 arguments to pass on each gccgo compiler/linker invocation. 107 -gcflags 'arg list' 108 arguments to pass on each 5g, 6g, 8g, or 9g compiler invocation. 109 -installsuffix suffix 110 a suffix to use in the name of the package installation directory, 111 in order to keep output separate from default builds. 112 If using the -race flag, the install suffix is automatically set to race 113 or, if set explicitly, has _race appended to it. Using a -buildmode 114 option that requires non-default compile flags has a similar effect. 115 -ldflags 'flag list' 116 arguments to pass on each 5l, 6l, 8l, or 9l linker invocation. 117 -asmflags 'flag list' 118 arguments to pass on each asm assembler invocation. 119 -tags 'tag list' 120 a list of build tags to consider satisfied during the build. 121 For more information about build tags, see the description of 122 build constraints in the documentation for the go/build package. 123 -toolexec 'cmd args' 124 a program to use to invoke toolchain programs like 5a, 5g, and 5l. 125 For example, instead of running 5g, the go command will run 126 'cmd args /path/to/5g <arguments for 5g>'. 127 128 The list flags accept a space-separated list of strings. To embed spaces 129 in an element in the list, surround it with either single or double quotes. 130 131 For more about specifying packages, see 'go help packages'. 132 For more about where packages and binaries are installed, 133 run 'go help gopath'. For more about calling between Go and C/C++, 134 run 'go help c'. 135 136 See also: go install, go get, go clean. 137 138 139 Remove object files 140 141 Usage: 142 143 go clean [-i] [-r] [-n] [-x] [build flags] [packages] 144 145 Clean removes object files from package source directories. 146 The go command builds most objects in a temporary directory, 147 so go clean is mainly concerned with object files left by other 148 tools or by manual invocations of go build. 149 150 Specifically, clean removes the following files from each of the 151 source directories corresponding to the import paths: 152 153 _obj/ old object directory, left from Makefiles 154 _test/ old test directory, left from Makefiles 155 _testmain.go old gotest file, left from Makefiles 156 test.out old test log, left from Makefiles 157 build.out old test log, left from Makefiles 158 *.[568ao] object files, left from Makefiles 159 160 DIR(.exe) from go build 161 DIR.test(.exe) from go test -c 162 MAINFILE(.exe) from go build MAINFILE.go 163 *.so from SWIG 164 165 In the list, DIR represents the final path element of the 166 directory, and MAINFILE is the base name of any Go source 167 file in the directory that is not included when building 168 the package. 169 170 The -i flag causes clean to remove the corresponding installed 171 archive or binary (what 'go install' would create). 172 173 The -n flag causes clean to print the remove commands it would execute, 174 but not run them. 175 176 The -r flag causes clean to be applied recursively to all the 177 dependencies of the packages named by the import paths. 178 179 The -x flag causes clean to print remove commands as it executes them. 180 181 For more about build flags, see 'go help build'. 182 183 For more about specifying packages, see 'go help packages'. 184 185 186 Print Go environment information 187 188 Usage: 189 190 go env [var ...] 191 192 Env prints Go environment information. 193 194 By default env prints information as a shell script 195 (on Windows, a batch file). If one or more variable 196 names is given as arguments, env prints the value of 197 each named variable on its own line. 198 199 200 Run go tool fix on packages 201 202 Usage: 203 204 go fix [packages] 205 206 Fix runs the Go fix command on the packages named by the import paths. 207 208 For more about fix, see 'godoc fix'. 209 For more about specifying packages, see 'go help packages'. 210 211 To run fix with specific options, run 'go tool fix'. 212 213 See also: go fmt, go vet. 214 215 216 Run gofmt on package sources 217 218 Usage: 219 220 go fmt [-n] [-x] [packages] 221 222 Fmt runs the command 'gofmt -l -w' on the packages named 223 by the import paths. It prints the names of the files that are modified. 224 225 For more about gofmt, see 'godoc gofmt'. 226 For more about specifying packages, see 'go help packages'. 227 228 The -n flag prints commands that would be executed. 229 The -x flag prints commands as they are executed. 230 231 To run gofmt with specific options, run gofmt itself. 232 233 See also: go fix, go vet. 234 235 236 Generate Go files by processing source 237 238 Usage: 239 240 go generate [-run regexp] [file.go... | packages] 241 242 Generate runs commands described by directives within existing 243 files. Those commands can run any process but the intent is to 244 create or update Go source files, for instance by running yacc. 245 246 Go generate is never run automatically by go build, go get, go test, 247 and so on. It must be run explicitly. 248 249 Go generate scans the file for directives, which are lines of 250 the form, 251 252 //go:generate command argument... 253 254 (note: no leading spaces and no space in "//go") where command 255 is the generator to be run, corresponding to an executable file 256 that can be run locally. It must either be in the shell path 257 (gofmt), a fully qualified path (/usr/you/bin/mytool), or a 258 command alias, described below. 259 260 Note that go generate does not parse the file, so lines that look 261 like directives in comments or multiline strings will be treated 262 as directives. 263 264 The arguments to the directive are space-separated tokens or 265 double-quoted strings passed to the generator as individual 266 arguments when it is run. 267 268 Quoted strings use Go syntax and are evaluated before execution; a 269 quoted string appears as a single argument to the generator. 270 271 Go generate sets several variables when it runs the generator: 272 273 $GOARCH 274 The execution architecture (arm, amd64, etc.) 275 $GOOS 276 The execution operating system (linux, windows, etc.) 277 $GOFILE 278 The base name of the file. 279 $GOPACKAGE 280 The name of the package of the file containing the directive. 281 $DOLLAR 282 A dollar sign. 283 284 Other than variable substitution and quoted-string evaluation, no 285 special processing such as "globbing" is performed on the command 286 line. 287 288 As a last step before running the command, any invocations of any 289 environment variables with alphanumeric names, such as $GOFILE or 290 $HOME, are expanded throughout the command line. The syntax for 291 variable expansion is $NAME on all operating systems. Due to the 292 order of evaluation, variables are expanded even inside quoted 293 strings. If the variable NAME is not set, $NAME expands to the 294 empty string. 295 296 A directive of the form, 297 298 //go:generate -command xxx args... 299 300 specifies, for the remainder of this source file only, that the 301 string xxx represents the command identified by the arguments. This 302 can be used to create aliases or to handle multiword generators. 303 For example, 304 305 //go:generate -command yacc go tool yacc 306 307 specifies that the command "yacc" represents the generator 308 "go tool yacc". 309 310 Generate processes packages in the order given on the command line, 311 one at a time. If the command line lists .go files, they are treated 312 as a single package. Within a package, generate processes the 313 source files in a package in file name order, one at a time. Within 314 a source file, generate runs generators in the order they appear 315 in the file, one at a time. 316 317 If any generator returns an error exit status, "go generate" skips 318 all further processing for that package. 319 320 The generator is run in the package's source directory. 321 322 Go generate accepts one specific flag: 323 324 -run="" 325 TODO: This flag is unimplemented. 326 if non-empty, specifies a regular expression to 327 select directives whose command matches the expression. 328 329 It also accepts the standard build flags -v, -n, and -x. 330 The -v flag prints the names of packages and files as they are 331 processed. 332 The -n flag prints commands that would be executed. 333 The -x flag prints commands as they are executed. 334 335 For more about specifying packages, see 'go help packages'. 336 337 338 Download and install packages and dependencies 339 340 Usage: 341 342 go get [-d] [-f] [-fix] [-t] [-u] [build flags] [packages] 343 344 Get downloads and installs the packages named by the import paths, 345 along with their dependencies. 346 347 The -d flag instructs get to stop after downloading the packages; that is, 348 it instructs get not to install the packages. 349 350 The -f flag, valid only when -u is set, forces get -u not to verify that 351 each package has been checked out from the source control repository 352 implied by its import path. This can be useful if the source is a local fork 353 of the original. 354 355 The -fix flag instructs get to run the fix tool on the downloaded packages 356 before resolving dependencies or building the code. 357 358 The -t flag instructs get to also download the packages required to build 359 the tests for the specified packages. 360 361 The -u flag instructs get to use the network to update the named packages 362 and their dependencies. By default, get uses the network to check out 363 missing packages but does not use it to look for updates to existing packages. 364 365 Get also accepts build flags to control the installation. See 'go help build'. 366 367 When checking out or updating a package, get looks for a branch or tag 368 that matches the locally installed version of Go. The most important 369 rule is that if the local installation is running version "go1", get 370 searches for a branch or tag named "go1". If no such version exists it 371 retrieves the most recent version of the package. 372 373 For more about specifying packages, see 'go help packages'. 374 375 For more about how 'go get' finds source code to 376 download, see 'go help importpath'. 377 378 See also: go build, go install, go clean. 379 380 381 Compile and install packages and dependencies 382 383 Usage: 384 385 go install [build flags] [packages] 386 387 Install compiles and installs the packages named by the import paths, 388 along with their dependencies. 389 390 For more about the build flags, see 'go help build'. 391 For more about specifying packages, see 'go help packages'. 392 393 See also: go build, go get, go clean. 394 395 396 List packages 397 398 Usage: 399 400 go list [-e] [-f format] [-json] [build flags] [packages] 401 402 List lists the packages named by the import paths, one per line. 403 404 The default output shows the package import path: 405 406 code.google.com/p/google-api-go-client/books/v1 407 code.google.com/p/goauth2/oauth 408 code.google.com/p/sqlite 409 410 The -f flag specifies an alternate format for the list, using the 411 syntax of package template. The default output is equivalent to -f 412 '{{.ImportPath}}'. The struct being passed to the template is: 413 414 type Package struct { 415 Dir string // directory containing package sources 416 ImportPath string // import path of package in dir 417 ImportComment string // path in import comment on package statement 418 Name string // package name 419 Doc string // package documentation string 420 Target string // install path 421 Goroot bool // is this package in the Go root? 422 Standard bool // is this package part of the standard Go library? 423 Stale bool // would 'go install' do anything for this package? 424 Root string // Go root or Go path dir containing this package 425 426 // Source files 427 GoFiles []string // .go source files (excluding CgoFiles, TestGoFiles, XTestGoFiles) 428 CgoFiles []string // .go sources files that import "C" 429 IgnoredGoFiles []string // .go sources ignored due to build constraints 430 CFiles []string // .c source files 431 CXXFiles []string // .cc, .cxx and .cpp source files 432 MFiles []string // .m source files 433 HFiles []string // .h, .hh, .hpp and .hxx source files 434 SFiles []string // .s source files 435 SwigFiles []string // .swig files 436 SwigCXXFiles []string // .swigcxx files 437 SysoFiles []string // .syso object files to add to archive 438 439 // Cgo directives 440 CgoCFLAGS []string // cgo: flags for C compiler 441 CgoCPPFLAGS []string // cgo: flags for C preprocessor 442 CgoCXXFLAGS []string // cgo: flags for C++ compiler 443 CgoLDFLAGS []string // cgo: flags for linker 444 CgoPkgConfig []string // cgo: pkg-config names 445 446 // Dependency information 447 Imports []string // import paths used by this package 448 Deps []string // all (recursively) imported dependencies 449 450 // Error information 451 Incomplete bool // this package or a dependency has an error 452 Error *PackageError // error loading package 453 DepsErrors []*PackageError // errors loading dependencies 454 455 TestGoFiles []string // _test.go files in package 456 TestImports []string // imports from TestGoFiles 457 XTestGoFiles []string // _test.go files outside package 458 XTestImports []string // imports from XTestGoFiles 459 } 460 461 The template function "join" calls strings.Join. 462 463 The template function "context" returns the build context, defined as: 464 465 type Context struct { 466 GOARCH string // target architecture 467 GOOS string // target operating system 468 GOROOT string // Go root 469 GOPATH string // Go path 470 CgoEnabled bool // whether cgo can be used 471 UseAllFiles bool // use files regardless of +build lines, file names 472 Compiler string // compiler to assume when computing target paths 473 BuildTags []string // build constraints to match in +build lines 474 ReleaseTags []string // releases the current release is compatible with 475 InstallSuffix string // suffix to use in the name of the install dir 476 } 477 478 For more information about the meaning of these fields see the documentation 479 for the go/build package's Context type. 480 481 The -json flag causes the package data to be printed in JSON format 482 instead of using the template format. 483 484 The -e flag changes the handling of erroneous packages, those that 485 cannot be found or are malformed. By default, the list command 486 prints an error to standard error for each erroneous package and 487 omits the packages from consideration during the usual printing. 488 With the -e flag, the list command never prints errors to standard 489 error and instead processes the erroneous packages with the usual 490 printing. Erroneous packages will have a non-empty ImportPath and 491 a non-nil Error field; other information may or may not be missing 492 (zeroed). 493 494 For more about build flags, see 'go help build'. 495 496 For more about specifying packages, see 'go help packages'. 497 498 499 Compile and run Go program 500 501 Usage: 502 503 go run [build flags] [-exec xprog] gofiles... [arguments...] 504 505 Run compiles and runs the main package comprising the named Go source files. 506 A Go source file is defined to be a file ending in a literal ".go" suffix. 507 508 By default, 'go run' runs the compiled binary directly: 'a.out arguments...'. 509 If the -exec flag is given, 'go run' invokes the binary using xprog: 'xprog a.out arguments...'. 510 If the -exec flag is not given, GOOS or GOARCH is different from the system 511 default, and a program named go_$GOOS_$GOARCH_exec can be found 512 on the current search path, 'go run' invokes the binary using that program, 513 for example 'go_nacl_386_exec a.out arguments...'. This allows execution of 514 cross-compiled programs when a simulator or other execution method is 515 available. 516 517 For more about build flags, see 'go help build'. 518 519 See also: go build. 520 521 522 Test packages 523 524 Usage: 525 526 go test [-c] [-i] [build and test flags] [packages] [flags for test binary] 527 528 'Go test' automates testing the packages named by the import paths. 529 It prints a summary of the test results in the format: 530 531 ok archive/tar 0.011s 532 FAIL archive/zip 0.022s 533 ok compress/gzip 0.033s 534 ... 535 536 followed by detailed output for each failed package. 537 538 'Go test' recompiles each package along with any files with names matching 539 the file pattern "*_test.go". 540 Files whose names begin with "_" (including "_test.go") or "." are ignored. 541 These additional files can contain test functions, benchmark functions, and 542 example functions. See 'go help testfunc' for more. 543 Each listed package causes the execution of a separate test binary. 544 545 Test files that declare a package with the suffix "_test" will be compiled as a 546 separate package, and then linked and run with the main test binary. 547 548 By default, go test needs no arguments. It compiles and tests the package 549 with source in the current directory, including tests, and runs the tests. 550 551 The package is built in a temporary directory so it does not interfere with the 552 non-test installation. 553 554 In addition to the build flags, the flags handled by 'go test' itself are: 555 556 -c 557 Compile the test binary to pkg.test but do not run it 558 (where pkg is the last element of the package's import path). 559 The file name can be changed with the -o flag. 560 561 -exec xprog 562 Run the test binary using xprog. The behavior is the same as 563 in 'go run'. See 'go help run' for details. 564 565 -i 566 Install packages that are dependencies of the test. 567 Do not run the test. 568 569 -o file 570 Compile the test binary to the named file. 571 The test still runs (unless -c or -i is specified). 572 573 574 The test binary also accepts flags that control execution of the test; these 575 flags are also accessible by 'go test'. See 'go help testflag' for details. 576 577 If the test binary needs any other flags, they should be presented after the 578 package names. The go tool treats as a flag the first argument that begins with 579 a minus sign that it does not recognize itself; that argument and all subsequent 580 arguments are passed as arguments to the test binary. 581 582 For more about build flags, see 'go help build'. 583 For more about specifying packages, see 'go help packages'. 584 585 See also: go build, go vet. 586 587 588 Run specified go tool 589 590 Usage: 591 592 go tool [-n] command [args...] 593 594 Tool runs the go tool command identified by the arguments. 595 With no arguments it prints the list of known tools. 596 597 The -n flag causes tool to print the command that would be 598 executed but not execute it. 599 600 For more about each tool command, see 'go tool command -h'. 601 602 603 Print Go version 604 605 Usage: 606 607 go version 608 609 Version prints the Go version, as reported by runtime.Version. 610 611 612 Run go tool vet on packages 613 614 Usage: 615 616 go vet [-n] [-x] [packages] 617 618 Vet runs the Go vet command on the packages named by the import paths. 619 620 For more about vet, see 'godoc golang.org/x/tools/cmd/vet'. 621 For more about specifying packages, see 'go help packages'. 622 623 To run the vet tool with specific options, run 'go tool vet'. 624 625 The -n flag prints commands that would be executed. 626 The -x flag prints commands as they are executed. 627 628 See also: go fmt, go fix. 629 630 631 Calling between Go and C 632 633 There are two different ways to call between Go and C/C++ code. 634 635 The first is the cgo tool, which is part of the Go distribution. For 636 information on how to use it see the cgo documentation (godoc cmd/cgo). 637 638 The second is the SWIG program, which is a general tool for 639 interfacing between languages. For information on SWIG see 640 http://swig.org/. When running go build, any file with a .swig 641 extension will be passed to SWIG. Any file with a .swigcxx extension 642 will be passed to SWIG with the -c++ option. 643 644 When either cgo or SWIG is used, go build will pass any .c, .m, .s, 645 or .S files to the C compiler, and any .cc, .cpp, .cxx files to the C++ 646 compiler. The CC or CXX environment variables may be set to determine 647 the C or C++ compiler, respectively, to use. 648 649 650 Description of build modes 651 652 The 'go build' and 'go install' commands take a -buildmode argument which 653 indicates which kind of object file is to be built. Currently supported values 654 are: 655 656 -buildmode=archive 657 Build the listed non-main packages into .a files. Packages named 658 main are ignored. 659 660 -buildmode=c-archive 661 Build the listed main package, plus all packages it imports, 662 into a C archive file. The only callable symbols will be those 663 functions marked as exported. Requires exactly one main package 664 to be listed. 665 666 -buildmode=c-shared 667 Build the listed main packages, plus all packages that they 668 import, into C shared libraries. The only callable symbols will 669 be those functions marked as exported. Non-main packages are 670 ignored. 671 672 -buildmode=default 673 Listed main packages are built into executables and listed 674 non-main packages are built into .a files (the default 675 behavior). 676 677 -buildmode=shared 678 Combine all the listed non-main packages into a single shared 679 library that will be used when building with the -linkshared 680 option. Packages named main are ignored. 681 682 -buildmode=exe 683 Build the listed main packages and everything they import into 684 executables. Packages not named main are ignored. 685 686 687 File types 688 689 The go command examines the contents of a restricted set of files 690 in each directory. It identifies which files to examine based on 691 the extension of the file name. These extensions are: 692 693 .go 694 Go source files. 695 .c, .h 696 C source files. 697 If the package uses cgo, these will be compiled with the 698 OS-native compiler (typically gcc); otherwise they will be 699 compiled with the Go-specific support compiler, 700 5c, 6c, or 8c, etc. as appropriate. 701 .cc, .cpp, .cxx, .hh, .hpp, .hxx 702 C++ source files. Only useful with cgo or SWIG, and always 703 compiled with the OS-native compiler. 704 .m 705 Objective-C source files. Only useful with cgo, and always 706 compiled with the OS-native compiler. 707 .s, .S 708 Assembler source files. 709 If the package uses cgo, these will be assembled with the 710 OS-native assembler (typically gcc (sic)); otherwise they 711 will be assembled with the Go-specific support assembler, 712 5a, 6a, or 8a, etc., as appropriate. 713 .swig, .swigcxx 714 SWIG definition files. 715 .syso 716 System object files. 717 718 Files of each of these types except .syso may contain build 719 constraints, but the go command stops scanning for build constraints 720 at the first item in the file that is not a blank line or //-style 721 line comment. 722 723 724 GOPATH environment variable 725 726 The Go path is used to resolve import statements. 727 It is implemented by and documented in the go/build package. 728 729 The GOPATH environment variable lists places to look for Go code. 730 On Unix, the value is a colon-separated string. 731 On Windows, the value is a semicolon-separated string. 732 On Plan 9, the value is a list. 733 734 GOPATH must be set to get, build and install packages outside the 735 standard Go tree. 736 737 Each directory listed in GOPATH must have a prescribed structure: 738 739 The src/ directory holds source code. The path below 'src' 740 determines the import path or executable name. 741 742 The pkg/ directory holds installed package objects. 743 As in the Go tree, each target operating system and 744 architecture pair has its own subdirectory of pkg 745 (pkg/GOOS_GOARCH). 746 747 If DIR is a directory listed in the GOPATH, a package with 748 source in DIR/src/foo/bar can be imported as "foo/bar" and 749 has its compiled form installed to "DIR/pkg/GOOS_GOARCH/foo/bar.a". 750 751 The bin/ directory holds compiled commands. 752 Each command is named for its source directory, but only 753 the final element, not the entire path. That is, the 754 command with source in DIR/src/foo/quux is installed into 755 DIR/bin/quux, not DIR/bin/foo/quux. The foo/ is stripped 756 so that you can add DIR/bin to your PATH to get at the 757 installed commands. If the GOBIN environment variable is 758 set, commands are installed to the directory it names instead 759 of DIR/bin. 760 761 Here's an example directory layout: 762 763 GOPATH=/home/user/gocode 764 765 /home/user/gocode/ 766 src/ 767 foo/ 768 bar/ (go code in package bar) 769 x.go 770 quux/ (go code in package main) 771 y.go 772 bin/ 773 quux (installed command) 774 pkg/ 775 linux_amd64/ 776 foo/ 777 bar.a (installed package object) 778 779 Go searches each directory listed in GOPATH to find source code, 780 but new packages are always downloaded into the first directory 781 in the list. 782 783 784 Import path syntax 785 786 An import path (see 'go help packages') denotes a package 787 stored in the local file system. In general, an import path denotes 788 either a standard package (such as "unicode/utf8") or a package 789 found in one of the work spaces (see 'go help gopath'). 790 791 Relative import paths 792 793 An import path beginning with ./ or ../ is called a relative path. 794 The toolchain supports relative import paths as a shortcut in two ways. 795 796 First, a relative path can be used as a shorthand on the command line. 797 If you are working in the directory containing the code imported as 798 "unicode" and want to run the tests for "unicode/utf8", you can type 799 "go test ./utf8" instead of needing to specify the full path. 800 Similarly, in the reverse situation, "go test .." will test "unicode" from 801 the "unicode/utf8" directory. Relative patterns are also allowed, like 802 "go test ./..." to test all subdirectories. See 'go help packages' for details 803 on the pattern syntax. 804 805 Second, if you are compiling a Go program not in a work space, 806 you can use a relative path in an import statement in that program 807 to refer to nearby code also not in a work space. 808 This makes it easy to experiment with small multipackage programs 809 outside of the usual work spaces, but such programs cannot be 810 installed with "go install" (there is no work space in which to install them), 811 so they are rebuilt from scratch each time they are built. 812 To avoid ambiguity, Go programs cannot use relative import paths 813 within a work space. 814 815 Remote import paths 816 817 Certain import paths also 818 describe how to obtain the source code for the package using 819 a revision control system. 820 821 A few common code hosting sites have special syntax: 822 823 Bitbucket (Git, Mercurial) 824 825 import "bitbucket.org/user/project" 826 import "bitbucket.org/user/project/sub/directory" 827 828 GitHub (Git) 829 830 import "github.com/user/project" 831 import "github.com/user/project/sub/directory" 832 833 Google Code Project Hosting (Git, Mercurial, Subversion) 834 835 import "code.google.com/p/project" 836 import "code.google.com/p/project/sub/directory" 837 838 import "code.google.com/p/project.subrepository" 839 import "code.google.com/p/project.subrepository/sub/directory" 840 841 Launchpad (Bazaar) 842 843 import "launchpad.net/project" 844 import "launchpad.net/project/series" 845 import "launchpad.net/project/series/sub/directory" 846 847 import "launchpad.net/~user/project/branch" 848 import "launchpad.net/~user/project/branch/sub/directory" 849 850 IBM DevOps Services (Git) 851 852 import "hub.jazz.net/git/user/project" 853 import "hub.jazz.net/git/user/project/sub/directory" 854 855 For code hosted on other servers, import paths may either be qualified 856 with the version control type, or the go tool can dynamically fetch 857 the import path over https/http and discover where the code resides 858 from a <meta> tag in the HTML. 859 860 To declare the code location, an import path of the form 861 862 repository.vcs/path 863 864 specifies the given repository, with or without the .vcs suffix, 865 using the named version control system, and then the path inside 866 that repository. The supported version control systems are: 867 868 Bazaar .bzr 869 Git .git 870 Mercurial .hg 871 Subversion .svn 872 873 For example, 874 875 import "example.org/user/foo.hg" 876 877 denotes the root directory of the Mercurial repository at 878 example.org/user/foo or foo.hg, and 879 880 import "example.org/repo.git/foo/bar" 881 882 denotes the foo/bar directory of the Git repository at 883 example.org/repo or repo.git. 884 885 When a version control system supports multiple protocols, 886 each is tried in turn when downloading. For example, a Git 887 download tries git://, then https://, then http://. 888 889 If the import path is not a known code hosting site and also lacks a 890 version control qualifier, the go tool attempts to fetch the import 891 over https/http and looks for a <meta> tag in the document's HTML 892 <head>. 893 894 The meta tag has the form: 895 896 <meta name="go-import" content="import-prefix vcs repo-root"> 897 898 The import-prefix is the import path corresponding to the repository 899 root. It must be a prefix or an exact match of the package being 900 fetched with "go get". If it's not an exact match, another http 901 request is made at the prefix to verify the <meta> tags match. 902 903 The vcs is one of "git", "hg", "svn", etc, 904 905 The repo-root is the root of the version control system 906 containing a scheme and not containing a .vcs qualifier. 907 908 For example, 909 910 import "example.org/pkg/foo" 911 912 will result in the following request(s): 913 914 https://example.org/pkg/foo?go-get=1 (preferred) 915 http://example.org/pkg/foo?go-get=1 (fallback) 916 917 If that page contains the meta tag 918 919 <meta name="go-import" content="example.org git https://code.org/r/p/exproj"> 920 921 the go tool will verify that https://example.org/?go-get=1 contains the 922 same meta tag and then git clone https://code.org/r/p/exproj into 923 GOPATH/src/example.org. 924 925 New downloaded packages are written to the first directory 926 listed in the GOPATH environment variable (see 'go help gopath'). 927 928 The go command attempts to download the version of the 929 package appropriate for the Go release being used. 930 Run 'go help get' for more. 931 932 Import path checking 933 934 When the custom import path feature described above redirects to a 935 known code hosting site, each of the resulting packages has two possible 936 import paths, using the custom domain or the known hosting site. 937 938 A package statement is said to have an "import comment" if it is immediately 939 followed (before the next newline) by a comment of one of these two forms: 940 941 package math // import "path" 942 package math /* import "path" * / 943 944 The go command will refuse to install a package with an import comment 945 unless it is being referred to by that import path. In this way, import comments 946 let package authors make sure the custom import path is used and not a 947 direct path to the underlying code hosting site. 948 949 See https://golang.org/s/go14customimport for details. 950 951 952 Description of package lists 953 954 Many commands apply to a set of packages: 955 956 go action [packages] 957 958 Usually, [packages] is a list of import paths. 959 960 An import path that is a rooted path or that begins with 961 a . or .. element is interpreted as a file system path and 962 denotes the package in that directory. 963 964 Otherwise, the import path P denotes the package found in 965 the directory DIR/src/P for some DIR listed in the GOPATH 966 environment variable (see 'go help gopath'). 967 968 If no import paths are given, the action applies to the 969 package in the current directory. 970 971 There are three reserved names for paths that should not be used 972 for packages to be built with the go tool: 973 974 - "main" denotes the top-level package in a stand-alone executable. 975 976 - "all" expands to all package directories found in all the GOPATH 977 trees. For example, 'go list all' lists all the packages on the local 978 system. 979 980 - "std" is like all but expands to just the packages in the standard 981 Go library. 982 983 - "cmd" expands to the Go repository's commands and their 984 internal libraries. 985 986 An import path is a pattern if it includes one or more "..." wildcards, 987 each of which can match any string, including the empty string and 988 strings containing slashes. Such a pattern expands to all package 989 directories found in the GOPATH trees with names matching the 990 patterns. As a special case, x/... matches x as well as x's subdirectories. 991 For example, net/... expands to net and packages in its subdirectories. 992 993 An import path can also name a package to be downloaded from 994 a remote repository. Run 'go help importpath' for details. 995 996 Every package in a program must have a unique import path. 997 By convention, this is arranged by starting each path with a 998 unique prefix that belongs to you. For example, paths used 999 internally at Google all begin with 'google', and paths 1000 denoting remote repositories begin with the path to the code, 1001 such as 'code.google.com/p/project'. 1002 1003 As a special case, if the package list is a list of .go files from a 1004 single directory, the command is applied to a single synthesized 1005 package made up of exactly those files, ignoring any build constraints 1006 in those files and ignoring any other files in the directory. 1007 1008 Directory and file names that begin with "." or "_" are ignored 1009 by the go tool, as are directories named "testdata". 1010 1011 1012 Description of testing flags 1013 1014 The 'go test' command takes both flags that apply to 'go test' itself 1015 and flags that apply to the resulting test binary. 1016 1017 Several of the flags control profiling and write an execution profile 1018 suitable for "go tool pprof"; run "go tool pprof help" for more 1019 information. The --alloc_space, --alloc_objects, and --show_bytes 1020 options of pprof control how the information is presented. 1021 1022 The following flags are recognized by the 'go test' command and 1023 control the execution of any test: 1024 1025 -bench regexp 1026 Run benchmarks matching the regular expression. 1027 By default, no benchmarks run. To run all benchmarks, 1028 use '-bench .' or '-bench=.'. 1029 1030 -benchmem 1031 Print memory allocation statistics for benchmarks. 1032 1033 -benchtime t 1034 Run enough iterations of each benchmark to take t, specified 1035 as a time.Duration (for example, -benchtime 1h30s). 1036 The default is 1 second (1s). 1037 1038 -blockprofile block.out 1039 Write a goroutine blocking profile to the specified file 1040 when all tests are complete. 1041 Writes test binary as -c would. 1042 1043 -blockprofilerate n 1044 Control the detail provided in goroutine blocking profiles by 1045 calling runtime.SetBlockProfileRate with n. 1046 See 'godoc runtime SetBlockProfileRate'. 1047 The profiler aims to sample, on average, one blocking event every 1048 n nanoseconds the program spends blocked. By default, 1049 if -test.blockprofile is set without this flag, all blocking events 1050 are recorded, equivalent to -test.blockprofilerate=1. 1051 1052 -cover 1053 Enable coverage analysis. 1054 1055 -covermode set,count,atomic 1056 Set the mode for coverage analysis for the package[s] 1057 being tested. The default is "set" unless -race is enabled, 1058 in which case it is "atomic". 1059 The values: 1060 set: bool: does this statement run? 1061 count: int: how many times does this statement run? 1062 atomic: int: count, but correct in multithreaded tests; 1063 significantly more expensive. 1064 Sets -cover. 1065 1066 -coverpkg pkg1,pkg2,pkg3 1067 Apply coverage analysis in each test to the given list of packages. 1068 The default is for each test to analyze only the package being tested. 1069 Packages are specified as import paths. 1070 Sets -cover. 1071 1072 -coverprofile cover.out 1073 Write a coverage profile to the file after all tests have passed. 1074 Sets -cover. 1075 1076 -cpu 1,2,4 1077 Specify a list of GOMAXPROCS values for which the tests or 1078 benchmarks should be executed. The default is the current value 1079 of GOMAXPROCS. 1080 1081 -cpuprofile cpu.out 1082 Write a CPU profile to the specified file before exiting. 1083 Writes test binary as -c would. 1084 1085 -memprofile mem.out 1086 Write a memory profile to the file after all tests have passed. 1087 Writes test binary as -c would. 1088 1089 -memprofilerate n 1090 Enable more precise (and expensive) memory profiles by setting 1091 runtime.MemProfileRate. See 'godoc runtime MemProfileRate'. 1092 To profile all memory allocations, use -test.memprofilerate=1 1093 and pass --alloc_space flag to the pprof tool. 1094 1095 -outputdir directory 1096 Place output files from profiling in the specified directory, 1097 by default the directory in which "go test" is running. 1098 1099 -parallel n 1100 Allow parallel execution of test functions that call t.Parallel. 1101 The value of this flag is the maximum number of tests to run 1102 simultaneously; by default, it is set to the value of GOMAXPROCS. 1103 1104 -run regexp 1105 Run only those tests and examples matching the regular 1106 expression. 1107 1108 -short 1109 Tell long-running tests to shorten their run time. 1110 It is off by default but set during all.bash so that installing 1111 the Go tree can run a sanity check but not spend time running 1112 exhaustive tests. 1113 1114 -timeout t 1115 If a test runs longer than t, panic. 1116 1117 -trace trace.out 1118 Write an execution trace to the specified file before exiting. 1119 Writes test binary as -c would. 1120 1121 -v 1122 Verbose output: log all tests as they are run. Also print all 1123 text from Log and Logf calls even if the test succeeds. 1124 1125 The test binary, called pkg.test where pkg is the name of the 1126 directory containing the package sources, can be invoked directly 1127 after building it with 'go test -c'. When invoking the test binary 1128 directly, each of the standard flag names must be prefixed with 'test.', 1129 as in -test.run=TestMyFunc or -test.v. 1130 1131 When running 'go test', flags not listed above are passed through 1132 unaltered. For instance, the command 1133 1134 go test -x -v -cpuprofile=prof.out -dir=testdata -update 1135 1136 will compile the test binary and then run it as 1137 1138 pkg.test -test.v -test.cpuprofile=prof.out -dir=testdata -update 1139 1140 The test flags that generate profiles (other than for coverage) also 1141 leave the test binary in pkg.test for use when analyzing the profiles. 1142 1143 Flags not recognized by 'go test' must be placed after any specified packages. 1144 1145 1146 Description of testing functions 1147 1148 The 'go test' command expects to find test, benchmark, and example functions 1149 in the "*_test.go" files corresponding to the package under test. 1150 1151 A test function is one named TestXXX (where XXX is any alphanumeric string 1152 not starting with a lower case letter) and should have the signature, 1153 1154 func TestXXX(t *testing.T) { ... } 1155 1156 A benchmark function is one named BenchmarkXXX and should have the signature, 1157 1158 func BenchmarkXXX(b *testing.B) { ... } 1159 1160 An example function is similar to a test function but, instead of using 1161 *testing.T to report success or failure, prints output to os.Stdout. 1162 That output is compared against the function's "Output:" comment, which 1163 must be the last comment in the function body (see example below). An 1164 example with no such comment, or with no text after "Output:" is compiled 1165 but not executed. 1166 1167 Godoc displays the body of ExampleXXX to demonstrate the use 1168 of the function, constant, or variable XXX. An example of a method M with 1169 receiver type T or *T is named ExampleT_M. There may be multiple examples 1170 for a given function, constant, or variable, distinguished by a trailing _xxx, 1171 where xxx is a suffix not beginning with an upper case letter. 1172 1173 Here is an example of an example: 1174 1175 func ExamplePrintln() { 1176 Println("The output of\nthis example.") 1177 // Output: The output of 1178 // this example. 1179 } 1180 1181 The entire test file is presented as the example when it contains a single 1182 example function, at least one other function, type, variable, or constant 1183 declaration, and no test or benchmark functions. 1184 1185 See the documentation of the testing package for more information. 1186 1187 1188 */ 1189 package main