github.com/xushiwei/go@v0.0.0-20130601165731-2b9d83f45bc9/src/cmd/go/help.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 package main 6 7 var helpPackages = &Command{ 8 UsageLine: "packages", 9 Short: "description of package lists", 10 Long: ` 11 Many commands apply to a set of packages: 12 13 go action [packages] 14 15 Usually, [packages] is a list of import paths. 16 17 An import path that is a rooted path or that begins with 18 a . or .. element is interpreted as a file system path and 19 denotes the package in that directory. 20 21 Otherwise, the import path P denotes the package found in 22 the directory DIR/src/P for some DIR listed in the GOPATH 23 environment variable (see 'go help gopath'). 24 25 If no import paths are given, the action applies to the 26 package in the current directory. 27 28 The special import path "all" expands to all package directories 29 found in all the GOPATH trees. For example, 'go list all' 30 lists all the packages on the local system. 31 32 The special import path "std" is like all but expands to just the 33 packages in the standard Go library. 34 35 An import path is a pattern if it includes one or more "..." wildcards, 36 each of which can match any string, including the empty string and 37 strings containing slashes. Such a pattern expands to all package 38 directories found in the GOPATH trees with names matching the 39 patterns. As a special case, x/... matches x as well as x's subdirectories. 40 For example, net/... expands to net and packages in its subdirectories. 41 42 An import path can also name a package to be downloaded from 43 a remote repository. Run 'go help remote' for details. 44 45 Every package in a program must have a unique import path. 46 By convention, this is arranged by starting each path with a 47 unique prefix that belongs to you. For example, paths used 48 internally at Google all begin with 'google', and paths 49 denoting remote repositories begin with the path to the code, 50 such as 'code.google.com/p/project'. 51 52 As a special case, if the package list is a list of .go files from a 53 single directory, the command is applied to a single synthesized 54 package made up of exactly those files, ignoring any build constraints 55 in those files and ignoring any other files in the directory. 56 `, 57 } 58 59 var helpRemote = &Command{ 60 UsageLine: "remote", 61 Short: "remote import path syntax", 62 Long: ` 63 64 An import path (see 'go help packages') denotes a package 65 stored in the local file system. Certain import paths also 66 describe how to obtain the source code for the package using 67 a revision control system. 68 69 A few common code hosting sites have special syntax: 70 71 Bitbucket (Git, Mercurial) 72 73 import "bitbucket.org/user/project" 74 import "bitbucket.org/user/project/sub/directory" 75 76 GitHub (Git) 77 78 import "github.com/user/project" 79 import "github.com/user/project/sub/directory" 80 81 Google Code Project Hosting (Git, Mercurial, Subversion) 82 83 import "code.google.com/p/project" 84 import "code.google.com/p/project/sub/directory" 85 86 import "code.google.com/p/project.subrepository" 87 import "code.google.com/p/project.subrepository/sub/directory" 88 89 Launchpad (Bazaar) 90 91 import "launchpad.net/project" 92 import "launchpad.net/project/series" 93 import "launchpad.net/project/series/sub/directory" 94 95 import "launchpad.net/~user/project/branch" 96 import "launchpad.net/~user/project/branch/sub/directory" 97 98 For code hosted on other servers, import paths may either be qualified 99 with the version control type, or the go tool can dynamically fetch 100 the import path over https/http and discover where the code resides 101 from a <meta> tag in the HTML. 102 103 To declare the code location, an import path of the form 104 105 repository.vcs/path 106 107 specifies the given repository, with or without the .vcs suffix, 108 using the named version control system, and then the path inside 109 that repository. The supported version control systems are: 110 111 Bazaar .bzr 112 Git .git 113 Mercurial .hg 114 Subversion .svn 115 116 For example, 117 118 import "example.org/user/foo.hg" 119 120 denotes the root directory of the Mercurial repository at 121 example.org/user/foo or foo.hg, and 122 123 import "example.org/repo.git/foo/bar" 124 125 denotes the foo/bar directory of the Git repository at 126 example.com/repo or repo.git. 127 128 When a version control system supports multiple protocols, 129 each is tried in turn when downloading. For example, a Git 130 download tries git://, then https://, then http://. 131 132 If the import path is not a known code hosting site and also lacks a 133 version control qualifier, the go tool attempts to fetch the import 134 over https/http and looks for a <meta> tag in the document's HTML 135 <head>. 136 137 The meta tag has the form: 138 139 <meta name="go-import" content="import-prefix vcs repo-root"> 140 141 The import-prefix is the import path corresponding to the repository 142 root. It must be a prefix or an exact match of the package being 143 fetched with "go get". If it's not an exact match, another http 144 request is made at the prefix to verify the <meta> tags match. 145 146 The vcs is one of "git", "hg", "svn", etc, 147 148 The repo-root is the root of the version control system 149 containing a scheme and not containing a .vcs qualifier. 150 151 For example, 152 153 import "example.org/pkg/foo" 154 155 will result in the following request(s): 156 157 https://example.org/pkg/foo?go-get=1 (preferred) 158 http://example.org/pkg/foo?go-get=1 (fallback) 159 160 If that page contains the meta tag 161 162 <meta name="go-import" content="example.org git https://code.org/r/p/exproj"> 163 164 the go tool will verify that https://example.org/?go-get=1 contains the 165 same meta tag and then git clone https://code.org/r/p/exproj into 166 GOPATH/src/example.org. 167 168 New downloaded packages are written to the first directory 169 listed in the GOPATH environment variable (see 'go help gopath'). 170 171 The go command attempts to download the version of the 172 package appropriate for the Go release being used. 173 Run 'go help install' for more. 174 `, 175 } 176 177 var helpGopath = &Command{ 178 UsageLine: "gopath", 179 Short: "GOPATH environment variable", 180 Long: ` 181 The Go path is used to resolve import statements. 182 It is implemented by and documented in the go/build package. 183 184 The GOPATH environment variable lists places to look for Go code. 185 On Unix, the value is a colon-separated string. 186 On Windows, the value is a semicolon-separated string. 187 On Plan 9, the value is a list. 188 189 GOPATH must be set to get, build and install packages outside the 190 standard Go tree. 191 192 Each directory listed in GOPATH must have a prescribed structure: 193 194 The src/ directory holds source code. The path below 'src' 195 determines the import path or executable name. 196 197 The pkg/ directory holds installed package objects. 198 As in the Go tree, each target operating system and 199 architecture pair has its own subdirectory of pkg 200 (pkg/GOOS_GOARCH). 201 202 If DIR is a directory listed in the GOPATH, a package with 203 source in DIR/src/foo/bar can be imported as "foo/bar" and 204 has its compiled form installed to "DIR/pkg/GOOS_GOARCH/foo/bar.a". 205 206 The bin/ directory holds compiled commands. 207 Each command is named for its source directory, but only 208 the final element, not the entire path. That is, the 209 command with source in DIR/src/foo/quux is installed into 210 DIR/bin/quux, not DIR/bin/foo/quux. The foo/ is stripped 211 so that you can add DIR/bin to your PATH to get at the 212 installed commands. If the GOBIN environment variable is 213 set, commands are installed to the directory it names instead 214 of DIR/bin. 215 216 Here's an example directory layout: 217 218 GOPATH=/home/user/gocode 219 220 /home/user/gocode/ 221 src/ 222 foo/ 223 bar/ (go code in package bar) 224 x.go 225 quux/ (go code in package main) 226 y.go 227 bin/ 228 quux (installed command) 229 pkg/ 230 linux_amd64/ 231 foo/ 232 bar.a (installed package object) 233 234 Go searches each directory listed in GOPATH to find source code, 235 but new packages are always downloaded into the first directory 236 in the list. 237 `, 238 }