tmpl.go 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991
  1. // Copyright 2017 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. // +build h2demo
  5. package main
  6. import "html/template"
  7. var pushTmpl = template.Must(template.New("serverpush").Parse(`
  8. <!DOCTYPE html>
  9. <html>
  10. <head>
  11. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  12. <meta name="viewport" content="width=device-width, initial-scale=1">
  13. <meta name="theme-color" content="#375EAB">
  14. <title>HTTP/2 Server Push Demo</title>
  15. <link type="text/css" rel="stylesheet" href="/serverpush/static/style.css?{{.CacheBust}}">
  16. <script>
  17. window.initFuncs = [];
  18. </script>
  19. <script>
  20. function showtimes() {
  21. var times = 'DOM loaded: ' + (window.performance.timing.domContentLoadedEventEnd - window.performance.timing.navigationStart) + 'ms, '
  22. times += 'DOM complete (all loaded): ' + (window.performance.timing.domComplete - window.performance.timing.navigationStart) + 'ms, '
  23. times += 'Load event fired: ' + (window.performance.timing.loadEventStart - window.performance.timing.navigationStart) + 'ms'
  24. document.getElementById('loadtimes').innerHTML = times
  25. }
  26. </script>
  27. </head>
  28. <body onload="showtimes()">
  29. <div style="background:#fff9a4;padding:10px">
  30. Note: This page exists for demonstration purposes. For the actual cmd/go docs, go to <a href="golang.org/cmd/go">golang.org/cmd/go</a>.
  31. </div>
  32. <div style="padding:20px">
  33. <a href="https://{{.HTTPSHost}}/serverpush">HTTP/2 with Server Push</a> | <a href="{{.HTTP1Prefix}}/serverpush">HTTP only</a>
  34. <div id="loadtimes"></div>
  35. </div>
  36. <div id='lowframe' style="position: fixed; bottom: 0; left: 0; height: 0; width: 100%; border-top: thin solid grey; background-color: white; overflow: auto;">
  37. ...
  38. </div><!-- #lowframe -->
  39. <div id="topbar" class="wide"><div class="container">
  40. <div class="top-heading" id="heading-wide"><a href="/">The Go Programming Language</a></div>
  41. <div class="top-heading" id="heading-narrow"><a href="/">Go</a></div>
  42. <a href="#" id="menu-button"><span id="menu-button-arrow">&#9661;</span></a>
  43. <form method="GET" action="/search">
  44. <div id="menu">
  45. <a href="/doc/">Documents</a>
  46. <a href="/pkg/">Packages</a>
  47. <a href="/project/">The Project</a>
  48. <a href="/help/">Help</a>
  49. <a href="/blog/">Blog</a>
  50. <a id="playgroundButton" href="http://play.golang.org/" title="Show Go Playground">Play</a>
  51. <input type="text" id="search" name="q" class="inactive" value="Search" placeholder="Search">
  52. </div>
  53. </form>
  54. </div></div>
  55. <div id="playground" class="play">
  56. <div class="input"><textarea class="code" spellcheck="false">package main
  57. import "fmt"
  58. func main() {
  59. fmt.Println("Hello, 世界")
  60. }</textarea></div>
  61. <div class="output"></div>
  62. <div class="buttons">
  63. <a class="run" title="Run this code [shift-enter]">Run</a>
  64. <a class="fmt" title="Format this code">Format</a>
  65. <a class="share" title="Share this code">Share</a>
  66. </div>
  67. </div>
  68. <div id="page" class="wide">
  69. <div class="container">
  70. <h1>Command go</h1>
  71. <div id="nav"></div>
  72. <!--
  73. Copyright 2009 The Go Authors. All rights reserved.
  74. Use of this source code is governed by a BSD-style
  75. license that can be found in the LICENSE file.
  76. -->
  77. <!--
  78. Note: Static (i.e., not template-generated) href and id
  79. attributes start with "pkg-" to make it impossible for
  80. them to conflict with generated attributes (some of which
  81. correspond to Go identifiers).
  82. -->
  83. <script type='text/javascript'>
  84. document.ANALYSIS_DATA = null;
  85. document.CALLGRAPH = null;
  86. </script>
  87. <p>
  88. Go is a tool for managing Go source code.
  89. </p>
  90. <p>
  91. Usage:
  92. </p>
  93. <pre>go command [arguments]
  94. </pre>
  95. <p>
  96. The commands are:
  97. </p>
  98. <pre>build compile packages and dependencies
  99. clean remove object files
  100. doc show documentation for package or symbol
  101. env print Go environment information
  102. bug start a bug report
  103. fix run go tool fix on packages
  104. fmt run gofmt on package sources
  105. generate generate Go files by processing source
  106. get download and install packages and dependencies
  107. install compile and install packages and dependencies
  108. list list packages
  109. run compile and run Go program
  110. test test packages
  111. tool run specified go tool
  112. version print Go version
  113. vet run go tool vet on packages
  114. </pre>
  115. <p>
  116. Use &#34;go help [command]&#34; for more information about a command.
  117. </p>
  118. <p>
  119. Additional help topics:
  120. </p>
  121. <pre>c calling between Go and C
  122. buildmode description of build modes
  123. filetype file types
  124. gopath GOPATH environment variable
  125. environment environment variables
  126. importpath import path syntax
  127. packages description of package lists
  128. testflag description of testing flags
  129. testfunc description of testing functions
  130. </pre>
  131. <p>
  132. Use &#34;go help [topic]&#34; for more information about that topic.
  133. </p>
  134. <h3 id="hdr-Compile_packages_and_dependencies">Compile packages and dependencies</h3>
  135. <p>
  136. Usage:
  137. </p>
  138. <pre>go build [-o output] [-i] [build flags] [packages]
  139. </pre>
  140. <p>
  141. Build compiles the packages named by the import paths,
  142. along with their dependencies, but it does not install the results.
  143. </p>
  144. <p>
  145. If the arguments to build are a list of .go files, build treats
  146. them as a list of source files specifying a single package.
  147. </p>
  148. <p>
  149. When compiling a single main package, build writes
  150. the resulting executable to an output file named after
  151. the first source file (&#39;go build ed.go rx.go&#39; writes &#39;ed&#39; or &#39;ed.exe&#39;)
  152. or the source code directory (&#39;go build unix/sam&#39; writes &#39;sam&#39; or &#39;sam.exe&#39;).
  153. The &#39;.exe&#39; suffix is added when writing a Windows executable.
  154. </p>
  155. <p>
  156. When compiling multiple packages or a single non-main package,
  157. build compiles the packages but discards the resulting object,
  158. serving only as a check that the packages can be built.
  159. </p>
  160. <p>
  161. When compiling packages, build ignores files that end in &#39;_test.go&#39;.
  162. </p>
  163. <p>
  164. The -o flag, only allowed when compiling a single package,
  165. forces build to write the resulting executable or object
  166. to the named output file, instead of the default behavior described
  167. in the last two paragraphs.
  168. </p>
  169. <p>
  170. The -i flag installs the packages that are dependencies of the target.
  171. </p>
  172. <p>
  173. The build flags are shared by the build, clean, get, install, list, run,
  174. and test commands:
  175. </p>
  176. <pre>-a
  177. force rebuilding of packages that are already up-to-date.
  178. -n
  179. print the commands but do not run them.
  180. -p n
  181. the number of programs, such as build commands or
  182. test binaries, that can be run in parallel.
  183. The default is the number of CPUs available.
  184. -race
  185. enable data race detection.
  186. Supported only on linux/amd64, freebsd/amd64, darwin/amd64 and windows/amd64.
  187. -msan
  188. enable interoperation with memory sanitizer.
  189. Supported only on linux/amd64,
  190. and only with Clang/LLVM as the host C compiler.
  191. -v
  192. print the names of packages as they are compiled.
  193. -work
  194. print the name of the temporary work directory and
  195. do not delete it when exiting.
  196. -x
  197. print the commands.
  198. -asmflags &#39;flag list&#39;
  199. arguments to pass on each go tool asm invocation.
  200. -buildmode mode
  201. build mode to use. See &#39;go help buildmode&#39; for more.
  202. -compiler name
  203. name of compiler to use, as in runtime.Compiler (gccgo or gc).
  204. -gccgoflags &#39;arg list&#39;
  205. arguments to pass on each gccgo compiler/linker invocation.
  206. -gcflags &#39;arg list&#39;
  207. arguments to pass on each go tool compile invocation.
  208. -installsuffix suffix
  209. a suffix to use in the name of the package installation directory,
  210. in order to keep output separate from default builds.
  211. If using the -race flag, the install suffix is automatically set to race
  212. or, if set explicitly, has _race appended to it. Likewise for the -msan
  213. flag. Using a -buildmode option that requires non-default compile flags
  214. has a similar effect.
  215. -ldflags &#39;flag list&#39;
  216. arguments to pass on each go tool link invocation.
  217. -linkshared
  218. link against shared libraries previously created with
  219. -buildmode=shared.
  220. -pkgdir dir
  221. install and load all packages from dir instead of the usual locations.
  222. For example, when building with a non-standard configuration,
  223. use -pkgdir to keep generated packages in a separate location.
  224. -tags &#39;tag list&#39;
  225. a list of build tags to consider satisfied during the build.
  226. For more information about build tags, see the description of
  227. build constraints in the documentation for the go/build package.
  228. -toolexec &#39;cmd args&#39;
  229. a program to use to invoke toolchain programs like vet and asm.
  230. For example, instead of running asm, the go command will run
  231. &#39;cmd args /path/to/asm &lt;arguments for asm&gt;&#39;.
  232. </pre>
  233. <p>
  234. The list flags accept a space-separated list of strings. To embed spaces
  235. in an element in the list, surround it with either single or double quotes.
  236. </p>
  237. <p>
  238. For more about specifying packages, see &#39;go help packages&#39;.
  239. For more about where packages and binaries are installed,
  240. run &#39;go help gopath&#39;.
  241. For more about calling between Go and C/C++, run &#39;go help c&#39;.
  242. </p>
  243. <p>
  244. Note: Build adheres to certain conventions such as those described
  245. by &#39;go help gopath&#39;. Not all projects can follow these conventions,
  246. however. Installations that have their own conventions or that use
  247. a separate software build system may choose to use lower-level
  248. invocations such as &#39;go tool compile&#39; and &#39;go tool link&#39; to avoid
  249. some of the overheads and design decisions of the build tool.
  250. </p>
  251. <p>
  252. See also: go install, go get, go clean.
  253. </p>
  254. <h3 id="hdr-Remove_object_files">Remove object files</h3>
  255. <p>
  256. Usage:
  257. </p>
  258. <pre>go clean [-i] [-r] [-n] [-x] [build flags] [packages]
  259. </pre>
  260. <p>
  261. Clean removes object files from package source directories.
  262. The go command builds most objects in a temporary directory,
  263. so go clean is mainly concerned with object files left by other
  264. tools or by manual invocations of go build.
  265. </p>
  266. <p>
  267. Specifically, clean removes the following files from each of the
  268. source directories corresponding to the import paths:
  269. </p>
  270. <pre>_obj/ old object directory, left from Makefiles
  271. _test/ old test directory, left from Makefiles
  272. _testmain.go old gotest file, left from Makefiles
  273. test.out old test log, left from Makefiles
  274. build.out old test log, left from Makefiles
  275. *.[568ao] object files, left from Makefiles
  276. DIR(.exe) from go build
  277. DIR.test(.exe) from go test -c
  278. MAINFILE(.exe) from go build MAINFILE.go
  279. *.so from SWIG
  280. </pre>
  281. <p>
  282. In the list, DIR represents the final path element of the
  283. directory, and MAINFILE is the base name of any Go source
  284. file in the directory that is not included when building
  285. the package.
  286. </p>
  287. <p>
  288. The -i flag causes clean to remove the corresponding installed
  289. archive or binary (what &#39;go install&#39; would create).
  290. </p>
  291. <p>
  292. The -n flag causes clean to print the remove commands it would execute,
  293. but not run them.
  294. </p>
  295. <p>
  296. The -r flag causes clean to be applied recursively to all the
  297. dependencies of the packages named by the import paths.
  298. </p>
  299. <p>
  300. The -x flag causes clean to print remove commands as it executes them.
  301. </p>
  302. <p>
  303. For more about build flags, see &#39;go help build&#39;.
  304. </p>
  305. <p>
  306. For more about specifying packages, see &#39;go help packages&#39;.
  307. </p>
  308. <h3 id="hdr-Show_documentation_for_package_or_symbol">Show documentation for package or symbol</h3>
  309. <p>
  310. Usage:
  311. </p>
  312. <pre>go doc [-u] [-c] [package|[package.]symbol[.method]]
  313. </pre>
  314. <p>
  315. Doc prints the documentation comments associated with the item identified by its
  316. arguments (a package, const, func, type, var, or method) followed by a one-line
  317. summary of each of the first-level items &#34;under&#34; that item (package-level
  318. declarations for a package, methods for a type, etc.).
  319. </p>
  320. <p>
  321. Doc accepts zero, one, or two arguments.
  322. </p>
  323. <p>
  324. Given no arguments, that is, when run as
  325. </p>
  326. <pre>go doc
  327. </pre>
  328. <p>
  329. it prints the package documentation for the package in the current directory.
  330. If the package is a command (package main), the exported symbols of the package
  331. are elided from the presentation unless the -cmd flag is provided.
  332. </p>
  333. <p>
  334. When run with one argument, the argument is treated as a Go-syntax-like
  335. representation of the item to be documented. What the argument selects depends
  336. on what is installed in GOROOT and GOPATH, as well as the form of the argument,
  337. which is schematically one of these:
  338. </p>
  339. <pre>go doc &lt;pkg&gt;
  340. go doc &lt;sym&gt;[.&lt;method&gt;]
  341. go doc [&lt;pkg&gt;.]&lt;sym&gt;[.&lt;method&gt;]
  342. go doc [&lt;pkg&gt;.][&lt;sym&gt;.]&lt;method&gt;
  343. </pre>
  344. <p>
  345. The first item in this list matched by the argument is the one whose documentation
  346. is printed. (See the examples below.) However, if the argument starts with a capital
  347. letter it is assumed to identify a symbol or method in the current directory.
  348. </p>
  349. <p>
  350. For packages, the order of scanning is determined lexically in breadth-first order.
  351. That is, the package presented is the one that matches the search and is nearest
  352. the root and lexically first at its level of the hierarchy. The GOROOT tree is
  353. always scanned in its entirety before GOPATH.
  354. </p>
  355. <p>
  356. If there is no package specified or matched, the package in the current
  357. directory is selected, so &#34;go doc Foo&#34; shows the documentation for symbol Foo in
  358. the current package.
  359. </p>
  360. <p>
  361. The package path must be either a qualified path or a proper suffix of a
  362. path. The go tool&#39;s usual package mechanism does not apply: package path
  363. elements like . and ... are not implemented by go doc.
  364. </p>
  365. <p>
  366. When run with two arguments, the first must be a full package path (not just a
  367. suffix), and the second is a symbol or symbol and method; this is similar to the
  368. syntax accepted by godoc:
  369. </p>
  370. <pre>go doc &lt;pkg&gt; &lt;sym&gt;[.&lt;method&gt;]
  371. </pre>
  372. <p>
  373. In all forms, when matching symbols, lower-case letters in the argument match
  374. either case but upper-case letters match exactly. This means that there may be
  375. multiple matches of a lower-case argument in a package if different symbols have
  376. different cases. If this occurs, documentation for all matches is printed.
  377. </p>
  378. <p>
  379. Examples:
  380. </p>
  381. <pre>go doc
  382. Show documentation for current package.
  383. go doc Foo
  384. Show documentation for Foo in the current package.
  385. (Foo starts with a capital letter so it cannot match
  386. a package path.)
  387. go doc encoding/json
  388. Show documentation for the encoding/json package.
  389. go doc json
  390. Shorthand for encoding/json.
  391. go doc json.Number (or go doc json.number)
  392. Show documentation and method summary for json.Number.
  393. go doc json.Number.Int64 (or go doc json.number.int64)
  394. Show documentation for json.Number&#39;s Int64 method.
  395. go doc cmd/doc
  396. Show package docs for the doc command.
  397. go doc -cmd cmd/doc
  398. Show package docs and exported symbols within the doc command.
  399. go doc template.new
  400. Show documentation for html/template&#39;s New function.
  401. (html/template is lexically before text/template)
  402. go doc text/template.new # One argument
  403. Show documentation for text/template&#39;s New function.
  404. go doc text/template new # Two arguments
  405. Show documentation for text/template&#39;s New function.
  406. At least in the current tree, these invocations all print the
  407. documentation for json.Decoder&#39;s Decode method:
  408. go doc json.Decoder.Decode
  409. go doc json.decoder.decode
  410. go doc json.decode
  411. cd go/src/encoding/json; go doc decode
  412. </pre>
  413. <p>
  414. Flags:
  415. </p>
  416. <pre>-c
  417. Respect case when matching symbols.
  418. -cmd
  419. Treat a command (package main) like a regular package.
  420. Otherwise package main&#39;s exported symbols are hidden
  421. when showing the package&#39;s top-level documentation.
  422. -u
  423. Show documentation for unexported as well as exported
  424. symbols and methods.
  425. </pre>
  426. <h3 id="hdr-Print_Go_environment_information">Print Go environment information</h3>
  427. <p>
  428. Usage:
  429. </p>
  430. <pre>go env [var ...]
  431. </pre>
  432. <p>
  433. Env prints Go environment information.
  434. </p>
  435. <p>
  436. By default env prints information as a shell script
  437. (on Windows, a batch file). If one or more variable
  438. names is given as arguments, env prints the value of
  439. each named variable on its own line.
  440. </p>
  441. <h3 id="hdr-Start_a_bug_report">Start a bug report</h3>
  442. <p>
  443. Usage:
  444. </p>
  445. <pre>go bug
  446. </pre>
  447. <p>
  448. Bug opens the default browser and starts a new bug report.
  449. The report includes useful system information.
  450. </p>
  451. <h3 id="hdr-Run_go_tool_fix_on_packages">Run go tool fix on packages</h3>
  452. <p>
  453. Usage:
  454. </p>
  455. <pre>go fix [packages]
  456. </pre>
  457. <p>
  458. Fix runs the Go fix command on the packages named by the import paths.
  459. </p>
  460. <p>
  461. For more about fix, see &#39;go doc cmd/fix&#39;.
  462. For more about specifying packages, see &#39;go help packages&#39;.
  463. </p>
  464. <p>
  465. To run fix with specific options, run &#39;go tool fix&#39;.
  466. </p>
  467. <p>
  468. See also: go fmt, go vet.
  469. </p>
  470. <h3 id="hdr-Run_gofmt_on_package_sources">Run gofmt on package sources</h3>
  471. <p>
  472. Usage:
  473. </p>
  474. <pre>go fmt [-n] [-x] [packages]
  475. </pre>
  476. <p>
  477. Fmt runs the command &#39;gofmt -l -w&#39; on the packages named
  478. by the import paths. It prints the names of the files that are modified.
  479. </p>
  480. <p>
  481. For more about gofmt, see &#39;go doc cmd/gofmt&#39;.
  482. For more about specifying packages, see &#39;go help packages&#39;.
  483. </p>
  484. <p>
  485. The -n flag prints commands that would be executed.
  486. The -x flag prints commands as they are executed.
  487. </p>
  488. <p>
  489. To run gofmt with specific options, run gofmt itself.
  490. </p>
  491. <p>
  492. See also: go fix, go vet.
  493. </p>
  494. <h3 id="hdr-Generate_Go_files_by_processing_source">Generate Go files by processing source</h3>
  495. <p>
  496. Usage:
  497. </p>
  498. <pre>go generate [-run regexp] [-n] [-v] [-x] [build flags] [file.go... | packages]
  499. </pre>
  500. <p>
  501. Generate runs commands described by directives within existing
  502. files. Those commands can run any process but the intent is to
  503. create or update Go source files.
  504. </p>
  505. <p>
  506. Go generate is never run automatically by go build, go get, go test,
  507. and so on. It must be run explicitly.
  508. </p>
  509. <p>
  510. Go generate scans the file for directives, which are lines of
  511. the form,
  512. </p>
  513. <pre>//go:generate command argument...
  514. </pre>
  515. <p>
  516. (note: no leading spaces and no space in &#34;//go&#34;) where command
  517. is the generator to be run, corresponding to an executable file
  518. that can be run locally. It must either be in the shell path
  519. (gofmt), a fully qualified path (/usr/you/bin/mytool), or a
  520. command alias, described below.
  521. </p>
  522. <p>
  523. Note that go generate does not parse the file, so lines that look
  524. like directives in comments or multiline strings will be treated
  525. as directives.
  526. </p>
  527. <p>
  528. The arguments to the directive are space-separated tokens or
  529. double-quoted strings passed to the generator as individual
  530. arguments when it is run.
  531. </p>
  532. <p>
  533. Quoted strings use Go syntax and are evaluated before execution; a
  534. quoted string appears as a single argument to the generator.
  535. </p>
  536. <p>
  537. Go generate sets several variables when it runs the generator:
  538. </p>
  539. <pre>$GOARCH
  540. The execution architecture (arm, amd64, etc.)
  541. $GOOS
  542. The execution operating system (linux, windows, etc.)
  543. $GOFILE
  544. The base name of the file.
  545. $GOLINE
  546. The line number of the directive in the source file.
  547. $GOPACKAGE
  548. The name of the package of the file containing the directive.
  549. $DOLLAR
  550. A dollar sign.
  551. </pre>
  552. <p>
  553. Other than variable substitution and quoted-string evaluation, no
  554. special processing such as &#34;globbing&#34; is performed on the command
  555. line.
  556. </p>
  557. <p>
  558. As a last step before running the command, any invocations of any
  559. environment variables with alphanumeric names, such as $GOFILE or
  560. $HOME, are expanded throughout the command line. The syntax for
  561. variable expansion is $NAME on all operating systems. Due to the
  562. order of evaluation, variables are expanded even inside quoted
  563. strings. If the variable NAME is not set, $NAME expands to the
  564. empty string.
  565. </p>
  566. <p>
  567. A directive of the form,
  568. </p>
  569. <pre>//go:generate -command xxx args...
  570. </pre>
  571. <p>
  572. specifies, for the remainder of this source file only, that the
  573. string xxx represents the command identified by the arguments. This
  574. can be used to create aliases or to handle multiword generators.
  575. For example,
  576. </p>
  577. <pre>//go:generate -command foo go tool foo
  578. </pre>
  579. <p>
  580. specifies that the command &#34;foo&#34; represents the generator
  581. &#34;go tool foo&#34;.
  582. </p>
  583. <p>
  584. Generate processes packages in the order given on the command line,
  585. one at a time. If the command line lists .go files, they are treated
  586. as a single package. Within a package, generate processes the
  587. source files in a package in file name order, one at a time. Within
  588. a source file, generate runs generators in the order they appear
  589. in the file, one at a time.
  590. </p>
  591. <p>
  592. If any generator returns an error exit status, &#34;go generate&#34; skips
  593. all further processing for that package.
  594. </p>
  595. <p>
  596. The generator is run in the package&#39;s source directory.
  597. </p>
  598. <p>
  599. Go generate accepts one specific flag:
  600. </p>
  601. <pre>-run=&#34;&#34;
  602. if non-empty, specifies a regular expression to select
  603. directives whose full original source text (excluding
  604. any trailing spaces and final newline) matches the
  605. expression.
  606. </pre>
  607. <p>
  608. It also accepts the standard build flags including -v, -n, and -x.
  609. The -v flag prints the names of packages and files as they are
  610. processed.
  611. The -n flag prints commands that would be executed.
  612. The -x flag prints commands as they are executed.
  613. </p>
  614. <p>
  615. For more about build flags, see &#39;go help build&#39;.
  616. </p>
  617. <p>
  618. For more about specifying packages, see &#39;go help packages&#39;.
  619. </p>
  620. <h3 id="hdr-Download_and_install_packages_and_dependencies">Download and install packages and dependencies</h3>
  621. <p>
  622. Usage:
  623. </p>
  624. <pre>go get [-d] [-f] [-fix] [-insecure] [-t] [-u] [build flags] [packages]
  625. </pre>
  626. <p>
  627. Get downloads the packages named by the import paths, along with their
  628. dependencies. It then installs the named packages, like &#39;go install&#39;.
  629. </p>
  630. <p>
  631. The -d flag instructs get to stop after downloading the packages; that is,
  632. it instructs get not to install the packages.
  633. </p>
  634. <p>
  635. The -f flag, valid only when -u is set, forces get -u not to verify that
  636. each package has been checked out from the source control repository
  637. implied by its import path. This can be useful if the source is a local fork
  638. of the original.
  639. </p>
  640. <p>
  641. The -fix flag instructs get to run the fix tool on the downloaded packages
  642. before resolving dependencies or building the code.
  643. </p>
  644. <p>
  645. The -insecure flag permits fetching from repositories and resolving
  646. custom domains using insecure schemes such as HTTP. Use with caution.
  647. </p>
  648. <p>
  649. The -t flag instructs get to also download the packages required to build
  650. the tests for the specified packages.
  651. </p>
  652. <p>
  653. The -u flag instructs get to use the network to update the named packages
  654. and their dependencies. By default, get uses the network to check out
  655. missing packages but does not use it to look for updates to existing packages.
  656. </p>
  657. <p>
  658. The -v flag enables verbose progress and debug output.
  659. </p>
  660. <p>
  661. Get also accepts build flags to control the installation. See &#39;go help build&#39;.
  662. </p>
  663. <p>
  664. When checking out a new package, get creates the target directory
  665. GOPATH/src/&lt;import-path&gt;. If the GOPATH contains multiple entries,
  666. get uses the first one. For more details see: &#39;go help gopath&#39;.
  667. </p>
  668. <p>
  669. When checking out or updating a package, get looks for a branch or tag
  670. that matches the locally installed version of Go. The most important
  671. rule is that if the local installation is running version &#34;go1&#34;, get
  672. searches for a branch or tag named &#34;go1&#34;. If no such version exists it
  673. retrieves the most recent version of the package.
  674. </p>
  675. <p>
  676. When go get checks out or updates a Git repository,
  677. it also updates any git submodules referenced by the repository.
  678. </p>
  679. <p>
  680. Get never checks out or updates code stored in vendor directories.
  681. </p>
  682. <p>
  683. For more about specifying packages, see &#39;go help packages&#39;.
  684. </p>
  685. <p>
  686. For more about how &#39;go get&#39; finds source code to
  687. download, see &#39;go help importpath&#39;.
  688. </p>
  689. <p>
  690. See also: go build, go install, go clean.
  691. </p>
  692. <h3 id="hdr-Compile_and_install_packages_and_dependencies">Compile and install packages and dependencies</h3>
  693. <p>
  694. Usage:
  695. </p>
  696. <pre>go install [build flags] [packages]
  697. </pre>
  698. <p>
  699. Install compiles and installs the packages named by the import paths,
  700. along with their dependencies.
  701. </p>
  702. <p>
  703. For more about the build flags, see &#39;go help build&#39;.
  704. For more about specifying packages, see &#39;go help packages&#39;.
  705. </p>
  706. <p>
  707. See also: go build, go get, go clean.
  708. </p>
  709. <h3 id="hdr-List_packages">List packages</h3>
  710. <p>
  711. Usage:
  712. </p>
  713. <pre>go list [-e] [-f format] [-json] [build flags] [packages]
  714. </pre>
  715. <p>
  716. List lists the packages named by the import paths, one per line.
  717. </p>
  718. <p>
  719. The default output shows the package import path:
  720. </p>
  721. <pre>bytes
  722. encoding/json
  723. github.com/gorilla/mux
  724. golang.org/x/net/html
  725. </pre>
  726. <p>
  727. The -f flag specifies an alternate format for the list, using the
  728. syntax of package template. The default output is equivalent to -f
  729. &#39;&#39;. The struct being passed to the template is:
  730. </p>
  731. <pre>type Package struct {
  732. Dir string // directory containing package sources
  733. ImportPath string // import path of package in dir
  734. ImportComment string // path in import comment on package statement
  735. Name string // package name
  736. Doc string // package documentation string
  737. Target string // install path
  738. Shlib string // the shared library that contains this package (only set when -linkshared)
  739. Goroot bool // is this package in the Go root?
  740. Standard bool // is this package part of the standard Go library?
  741. Stale bool // would &#39;go install&#39; do anything for this package?
  742. StaleReason string // explanation for Stale==true
  743. Root string // Go root or Go path dir containing this package
  744. ConflictDir string // this directory shadows Dir in $GOPATH
  745. BinaryOnly bool // binary-only package: cannot be recompiled from sources
  746. // Source files
  747. GoFiles []string // .go source files (excluding CgoFiles, TestGoFiles, XTestGoFiles)
  748. CgoFiles []string // .go sources files that import &#34;C&#34;
  749. IgnoredGoFiles []string // .go sources ignored due to build constraints
  750. CFiles []string // .c source files
  751. CXXFiles []string // .cc, .cxx and .cpp source files
  752. MFiles []string // .m source files
  753. HFiles []string // .h, .hh, .hpp and .hxx source files
  754. FFiles []string // .f, .F, .for and .f90 Fortran source files
  755. SFiles []string // .s source files
  756. SwigFiles []string // .swig files
  757. SwigCXXFiles []string // .swigcxx files
  758. SysoFiles []string // .syso object files to add to archive
  759. TestGoFiles []string // _test.go files in package
  760. XTestGoFiles []string // _test.go files outside package
  761. // Cgo directives
  762. CgoCFLAGS []string // cgo: flags for C compiler
  763. CgoCPPFLAGS []string // cgo: flags for C preprocessor
  764. CgoCXXFLAGS []string // cgo: flags for C++ compiler
  765. CgoFFLAGS []string // cgo: flags for Fortran compiler
  766. CgoLDFLAGS []string // cgo: flags for linker
  767. CgoPkgConfig []string // cgo: pkg-config names
  768. // Dependency information
  769. Imports []string // import paths used by this package
  770. Deps []string // all (recursively) imported dependencies
  771. TestImports []string // imports from TestGoFiles
  772. XTestImports []string // imports from XTestGoFiles
  773. // Error information
  774. Incomplete bool // this package or a dependency has an error
  775. Error *PackageError // error loading package
  776. DepsErrors []*PackageError // errors loading dependencies
  777. }
  778. </pre>
  779. <p>
  780. Packages stored in vendor directories report an ImportPath that includes the
  781. path to the vendor directory (for example, &#34;d/vendor/p&#34; instead of &#34;p&#34;),
  782. so that the ImportPath uniquely identifies a given copy of a package.
  783. The Imports, Deps, TestImports, and XTestImports lists also contain these
  784. expanded imports paths. See golang.org/s/go15vendor for more about vendoring.
  785. </p>
  786. <p>
  787. The error information, if any, is
  788. </p>
  789. <pre>type PackageError struct {
  790. ImportStack []string // shortest path from package named on command line to this one
  791. Pos string // position of error (if present, file:line:col)
  792. Err string // the error itself
  793. }
  794. </pre>
  795. <p>
  796. The template function &#34;join&#34; calls strings.Join.
  797. </p>
  798. <p>
  799. The template function &#34;context&#34; returns the build context, defined as:
  800. </p>
  801. <pre>type Context struct {
  802. GOARCH string // target architecture
  803. GOOS string // target operating system
  804. GOROOT string // Go root
  805. GOPATH string // Go path
  806. CgoEnabled bool // whether cgo can be used
  807. UseAllFiles bool // use files regardless of +build lines, file names
  808. Compiler string // compiler to assume when computing target paths
  809. BuildTags []string // build constraints to match in +build lines
  810. ReleaseTags []string // releases the current release is compatible with
  811. InstallSuffix string // suffix to use in the name of the install dir
  812. }
  813. </pre>
  814. <p>
  815. For more information about the meaning of these fields see the documentation
  816. for the go/build package&#39;s Context type.
  817. </p>
  818. <p>
  819. The -json flag causes the package data to be printed in JSON format
  820. instead of using the template format.
  821. </p>
  822. <p>
  823. The -e flag changes the handling of erroneous packages, those that
  824. cannot be found or are malformed. By default, the list command
  825. prints an error to standard error for each erroneous package and
  826. omits the packages from consideration during the usual printing.
  827. With the -e flag, the list command never prints errors to standard
  828. error and instead processes the erroneous packages with the usual
  829. printing. Erroneous packages will have a non-empty ImportPath and
  830. a non-nil Error field; other information may or may not be missing
  831. (zeroed).
  832. </p>
  833. <p>
  834. For more about build flags, see &#39;go help build&#39;.
  835. </p>
  836. <p>
  837. For more about specifying packages, see &#39;go help packages&#39;.
  838. </p>
  839. <h3 id="hdr-Compile_and_run_Go_program">Compile and run Go program</h3>
  840. <p>
  841. Usage:
  842. </p>
  843. <pre>go run [build flags] [-exec xprog] gofiles... [arguments...]
  844. </pre>
  845. <p>
  846. Run compiles and runs the main package comprising the named Go source files.
  847. A Go source file is defined to be a file ending in a literal &#34;.go&#34; suffix.
  848. </p>
  849. <p>
  850. By default, &#39;go run&#39; runs the compiled binary directly: &#39;a.out arguments...&#39;.
  851. If the -exec flag is given, &#39;go run&#39; invokes the binary using xprog:
  852. </p>
  853. <pre>&#39;xprog a.out arguments...&#39;.
  854. </pre>
  855. <p>
  856. If the -exec flag is not given, GOOS or GOARCH is different from the system
  857. default, and a program named go_$GOOS_$GOARCH_exec can be found
  858. on the current search path, &#39;go run&#39; invokes the binary using that program,
  859. for example &#39;go_nacl_386_exec a.out arguments...&#39;. This allows execution of
  860. cross-compiled programs when a simulator or other execution method is
  861. available.
  862. </p>
  863. <p>
  864. For more about build flags, see &#39;go help build&#39;.
  865. </p>
  866. <p>
  867. See also: go build.
  868. </p>
  869. <h3 id="hdr-Test_packages">Test packages</h3>
  870. <p>
  871. Usage:
  872. </p>
  873. <pre>go test [build/test flags] [packages] [build/test flags &amp; test binary flags]
  874. </pre>
  875. <p>
  876. &#39;Go test&#39; automates testing the packages named by the import paths.
  877. It prints a summary of the test results in the format:
  878. </p>
  879. <pre>ok archive/tar 0.011s
  880. FAIL archive/zip 0.022s
  881. ok compress/gzip 0.033s
  882. ...
  883. </pre>
  884. <p>
  885. followed by detailed output for each failed package.
  886. </p>
  887. <p>
  888. &#39;Go test&#39; recompiles each package along with any files with names matching
  889. the file pattern &#34;*_test.go&#34;.
  890. Files whose names begin with &#34;_&#34; (including &#34;_test.go&#34;) or &#34;.&#34; are ignored.
  891. These additional files can contain test functions, benchmark functions, and
  892. example functions. See &#39;go help testfunc&#39; for more.
  893. Each listed package causes the execution of a separate test binary.
  894. </p>
  895. <p>
  896. Test files that declare a package with the suffix &#34;_test&#34; will be compiled as a
  897. separate package, and then linked and run with the main test binary.
  898. </p>
  899. <p>
  900. The go tool will ignore a directory named &#34;testdata&#34;, making it available
  901. to hold ancillary data needed by the tests.
  902. </p>
  903. <p>
  904. By default, go test needs no arguments. It compiles and tests the package
  905. with source in the current directory, including tests, and runs the tests.
  906. </p>
  907. <p>
  908. The package is built in a temporary directory so it does not interfere with the
  909. non-test installation.
  910. </p>
  911. <p>
  912. In addition to the build flags, the flags handled by &#39;go test&#39; itself are:
  913. </p>
  914. <pre>-args
  915. Pass the remainder of the command line (everything after -args)
  916. to the test binary, uninterpreted and unchanged.
  917. Because this flag consumes the remainder of the command line,
  918. the package list (if present) must appear before this flag.
  919. -c
  920. Compile the test binary to pkg.test but do not run it
  921. (where pkg is the last element of the package&#39;s import path).
  922. The file name can be changed with the -o flag.
  923. -exec xprog
  924. Run the test binary using xprog. The behavior is the same as
  925. in &#39;go run&#39;. See &#39;go help run&#39; for details.
  926. -i
  927. Install packages that are dependencies of the test.
  928. Do not run the test.
  929. -o file
  930. Compile the test binary to the named file.
  931. The test still runs (unless -c or -i is specified).
  932. </pre>
  933. <p>
  934. The test binary also accepts flags that control execution of the test; these
  935. flags are also accessible by &#39;go test&#39;. See &#39;go help testflag&#39; for details.
  936. </p>
  937. <p>
  938. For more about build flags, see &#39;go help build&#39;.
  939. For more about specifying packages, see &#39;go help packages&#39;.
  940. </p>
  941. <p>
  942. See also: go build, go vet.
  943. </p>
  944. <h3 id="hdr-Run_specified_go_tool">Run specified go tool</h3>
  945. <p>
  946. Usage:
  947. </p>
  948. <pre>go tool [-n] command [args...]
  949. </pre>
  950. <p>
  951. Tool runs the go tool command identified by the arguments.
  952. With no arguments it prints the list of known tools.
  953. </p>
  954. <p>
  955. The -n flag causes tool to print the command that would be
  956. executed but not execute it.
  957. </p>
  958. <p>
  959. For more about each tool command, see &#39;go tool command -h&#39;.
  960. </p>
  961. <h3 id="hdr-Print_Go_version">Print Go version</h3>
  962. <p>
  963. Usage:
  964. </p>
  965. <pre>go version
  966. </pre>
  967. <p>
  968. Version prints the Go version, as reported by runtime.Version.
  969. </p>
  970. <h3 id="hdr-Run_go_tool_vet_on_packages">Run go tool vet on packages</h3>
  971. <p>
  972. Usage:
  973. </p>
  974. <pre>go vet [-n] [-x] [build flags] [packages]
  975. </pre>
  976. <p>
  977. Vet runs the Go vet command on the packages named by the import paths.
  978. </p>
  979. <p>
  980. For more about vet, see &#39;go doc cmd/vet&#39;.
  981. For more about specifying packages, see &#39;go help packages&#39;.
  982. </p>
  983. <p>
  984. To run the vet tool with specific options, run &#39;go tool vet&#39;.
  985. </p>
  986. <p>
  987. The -n flag prints commands that would be executed.
  988. The -x flag prints commands as they are executed.
  989. </p>
  990. <p>
  991. For more about build flags, see &#39;go help build&#39;.
  992. </p>
  993. <p>
  994. See also: go fmt, go fix.
  995. </p>
  996. <h3 id="hdr-Calling_between_Go_and_C">Calling between Go and C</h3>
  997. <p>
  998. There are two different ways to call between Go and C/C++ code.
  999. </p>
  1000. <p>
  1001. The first is the cgo tool, which is part of the Go distribution. For
  1002. information on how to use it see the cgo documentation (go doc cmd/cgo).
  1003. </p>
  1004. <p>
  1005. The second is the SWIG program, which is a general tool for
  1006. interfacing between languages. For information on SWIG see
  1007. <a href="http://swig.org/">http://swig.org/</a>. When running go build, any file with a .swig
  1008. extension will be passed to SWIG. Any file with a .swigcxx extension
  1009. will be passed to SWIG with the -c++ option.
  1010. </p>
  1011. <p>
  1012. When either cgo or SWIG is used, go build will pass any .c, .m, .s,
  1013. or .S files to the C compiler, and any .cc, .cpp, .cxx files to the C++
  1014. compiler. The CC or CXX environment variables may be set to determine
  1015. the C or C++ compiler, respectively, to use.
  1016. </p>
  1017. <h3 id="hdr-Description_of_build_modes">Description of build modes</h3>
  1018. <p>
  1019. The &#39;go build&#39; and &#39;go install&#39; commands take a -buildmode argument which
  1020. indicates which kind of object file is to be built. Currently supported values
  1021. are:
  1022. </p>
  1023. <pre>-buildmode=archive
  1024. Build the listed non-main packages into .a files. Packages named
  1025. main are ignored.
  1026. -buildmode=c-archive
  1027. Build the listed main package, plus all packages it imports,
  1028. into a C archive file. The only callable symbols will be those
  1029. functions exported using a cgo //export comment. Requires
  1030. exactly one main package to be listed.
  1031. -buildmode=c-shared
  1032. Build the listed main packages, plus all packages that they
  1033. import, into C shared libraries. The only callable symbols will
  1034. be those functions exported using a cgo //export comment.
  1035. Non-main packages are ignored.
  1036. -buildmode=default
  1037. Listed main packages are built into executables and listed
  1038. non-main packages are built into .a files (the default
  1039. behavior).
  1040. -buildmode=shared
  1041. Combine all the listed non-main packages into a single shared
  1042. library that will be used when building with the -linkshared
  1043. option. Packages named main are ignored.
  1044. -buildmode=exe
  1045. Build the listed main packages and everything they import into
  1046. executables. Packages not named main are ignored.
  1047. -buildmode=pie
  1048. Build the listed main packages and everything they import into
  1049. position independent executables (PIE). Packages not named
  1050. main are ignored.
  1051. -buildmode=plugin
  1052. Build the listed main packages, plus all packages that they
  1053. import, into a Go plugin. Packages not named main are ignored.
  1054. </pre>
  1055. <h3 id="hdr-File_types">File types</h3>
  1056. <p>
  1057. The go command examines the contents of a restricted set of files
  1058. in each directory. It identifies which files to examine based on
  1059. the extension of the file name. These extensions are:
  1060. </p>
  1061. <pre>.go
  1062. Go source files.
  1063. .c, .h
  1064. C source files.
  1065. If the package uses cgo or SWIG, these will be compiled with the
  1066. OS-native compiler (typically gcc); otherwise they will
  1067. trigger an error.
  1068. .cc, .cpp, .cxx, .hh, .hpp, .hxx
  1069. C++ source files. Only useful with cgo or SWIG, and always
  1070. compiled with the OS-native compiler.
  1071. .m
  1072. Objective-C source files. Only useful with cgo, and always
  1073. compiled with the OS-native compiler.
  1074. .s, .S
  1075. Assembler source files.
  1076. If the package uses cgo or SWIG, these will be assembled with the
  1077. OS-native assembler (typically gcc (sic)); otherwise they
  1078. will be assembled with the Go assembler.
  1079. .swig, .swigcxx
  1080. SWIG definition files.
  1081. .syso
  1082. System object files.
  1083. </pre>
  1084. <p>
  1085. Files of each of these types except .syso may contain build
  1086. constraints, but the go command stops scanning for build constraints
  1087. at the first item in the file that is not a blank line or //-style
  1088. line comment. See the go/build package documentation for
  1089. more details.
  1090. </p>
  1091. <p>
  1092. Non-test Go source files can also include a //go:binary-only-package
  1093. comment, indicating that the package sources are included
  1094. for documentation only and must not be used to build the
  1095. package binary. This enables distribution of Go packages in
  1096. their compiled form alone. See the go/build package documentation
  1097. for more details.
  1098. </p>
  1099. <h3 id="hdr-GOPATH_environment_variable">GOPATH environment variable</h3>
  1100. <p>
  1101. The Go path is used to resolve import statements.
  1102. It is implemented by and documented in the go/build package.
  1103. </p>
  1104. <p>
  1105. The GOPATH environment variable lists places to look for Go code.
  1106. On Unix, the value is a colon-separated string.
  1107. On Windows, the value is a semicolon-separated string.
  1108. On Plan 9, the value is a list.
  1109. </p>
  1110. <p>
  1111. If the environment variable is unset, GOPATH defaults
  1112. to a subdirectory named &#34;go&#34; in the user&#39;s home directory
  1113. ($HOME/go on Unix, %USERPROFILE%\go on Windows),
  1114. unless that directory holds a Go distribution.
  1115. Run &#34;go env GOPATH&#34; to see the current GOPATH.
  1116. </p>
  1117. <p>
  1118. See <a href="https://golang.org/wiki/SettingGOPATH">https://golang.org/wiki/SettingGOPATH</a> to set a custom GOPATH.
  1119. </p>
  1120. <p>
  1121. Each directory listed in GOPATH must have a prescribed structure:
  1122. </p>
  1123. <p>
  1124. The src directory holds source code. The path below src
  1125. determines the import path or executable name.
  1126. </p>
  1127. <p>
  1128. The pkg directory holds installed package objects.
  1129. As in the Go tree, each target operating system and
  1130. architecture pair has its own subdirectory of pkg
  1131. (pkg/GOOS_GOARCH).
  1132. </p>
  1133. <p>
  1134. If DIR is a directory listed in the GOPATH, a package with
  1135. source in DIR/src/foo/bar can be imported as &#34;foo/bar&#34; and
  1136. has its compiled form installed to &#34;DIR/pkg/GOOS_GOARCH/foo/bar.a&#34;.
  1137. </p>
  1138. <p>
  1139. The bin directory holds compiled commands.
  1140. Each command is named for its source directory, but only
  1141. the final element, not the entire path. That is, the
  1142. command with source in DIR/src/foo/quux is installed into
  1143. DIR/bin/quux, not DIR/bin/foo/quux. The &#34;foo/&#34; prefix is stripped
  1144. so that you can add DIR/bin to your PATH to get at the
  1145. installed commands. If the GOBIN environment variable is
  1146. set, commands are installed to the directory it names instead
  1147. of DIR/bin. GOBIN must be an absolute path.
  1148. </p>
  1149. <p>
  1150. Here&#39;s an example directory layout:
  1151. </p>
  1152. <pre>GOPATH=/home/user/go
  1153. /home/user/go/
  1154. src/
  1155. foo/
  1156. bar/ (go code in package bar)
  1157. x.go
  1158. quux/ (go code in package main)
  1159. y.go
  1160. bin/
  1161. quux (installed command)
  1162. pkg/
  1163. linux_amd64/
  1164. foo/
  1165. bar.a (installed package object)
  1166. </pre>
  1167. <p>
  1168. Go searches each directory listed in GOPATH to find source code,
  1169. but new packages are always downloaded into the first directory
  1170. in the list.
  1171. </p>
  1172. <p>
  1173. See <a href="https://golang.org/doc/code.html">https://golang.org/doc/code.html</a> for an example.
  1174. </p>
  1175. <h3 id="hdr-Internal_Directories">Internal Directories</h3>
  1176. <p>
  1177. Code in or below a directory named &#34;internal&#34; is importable only
  1178. by code in the directory tree rooted at the parent of &#34;internal&#34;.
  1179. Here&#39;s an extended version of the directory layout above:
  1180. </p>
  1181. <pre>/home/user/go/
  1182. src/
  1183. crash/
  1184. bang/ (go code in package bang)
  1185. b.go
  1186. foo/ (go code in package foo)
  1187. f.go
  1188. bar/ (go code in package bar)
  1189. x.go
  1190. internal/
  1191. baz/ (go code in package baz)
  1192. z.go
  1193. quux/ (go code in package main)
  1194. y.go
  1195. </pre>
  1196. <p>
  1197. The code in z.go is imported as &#34;foo/internal/baz&#34;, but that
  1198. import statement can only appear in source files in the subtree
  1199. rooted at foo. The source files foo/f.go, foo/bar/x.go, and
  1200. foo/quux/y.go can all import &#34;foo/internal/baz&#34;, but the source file
  1201. crash/bang/b.go cannot.
  1202. </p>
  1203. <p>
  1204. See <a href="https://golang.org/s/go14internal">https://golang.org/s/go14internal</a> for details.
  1205. </p>
  1206. <h3 id="hdr-Vendor_Directories">Vendor Directories</h3>
  1207. <p>
  1208. Go 1.6 includes support for using local copies of external dependencies
  1209. to satisfy imports of those dependencies, often referred to as vendoring.
  1210. </p>
  1211. <p>
  1212. Code below a directory named &#34;vendor&#34; is importable only
  1213. by code in the directory tree rooted at the parent of &#34;vendor&#34;,
  1214. and only using an import path that omits the prefix up to and
  1215. including the vendor element.
  1216. </p>
  1217. <p>
  1218. Here&#39;s the example from the previous section,
  1219. but with the &#34;internal&#34; directory renamed to &#34;vendor&#34;
  1220. and a new foo/vendor/crash/bang directory added:
  1221. </p>
  1222. <pre>/home/user/go/
  1223. src/
  1224. crash/
  1225. bang/ (go code in package bang)
  1226. b.go
  1227. foo/ (go code in package foo)
  1228. f.go
  1229. bar/ (go code in package bar)
  1230. x.go
  1231. vendor/
  1232. crash/
  1233. bang/ (go code in package bang)
  1234. b.go
  1235. baz/ (go code in package baz)
  1236. z.go
  1237. quux/ (go code in package main)
  1238. y.go
  1239. </pre>
  1240. <p>
  1241. The same visibility rules apply as for internal, but the code
  1242. in z.go is imported as &#34;baz&#34;, not as &#34;foo/vendor/baz&#34;.
  1243. </p>
  1244. <p>
  1245. Code in vendor directories deeper in the source tree shadows
  1246. code in higher directories. Within the subtree rooted at foo, an import
  1247. of &#34;crash/bang&#34; resolves to &#34;foo/vendor/crash/bang&#34;, not the
  1248. top-level &#34;crash/bang&#34;.
  1249. </p>
  1250. <p>
  1251. Code in vendor directories is not subject to import path
  1252. checking (see &#39;go help importpath&#39;).
  1253. </p>
  1254. <p>
  1255. When &#39;go get&#39; checks out or updates a git repository, it now also
  1256. updates submodules.
  1257. </p>
  1258. <p>
  1259. Vendor directories do not affect the placement of new repositories
  1260. being checked out for the first time by &#39;go get&#39;: those are always
  1261. placed in the main GOPATH, never in a vendor subtree.
  1262. </p>
  1263. <p>
  1264. See <a href="https://golang.org/s/go15vendor">https://golang.org/s/go15vendor</a> for details.
  1265. </p>
  1266. <h3 id="hdr-Environment_variables">Environment variables</h3>
  1267. <p>
  1268. The go command, and the tools it invokes, examine a few different
  1269. environment variables. For many of these, you can see the default
  1270. value of on your system by running &#39;go env NAME&#39;, where NAME is the
  1271. name of the variable.
  1272. </p>
  1273. <p>
  1274. General-purpose environment variables:
  1275. </p>
  1276. <pre>GCCGO
  1277. The gccgo command to run for &#39;go build -compiler=gccgo&#39;.
  1278. GOARCH
  1279. The architecture, or processor, for which to compile code.
  1280. Examples are amd64, 386, arm, ppc64.
  1281. GOBIN
  1282. The directory where &#39;go install&#39; will install a command.
  1283. GOOS
  1284. The operating system for which to compile code.
  1285. Examples are linux, darwin, windows, netbsd.
  1286. GOPATH
  1287. For more details see: &#39;go help gopath&#39;.
  1288. GORACE
  1289. Options for the race detector.
  1290. See <a href="https://golang.org/doc/articles/race_detector.html">https://golang.org/doc/articles/race_detector.html</a>.
  1291. GOROOT
  1292. The root of the go tree.
  1293. </pre>
  1294. <p>
  1295. Environment variables for use with cgo:
  1296. </p>
  1297. <pre>CC
  1298. The command to use to compile C code.
  1299. CGO_ENABLED
  1300. Whether the cgo command is supported. Either 0 or 1.
  1301. CGO_CFLAGS
  1302. Flags that cgo will pass to the compiler when compiling
  1303. C code.
  1304. CGO_CPPFLAGS
  1305. Flags that cgo will pass to the compiler when compiling
  1306. C or C++ code.
  1307. CGO_CXXFLAGS
  1308. Flags that cgo will pass to the compiler when compiling
  1309. C++ code.
  1310. CGO_FFLAGS
  1311. Flags that cgo will pass to the compiler when compiling
  1312. Fortran code.
  1313. CGO_LDFLAGS
  1314. Flags that cgo will pass to the compiler when linking.
  1315. CXX
  1316. The command to use to compile C++ code.
  1317. PKG_CONFIG
  1318. Path to pkg-config tool.
  1319. </pre>
  1320. <p>
  1321. Architecture-specific environment variables:
  1322. </p>
  1323. <pre>GOARM
  1324. For GOARCH=arm, the ARM architecture for which to compile.
  1325. Valid values are 5, 6, 7.
  1326. GO386
  1327. For GOARCH=386, the floating point instruction set.
  1328. Valid values are 387, sse2.
  1329. </pre>
  1330. <p>
  1331. Special-purpose environment variables:
  1332. </p>
  1333. <pre>GOROOT_FINAL
  1334. The root of the installed Go tree, when it is
  1335. installed in a location other than where it is built.
  1336. File names in stack traces are rewritten from GOROOT to
  1337. GOROOT_FINAL.
  1338. GO_EXTLINK_ENABLED
  1339. Whether the linker should use external linking mode
  1340. when using -linkmode=auto with code that uses cgo.
  1341. Set to 0 to disable external linking mode, 1 to enable it.
  1342. GIT_ALLOW_PROTOCOL
  1343. Defined by Git. A colon-separated list of schemes that are allowed to be used
  1344. with git fetch/clone. If set, any scheme not explicitly mentioned will be
  1345. considered insecure by &#39;go get&#39;.
  1346. </pre>
  1347. <h3 id="hdr-Import_path_syntax">Import path syntax</h3>
  1348. <p>
  1349. An import path (see &#39;go help packages&#39;) denotes a package stored in the local
  1350. file system. In general, an import path denotes either a standard package (such
  1351. as &#34;unicode/utf8&#34;) or a package found in one of the work spaces (For more
  1352. details see: &#39;go help gopath&#39;).
  1353. </p>
  1354. <h3 id="hdr-Relative_import_paths">Relative import paths</h3>
  1355. <p>
  1356. An import path beginning with ./ or ../ is called a relative path.
  1357. The toolchain supports relative import paths as a shortcut in two ways.
  1358. </p>
  1359. <p>
  1360. First, a relative path can be used as a shorthand on the command line.
  1361. If you are working in the directory containing the code imported as
  1362. &#34;unicode&#34; and want to run the tests for &#34;unicode/utf8&#34;, you can type
  1363. &#34;go test ./utf8&#34; instead of needing to specify the full path.
  1364. Similarly, in the reverse situation, &#34;go test ..&#34; will test &#34;unicode&#34; from
  1365. the &#34;unicode/utf8&#34; directory. Relative patterns are also allowed, like
  1366. &#34;go test ./...&#34; to test all subdirectories. See &#39;go help packages&#39; for details
  1367. on the pattern syntax.
  1368. </p>
  1369. <p>
  1370. Second, if you are compiling a Go program not in a work space,
  1371. you can use a relative path in an import statement in that program
  1372. to refer to nearby code also not in a work space.
  1373. This makes it easy to experiment with small multipackage programs
  1374. outside of the usual work spaces, but such programs cannot be
  1375. installed with &#34;go install&#34; (there is no work space in which to install them),
  1376. so they are rebuilt from scratch each time they are built.
  1377. To avoid ambiguity, Go programs cannot use relative import paths
  1378. within a work space.
  1379. </p>
  1380. <h3 id="hdr-Remote_import_paths">Remote import paths</h3>
  1381. <p>
  1382. Certain import paths also
  1383. describe how to obtain the source code for the package using
  1384. a revision control system.
  1385. </p>
  1386. <p>
  1387. A few common code hosting sites have special syntax:
  1388. </p>
  1389. <pre>Bitbucket (Git, Mercurial)
  1390. import &#34;bitbucket.org/user/project&#34;
  1391. import &#34;bitbucket.org/user/project/sub/directory&#34;
  1392. GitHub (Git)
  1393. import &#34;github.com/user/project&#34;
  1394. import &#34;github.com/user/project/sub/directory&#34;
  1395. Launchpad (Bazaar)
  1396. import &#34;launchpad.net/project&#34;
  1397. import &#34;launchpad.net/project/series&#34;
  1398. import &#34;launchpad.net/project/series/sub/directory&#34;
  1399. import &#34;launchpad.net/~user/project/branch&#34;
  1400. import &#34;launchpad.net/~user/project/branch/sub/directory&#34;
  1401. IBM DevOps Services (Git)
  1402. import &#34;hub.jazz.net/git/user/project&#34;
  1403. import &#34;hub.jazz.net/git/user/project/sub/directory&#34;
  1404. </pre>
  1405. <p>
  1406. For code hosted on other servers, import paths may either be qualified
  1407. with the version control type, or the go tool can dynamically fetch
  1408. the import path over https/http and discover where the code resides
  1409. from a &lt;meta&gt; tag in the HTML.
  1410. </p>
  1411. <p>
  1412. To declare the code location, an import path of the form
  1413. </p>
  1414. <pre>repository.vcs/path
  1415. </pre>
  1416. <p>
  1417. specifies the given repository, with or without the .vcs suffix,
  1418. using the named version control system, and then the path inside
  1419. that repository. The supported version control systems are:
  1420. </p>
  1421. <pre>Bazaar .bzr
  1422. Git .git
  1423. Mercurial .hg
  1424. Subversion .svn
  1425. </pre>
  1426. <p>
  1427. For example,
  1428. </p>
  1429. <pre>import &#34;example.org/user/foo.hg&#34;
  1430. </pre>
  1431. <p>
  1432. denotes the root directory of the Mercurial repository at
  1433. example.org/user/foo or foo.hg, and
  1434. </p>
  1435. <pre>import &#34;example.org/repo.git/foo/bar&#34;
  1436. </pre>
  1437. <p>
  1438. denotes the foo/bar directory of the Git repository at
  1439. example.org/repo or repo.git.
  1440. </p>
  1441. <p>
  1442. When a version control system supports multiple protocols,
  1443. each is tried in turn when downloading. For example, a Git
  1444. download tries https://, then git+ssh://.
  1445. </p>
  1446. <p>
  1447. By default, downloads are restricted to known secure protocols
  1448. (e.g. https, ssh). To override this setting for Git downloads, the
  1449. GIT_ALLOW_PROTOCOL environment variable can be set (For more details see:
  1450. &#39;go help environment&#39;).
  1451. </p>
  1452. <p>
  1453. If the import path is not a known code hosting site and also lacks a
  1454. version control qualifier, the go tool attempts to fetch the import
  1455. over https/http and looks for a &lt;meta&gt; tag in the document&#39;s HTML
  1456. &lt;head&gt;.
  1457. </p>
  1458. <p>
  1459. The meta tag has the form:
  1460. </p>
  1461. <pre>&lt;meta name=&#34;go-import&#34; content=&#34;import-prefix vcs repo-root&#34;&gt;
  1462. </pre>
  1463. <p>
  1464. The import-prefix is the import path corresponding to the repository
  1465. root. It must be a prefix or an exact match of the package being
  1466. fetched with &#34;go get&#34;. If it&#39;s not an exact match, another http
  1467. request is made at the prefix to verify the &lt;meta&gt; tags match.
  1468. </p>
  1469. <p>
  1470. The meta tag should appear as early in the file as possible.
  1471. In particular, it should appear before any raw JavaScript or CSS,
  1472. to avoid confusing the go command&#39;s restricted parser.
  1473. </p>
  1474. <p>
  1475. The vcs is one of &#34;git&#34;, &#34;hg&#34;, &#34;svn&#34;, etc,
  1476. </p>
  1477. <p>
  1478. The repo-root is the root of the version control system
  1479. containing a scheme and not containing a .vcs qualifier.
  1480. </p>
  1481. <p>
  1482. For example,
  1483. </p>
  1484. <pre>import &#34;example.org/pkg/foo&#34;
  1485. </pre>
  1486. <p>
  1487. will result in the following requests:
  1488. </p>
  1489. <pre><a href="https://example.org/pkg/foo?go-get=1">https://example.org/pkg/foo?go-get=1</a> (preferred)
  1490. <a href="http://example.org/pkg/foo?go-get=1">http://example.org/pkg/foo?go-get=1</a> (fallback, only with -insecure)
  1491. </pre>
  1492. <p>
  1493. If that page contains the meta tag
  1494. </p>
  1495. <pre>&lt;meta name=&#34;go-import&#34; content=&#34;example.org git <a href="https://code.org/r/p/exproj">https://code.org/r/p/exproj</a>&#34;&gt;
  1496. </pre>
  1497. <p>
  1498. the go tool will verify that <a href="https://example.org/?go-get=1">https://example.org/?go-get=1</a> contains the
  1499. same meta tag and then git clone <a href="https://code.org/r/p/exproj">https://code.org/r/p/exproj</a> into
  1500. GOPATH/src/example.org.
  1501. </p>
  1502. <p>
  1503. New downloaded packages are written to the first directory listed in the GOPATH
  1504. environment variable (For more details see: &#39;go help gopath&#39;).
  1505. </p>
  1506. <p>
  1507. The go command attempts to download the version of the
  1508. package appropriate for the Go release being used.
  1509. Run &#39;go help get&#39; for more.
  1510. </p>
  1511. <h3 id="hdr-Import_path_checking">Import path checking</h3>
  1512. <p>
  1513. When the custom import path feature described above redirects to a
  1514. known code hosting site, each of the resulting packages has two possible
  1515. import paths, using the custom domain or the known hosting site.
  1516. </p>
  1517. <p>
  1518. A package statement is said to have an &#34;import comment&#34; if it is immediately
  1519. followed (before the next newline) by a comment of one of these two forms:
  1520. </p>
  1521. <pre>package math // import &#34;path&#34;
  1522. package math /* import &#34;path&#34; */
  1523. </pre>
  1524. <p>
  1525. The go command will refuse to install a package with an import comment
  1526. unless it is being referred to by that import path. In this way, import comments
  1527. let package authors make sure the custom import path is used and not a
  1528. direct path to the underlying code hosting site.
  1529. </p>
  1530. <p>
  1531. Import path checking is disabled for code found within vendor trees.
  1532. This makes it possible to copy code into alternate locations in vendor trees
  1533. without needing to update import comments.
  1534. </p>
  1535. <p>
  1536. See <a href="https://golang.org/s/go14customimport">https://golang.org/s/go14customimport</a> for details.
  1537. </p>
  1538. <h3 id="hdr-Description_of_package_lists">Description of package lists</h3>
  1539. <p>
  1540. Many commands apply to a set of packages:
  1541. </p>
  1542. <pre>go action [packages]
  1543. </pre>
  1544. <p>
  1545. Usually, [packages] is a list of import paths.
  1546. </p>
  1547. <p>
  1548. An import path that is a rooted path or that begins with
  1549. a . or .. element is interpreted as a file system path and
  1550. denotes the package in that directory.
  1551. </p>
  1552. <p>
  1553. Otherwise, the import path P denotes the package found in
  1554. the directory DIR/src/P for some DIR listed in the GOPATH
  1555. environment variable (For more details see: &#39;go help gopath&#39;).
  1556. </p>
  1557. <p>
  1558. If no import paths are given, the action applies to the
  1559. package in the current directory.
  1560. </p>
  1561. <p>
  1562. There are four reserved names for paths that should not be used
  1563. for packages to be built with the go tool:
  1564. </p>
  1565. <p>
  1566. - &#34;main&#34; denotes the top-level package in a stand-alone executable.
  1567. </p>
  1568. <p>
  1569. - &#34;all&#34; expands to all package directories found in all the GOPATH
  1570. trees. For example, &#39;go list all&#39; lists all the packages on the local
  1571. system.
  1572. </p>
  1573. <p>
  1574. - &#34;std&#34; is like all but expands to just the packages in the standard
  1575. Go library.
  1576. </p>
  1577. <p>
  1578. - &#34;cmd&#34; expands to the Go repository&#39;s commands and their
  1579. internal libraries.
  1580. </p>
  1581. <p>
  1582. Import paths beginning with &#34;cmd/&#34; only match source code in
  1583. the Go repository.
  1584. </p>
  1585. <p>
  1586. An import path is a pattern if it includes one or more &#34;...&#34; wildcards,
  1587. each of which can match any string, including the empty string and
  1588. strings containing slashes. Such a pattern expands to all package
  1589. directories found in the GOPATH trees with names matching the
  1590. patterns. As a special case, x/... matches x as well as x&#39;s subdirectories.
  1591. For example, net/... expands to net and packages in its subdirectories.
  1592. </p>
  1593. <p>
  1594. An import path can also name a package to be downloaded from
  1595. a remote repository. Run &#39;go help importpath&#39; for details.
  1596. </p>
  1597. <p>
  1598. Every package in a program must have a unique import path.
  1599. By convention, this is arranged by starting each path with a
  1600. unique prefix that belongs to you. For example, paths used
  1601. internally at Google all begin with &#39;google&#39;, and paths
  1602. denoting remote repositories begin with the path to the code,
  1603. such as &#39;github.com/user/repo&#39;.
  1604. </p>
  1605. <p>
  1606. Packages in a program need not have unique package names,
  1607. but there are two reserved package names with special meaning.
  1608. The name main indicates a command, not a library.
  1609. Commands are built into binaries and cannot be imported.
  1610. The name documentation indicates documentation for
  1611. a non-Go program in the directory. Files in package documentation
  1612. are ignored by the go command.
  1613. </p>
  1614. <p>
  1615. As a special case, if the package list is a list of .go files from a
  1616. single directory, the command is applied to a single synthesized
  1617. package made up of exactly those files, ignoring any build constraints
  1618. in those files and ignoring any other files in the directory.
  1619. </p>
  1620. <p>
  1621. Directory and file names that begin with &#34;.&#34; or &#34;_&#34; are ignored
  1622. by the go tool, as are directories named &#34;testdata&#34;.
  1623. </p>
  1624. <h3 id="hdr-Description_of_testing_flags">Description of testing flags</h3>
  1625. <p>
  1626. The &#39;go test&#39; command takes both flags that apply to &#39;go test&#39; itself
  1627. and flags that apply to the resulting test binary.
  1628. </p>
  1629. <p>
  1630. Several of the flags control profiling and write an execution profile
  1631. suitable for &#34;go tool pprof&#34;; run &#34;go tool pprof -h&#34; for more
  1632. information. The --alloc_space, --alloc_objects, and --show_bytes
  1633. options of pprof control how the information is presented.
  1634. </p>
  1635. <p>
  1636. The following flags are recognized by the &#39;go test&#39; command and
  1637. control the execution of any test:
  1638. </p>
  1639. <pre>-bench regexp
  1640. Run (sub)benchmarks matching a regular expression.
  1641. The given regular expression is split into smaller ones by
  1642. top-level &#39;/&#39;, where each must match the corresponding part of a
  1643. benchmark&#39;s identifier.
  1644. By default, no benchmarks run. To run all benchmarks,
  1645. use &#39;-bench .&#39; or &#39;-bench=.&#39;.
  1646. -benchtime t
  1647. Run enough iterations of each benchmark to take t, specified
  1648. as a time.Duration (for example, -benchtime 1h30s).
  1649. The default is 1 second (1s).
  1650. -count n
  1651. Run each test and benchmark n times (default 1).
  1652. If -cpu is set, run n times for each GOMAXPROCS value.
  1653. Examples are always run once.
  1654. -cover
  1655. Enable coverage analysis.
  1656. -covermode set,count,atomic
  1657. Set the mode for coverage analysis for the package[s]
  1658. being tested. The default is &#34;set&#34; unless -race is enabled,
  1659. in which case it is &#34;atomic&#34;.
  1660. The values:
  1661. set: bool: does this statement run?
  1662. count: int: how many times does this statement run?
  1663. atomic: int: count, but correct in multithreaded tests;
  1664. significantly more expensive.
  1665. Sets -cover.
  1666. -coverpkg pkg1,pkg2,pkg3
  1667. Apply coverage analysis in each test to the given list of packages.
  1668. The default is for each test to analyze only the package being tested.
  1669. Packages are specified as import paths.
  1670. Sets -cover.
  1671. -cpu 1,2,4
  1672. Specify a list of GOMAXPROCS values for which the tests or
  1673. benchmarks should be executed. The default is the current value
  1674. of GOMAXPROCS.
  1675. -parallel n
  1676. Allow parallel execution of test functions that call t.Parallel.
  1677. The value of this flag is the maximum number of tests to run
  1678. simultaneously; by default, it is set to the value of GOMAXPROCS.
  1679. Note that -parallel only applies within a single test binary.
  1680. The &#39;go test&#39; command may run tests for different packages
  1681. in parallel as well, according to the setting of the -p flag
  1682. (see &#39;go help build&#39;).
  1683. -run regexp
  1684. Run only those tests and examples matching the regular expression.
  1685. For tests the regular expression is split into smaller ones by
  1686. top-level &#39;/&#39;, where each must match the corresponding part of a
  1687. test&#39;s identifier.
  1688. -short
  1689. Tell long-running tests to shorten their run time.
  1690. It is off by default but set during all.bash so that installing
  1691. the Go tree can run a sanity check but not spend time running
  1692. exhaustive tests.
  1693. -timeout t
  1694. If a test runs longer than t, panic.
  1695. The default is 10 minutes (10m).
  1696. -v
  1697. Verbose output: log all tests as they are run. Also print all
  1698. text from Log and Logf calls even if the test succeeds.
  1699. </pre>
  1700. <p>
  1701. The following flags are also recognized by &#39;go test&#39; and can be used to
  1702. profile the tests during execution:
  1703. </p>
  1704. <pre>-benchmem
  1705. Print memory allocation statistics for benchmarks.
  1706. -blockprofile block.out
  1707. Write a goroutine blocking profile to the specified file
  1708. when all tests are complete.
  1709. Writes test binary as -c would.
  1710. -blockprofilerate n
  1711. Control the detail provided in goroutine blocking profiles by
  1712. calling runtime.SetBlockProfileRate with n.
  1713. See &#39;go doc runtime.SetBlockProfileRate&#39;.
  1714. The profiler aims to sample, on average, one blocking event every
  1715. n nanoseconds the program spends blocked. By default,
  1716. if -test.blockprofile is set without this flag, all blocking events
  1717. are recorded, equivalent to -test.blockprofilerate=1.
  1718. -coverprofile cover.out
  1719. Write a coverage profile to the file after all tests have passed.
  1720. Sets -cover.
  1721. -cpuprofile cpu.out
  1722. Write a CPU profile to the specified file before exiting.
  1723. Writes test binary as -c would.
  1724. -memprofile mem.out
  1725. Write a memory profile to the file after all tests have passed.
  1726. Writes test binary as -c would.
  1727. -memprofilerate n
  1728. Enable more precise (and expensive) memory profiles by setting
  1729. runtime.MemProfileRate. See &#39;go doc runtime.MemProfileRate&#39;.
  1730. To profile all memory allocations, use -test.memprofilerate=1
  1731. and pass --alloc_space flag to the pprof tool.
  1732. -mutexprofile mutex.out
  1733. Write a mutex contention profile to the specified file
  1734. when all tests are complete.
  1735. Writes test binary as -c would.
  1736. -mutexprofilefraction n
  1737. Sample 1 in n stack traces of goroutines holding a
  1738. contended mutex.
  1739. -outputdir directory
  1740. Place output files from profiling in the specified directory,
  1741. by default the directory in which &#34;go test&#34; is running.
  1742. -trace trace.out
  1743. Write an execution trace to the specified file before exiting.
  1744. </pre>
  1745. <p>
  1746. Each of these flags is also recognized with an optional &#39;test.&#39; prefix,
  1747. as in -test.v. When invoking the generated test binary (the result of
  1748. &#39;go test -c&#39;) directly, however, the prefix is mandatory.
  1749. </p>
  1750. <p>
  1751. The &#39;go test&#39; command rewrites or removes recognized flags,
  1752. as appropriate, both before and after the optional package list,
  1753. before invoking the test binary.
  1754. </p>
  1755. <p>
  1756. For instance, the command
  1757. </p>
  1758. <pre>go test -v -myflag testdata -cpuprofile=prof.out -x
  1759. </pre>
  1760. <p>
  1761. will compile the test binary and then run it as
  1762. </p>
  1763. <pre>pkg.test -test.v -myflag testdata -test.cpuprofile=prof.out
  1764. </pre>
  1765. <p>
  1766. (The -x flag is removed because it applies only to the go command&#39;s
  1767. execution, not to the test itself.)
  1768. </p>
  1769. <p>
  1770. The test flags that generate profiles (other than for coverage) also
  1771. leave the test binary in pkg.test for use when analyzing the profiles.
  1772. </p>
  1773. <p>
  1774. When &#39;go test&#39; runs a test binary, it does so from within the
  1775. corresponding package&#39;s source code directory. Depending on the test,
  1776. it may be necessary to do the same when invoking a generated test
  1777. binary directly.
  1778. </p>
  1779. <p>
  1780. The command-line package list, if present, must appear before any
  1781. flag not known to the go test command. Continuing the example above,
  1782. the package list would have to appear before -myflag, but could appear
  1783. on either side of -v.
  1784. </p>
  1785. <p>
  1786. To keep an argument for a test binary from being interpreted as a
  1787. known flag or a package name, use -args (see &#39;go help test&#39;) which
  1788. passes the remainder of the command line through to the test binary
  1789. uninterpreted and unaltered.
  1790. </p>
  1791. <p>
  1792. For instance, the command
  1793. </p>
  1794. <pre>go test -v -args -x -v
  1795. </pre>
  1796. <p>
  1797. will compile the test binary and then run it as
  1798. </p>
  1799. <pre>pkg.test -test.v -x -v
  1800. </pre>
  1801. <p>
  1802. Similarly,
  1803. </p>
  1804. <pre>go test -args math
  1805. </pre>
  1806. <p>
  1807. will compile the test binary and then run it as
  1808. </p>
  1809. <pre>pkg.test math
  1810. </pre>
  1811. <p>
  1812. In the first example, the -x and the second -v are passed through to the
  1813. test binary unchanged and with no effect on the go command itself.
  1814. In the second example, the argument math is passed through to the test
  1815. binary, instead of being interpreted as the package list.
  1816. </p>
  1817. <h3 id="hdr-Description_of_testing_functions">Description of testing functions</h3>
  1818. <p>
  1819. The &#39;go test&#39; command expects to find test, benchmark, and example functions
  1820. in the &#34;*_test.go&#34; files corresponding to the package under test.
  1821. </p>
  1822. <p>
  1823. A test function is one named TestXXX (where XXX is any alphanumeric string
  1824. not starting with a lower case letter) and should have the signature,
  1825. </p>
  1826. <pre>func TestXXX(t *testing.T) { ... }
  1827. </pre>
  1828. <p>
  1829. A benchmark function is one named BenchmarkXXX and should have the signature,
  1830. </p>
  1831. <pre>func BenchmarkXXX(b *testing.B) { ... }
  1832. </pre>
  1833. <p>
  1834. An example function is similar to a test function but, instead of using
  1835. *testing.T to report success or failure, prints output to os.Stdout.
  1836. If the last comment in the function starts with &#34;Output:&#34; then the output
  1837. is compared exactly against the comment (see examples below). If the last
  1838. comment begins with &#34;Unordered output:&#34; then the output is compared to the
  1839. comment, however the order of the lines is ignored. An example with no such
  1840. comment is compiled but not executed. An example with no text after
  1841. &#34;Output:&#34; is compiled, executed, and expected to produce no output.
  1842. </p>
  1843. <p>
  1844. Godoc displays the body of ExampleXXX to demonstrate the use
  1845. of the function, constant, or variable XXX. An example of a method M with
  1846. receiver type T or *T is named ExampleT_M. There may be multiple examples
  1847. for a given function, constant, or variable, distinguished by a trailing _xxx,
  1848. where xxx is a suffix not beginning with an upper case letter.
  1849. </p>
  1850. <p>
  1851. Here is an example of an example:
  1852. </p>
  1853. <pre>func ExamplePrintln() {
  1854. Println(&#34;The output of\nthis example.&#34;)
  1855. // Output: The output of
  1856. // this example.
  1857. }
  1858. </pre>
  1859. <p>
  1860. Here is another example where the ordering of the output is ignored:
  1861. </p>
  1862. <pre>func ExamplePerm() {
  1863. for _, value := range Perm(4) {
  1864. fmt.Println(value)
  1865. }
  1866. // Unordered output: 4
  1867. // 2
  1868. // 1
  1869. // 3
  1870. // 0
  1871. }
  1872. </pre>
  1873. <p>
  1874. The entire test file is presented as the example when it contains a single
  1875. example function, at least one other function, type, variable, or constant
  1876. declaration, and no test or benchmark functions.
  1877. </p>
  1878. <p>
  1879. See the documentation of the testing package for more information.
  1880. </p>
  1881. <div id="footer">
  1882. Build version go1.8.<br>
  1883. Except as <a href="https://developers.google.com/site-policies#restrictions">noted</a>,
  1884. the content of this page is licensed under the
  1885. Creative Commons Attribution 3.0 License,
  1886. and code is licensed under a <a href="/LICENSE">BSD license</a>.<br>
  1887. <a href="/doc/tos.html">Terms of Service</a> |
  1888. <a href="http://www.google.com/intl/en/policies/privacy/">Privacy Policy</a>
  1889. </div>
  1890. </div><!-- .container -->
  1891. </div><!-- #page -->
  1892. <!-- TODO(adonovan): load these from <head> using "defer" attribute? -->
  1893. <script type="text/javascript" src="/serverpush/static/jquery.min.js?{{.CacheBust}}"></script>
  1894. <script type="text/javascript" src="/serverpush/static/playground.js?{{.CacheBust}}"></script>
  1895. <script>var goVersion = "go1.8";</script>
  1896. <script type="text/javascript" src="/serverpush/static/godocs.js?{{.CacheBust}}"></script>
  1897. </body>
  1898. </html>
  1899. `))