go1.5.html 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310
  1. <!--{
  2. "Title": "Go 1.5 Release Notes",
  3. "Path": "/doc/go1.5",
  4. "Template": true
  5. }-->
  6. <h2 id="introduction">Introduction to Go 1.5</h2>
  7. <p>
  8. The latest Go release, version 1.5,
  9. is a significant release, including major architectural changes to the implementation.
  10. Despite that, we expect almost all Go programs to continue to compile and run as before,
  11. because the release still maintains the Go 1 <a href="/doc/go1compat.html">promise
  12. of compatibility</a>.
  13. </p>
  14. <p>
  15. The biggest developments in the implementation are:
  16. </p>
  17. <ul>
  18. <li>
  19. The compiler and runtime are now written entirely in Go (with a little assembler).
  20. C is no longer involved in the implementation, and so the C compiler that was
  21. once necessary for building the distribution is gone.
  22. </li>
  23. <li>
  24. The garbage collector is now <a href="https://golang.org/s/go14gc">concurrent</a> and provides dramatically lower
  25. pause times by running, when possible, in parallel with other goroutines.
  26. </li>
  27. <li>
  28. By default, Go programs run with <code>GOMAXPROCS</code> set to the
  29. number of cores available; in prior releases it defaulted to 1.
  30. </li>
  31. <li>
  32. Support for <a href="https://golang.org/s/go14internal">internal packages</a>
  33. is now provided for all repositories, not just the Go core.
  34. </li>
  35. <li>
  36. The <code>go</code> command now provides <a href="https://golang.org/s/go15vendor">experimental
  37. support</a> for "vendoring" external dependencies.
  38. </li>
  39. <li>
  40. A new <code>go tool trace</code> command supports fine-grained
  41. tracing of program execution.
  42. </li>
  43. <li>
  44. A new <code>go doc</code> command (distinct from <code>godoc</code>)
  45. is customized for command-line use.
  46. </li>
  47. </ul>
  48. <p>
  49. These and a number of other changes to the implementation and tools
  50. are discussed below.
  51. </p>
  52. <p>
  53. The release also contains one small language change involving map literals.
  54. </p>
  55. <p>
  56. Finally, the timing of the <a href="https://golang.org/s/releasesched">release</a>
  57. strays from the usual six-month interval,
  58. both to provide more time to prepare this major release and to shift the schedule thereafter to
  59. time the release dates more conveniently.
  60. </p>
  61. <h2 id="language">Changes to the language</h2>
  62. <h3 id="map_literals">Map literals</h3>
  63. <p>
  64. Due to an oversight, the rule that allowed the element type to be elided from slice literals was not
  65. applied to map keys.
  66. This has been <a href="/cl/2591">corrected</a> in Go 1.5.
  67. An example will make this clear.
  68. As of Go 1.5, this map literal,
  69. </p>
  70. <pre>
  71. m := map[Point]string{
  72. Point{29.935523, 52.891566}: "Persepolis",
  73. Point{-25.352594, 131.034361}: "Uluru",
  74. Point{37.422455, -122.084306}: "Googleplex",
  75. }
  76. </pre>
  77. <p>
  78. may be written as follows, without the <code>Point</code> type listed explicitly:
  79. </p>
  80. <pre>
  81. m := map[Point]string{
  82. {29.935523, 52.891566}: "Persepolis",
  83. {-25.352594, 131.034361}: "Uluru",
  84. {37.422455, -122.084306}: "Googleplex",
  85. }
  86. </pre>
  87. <h2 id="implementation">The Implementation</h2>
  88. <h3 id="c">No more C</h3>
  89. <p>
  90. The compiler and runtime are now implemented in Go and assembler, without C.
  91. The only C source left in the tree is related to testing or to <code>cgo</code>.
  92. There was a C compiler in the tree in 1.4 and earlier.
  93. It was used to build the runtime; a custom compiler was necessary in part to
  94. guarantee the C code would work with the stack management of goroutines.
  95. Since the runtime is in Go now, there is no need for this C compiler and it is gone.
  96. Details of the process to eliminate C are discussed <a href="https://golang.org/s/go13compiler">elsewhere</a>.
  97. </p>
  98. <p>
  99. The conversion from C was done with the help of custom tools created for the job.
  100. Most important, the compiler was actually moved by automatic translation of
  101. the C code into Go.
  102. It is in effect the same program in a different language.
  103. It is not a new implementation
  104. of the compiler so we expect the process will not have introduced new compiler
  105. bugs.
  106. An overview of this process is available in the slides for
  107. <a href="https://talks.golang.org/2015/gogo.slide">this presentation</a>.
  108. </p>
  109. <h3 id="compiler_and_tools">Compiler and tools</h3>
  110. <p>
  111. Independent of but encouraged by the move to Go, the names of the tools have changed.
  112. The old names <code>6g</code>, <code>8g</code> and so on are gone; instead there
  113. is just one binary, accessible as <code>go</code> <code>tool</code> <code>compile</code>,
  114. that compiles Go source into binaries suitable for the architecture and operating system
  115. specified by <code>$GOARCH</code> and <code>$GOOS</code>.
  116. Similarly, there is now one linker (<code>go</code> <code>tool</code> <code>link</code>)
  117. and one assembler (<code>go</code> <code>tool</code> <code>asm</code>).
  118. The linker was translated automatically from the old C implementation,
  119. but the assembler is a new native Go implementation discussed
  120. in more detail below.
  121. </p>
  122. <p>
  123. Similar to the drop of the names <code>6g</code>, <code>8g</code>, and so on,
  124. the output of the compiler and assembler are now given a plain <code>.o</code> suffix
  125. rather than <code>.8</code>, <code>.6</code>, etc.
  126. </p>
  127. <h3 id="gc">Garbage collector</h3>
  128. <p>
  129. The garbage collector has been re-engineered for 1.5 as part of the development
  130. outlined in the <a href="https://golang.org/s/go14gc">design document</a>.
  131. Expected latencies are much lower than with the collector
  132. in prior releases, through a combination of advanced algorithms,
  133. better <a href="https://golang.org/s/go15gcpacing">scheduling</a> of the collector,
  134. and running more of the collection in parallel with the user program.
  135. The "stop the world" phase of the collector
  136. will almost always be under 10 milliseconds and usually much less.
  137. </p>
  138. <p>
  139. For systems that benefit from low latency, such as user-responsive web sites,
  140. the drop in expected latency with the new collector may be important.
  141. </p>
  142. <p>
  143. Details of the new collector were presented in a
  144. <a href="https://talks.golang.org/2015/go-gc.pdf">talk</a> at GopherCon 2015.
  145. </p>
  146. <h3 id="runtime">Runtime</h3>
  147. <p>
  148. In Go 1.5, the order in which goroutines are scheduled has been changed.
  149. The properties of the scheduler were never defined by the language,
  150. but programs that depend on the scheduling order may be broken
  151. by this change.
  152. We have seen a few (erroneous) programs affected by this change.
  153. If you have programs that implicitly depend on the scheduling
  154. order, you will need to update them.
  155. </p>
  156. <p>
  157. Another potentially breaking change is that the runtime now
  158. sets the default number of threads to run simultaneously,
  159. defined by <code>GOMAXPROCS</code>, to the number
  160. of cores available on the CPU.
  161. In prior releases the default was 1.
  162. Programs that do not expect to run with multiple cores may
  163. break inadvertently.
  164. They can be updated by removing the restriction or by setting
  165. <code>GOMAXPROCS</code> explicitly.
  166. For a more detailed discussion of this change, see
  167. the <a href="https://golang.org/s/go15gomaxprocs">design document</a>.
  168. </p>
  169. <h3 id="build">Build</h3>
  170. <p>
  171. Now that the Go compiler and runtime are implemented in Go, a Go compiler
  172. must be available to compile the distribution from source.
  173. Thus, to build the Go core, a working Go distribution must already be in place.
  174. (Go programmers who do not work on the core are unaffected by this change.)
  175. Any Go 1.4 or later distribution (including <code>gccgo</code>) will serve.
  176. For details, see the <a href="https://golang.org/s/go15bootstrap">design document</a>.
  177. </p>
  178. <h2 id="ports">Ports</h2>
  179. <p>
  180. Due mostly to the industry's move away from the 32-bit x86 architecture,
  181. the set of binary downloads provided is reduced in 1.5.
  182. A distribution for the OS X operating system is provided only for the
  183. <code>amd64</code> architecture, not <code>386</code>.
  184. Similarly, the ports for Snow Leopard (Apple OS X 10.6) still work but are no
  185. longer released as a download or maintained since Apple no longer maintains that version
  186. of the operating system.
  187. Also, the <code>dragonfly/386</code> port is no longer supported at all
  188. because DragonflyBSD itself no longer supports the 32-bit 386 architecture.
  189. </p>
  190. <p>
  191. There are however several new ports available to be built from source.
  192. These include <code>darwin/arm</code> and <code>darwin/arm64</code>.
  193. The new port <code>linux/arm64</code> is mostly in place, but <code>cgo</code>
  194. is only supported using external linking.
  195. </p>
  196. <p>
  197. Also available as experiments are <code>ppc64</code>
  198. and <code>ppc64le</code> (64-bit PowerPC, big- and little-endian).
  199. Both these ports support <code>cgo</code> but
  200. only with internal linking.
  201. </p>
  202. <p>
  203. On FreeBSD, Go 1.5 requires FreeBSD 8-STABLE+ because of its new use of the <code>SYSCALL</code> instruction.
  204. </p>
  205. <p>
  206. On NaCl, Go 1.5 requires SDK version pepper-41. Later pepper versions are not
  207. compatible due to the removal of the sRPC subsystem from the NaCl runtime.
  208. </p>
  209. <p>
  210. On Darwin, the use of the system X.509 certificate interface can be disabled
  211. with the <code>ios</code> build tag.
  212. </p>
  213. <p>
  214. The Solaris port now has full support for cgo and the packages
  215. <a href="/pkg/net/"><code>net</code></a> and
  216. <a href="/pkg/crypto/x509/"><code>crypto/x509</code></a>,
  217. as well as a number of other fixes and improvements.
  218. </p>
  219. <h2 id="tools">Tools</h2>
  220. <h3 id="translate">Translating</h3>
  221. <p>
  222. As part of the process to eliminate C from the tree, the compiler and
  223. linker were translated from C to Go.
  224. It was a genuine (machine assisted) translation, so the new programs are essentially
  225. the old programs translated rather than new ones with new bugs.
  226. We are confident the translation process has introduced few if any new bugs,
  227. and in fact uncovered a number of previously unknown bugs, now fixed.
  228. </p>
  229. <p>
  230. The assembler is a new program, however; it is described below.
  231. </p>
  232. <h3 id="rename">Renaming</h3>
  233. <p>
  234. The suites of programs that were the compilers (<code>6g</code>, <code>8g</code>, etc.),
  235. the assemblers (<code>6a</code>, <code>8a</code>, etc.),
  236. and the linkers (<code>6l</code>, <code>8l</code>, etc.)
  237. have each been consolidated into a single tool that is configured
  238. by the environment variables <code>GOOS</code> and <code>GOARCH</code>.
  239. The old names are gone; the new tools are available through the <code>go</code> <code>tool</code>
  240. mechanism as <code>go tool compile</code>,
  241. <code>go tool asm</code>,
  242. <code>and go tool link</code>.
  243. Also, the file suffixes <code>.6</code>, <code>.8</code>, etc. for the
  244. intermediate object files are also gone; now they are just plain <code>.o</code> files.
  245. </p>
  246. <p>
  247. For example, to build and link a program on amd64 for Darwin
  248. using the tools directly, rather than through <code>go build</code>,
  249. one would run:
  250. </p>
  251. <pre>
  252. $ export GOOS=darwin GOARCH=amd64
  253. $ go tool compile program.go
  254. $ go tool link program.o
  255. </pre>
  256. <h3 id="moving">Moving</h3>
  257. <p>
  258. Because the <a href="/pkg/go/types/"><code>go/types</code></a> package
  259. has now moved into the main repository (see below),
  260. the <a href="/cmd/vet"><code>vet</code></a> and
  261. <a href="/cmd/cover"><code>cover</code></a>
  262. tools have also been moved.
  263. They are no longer maintained in the external <code>golang.org/x/tools</code> repository,
  264. although (deprecated) source still resides there for compatibility with old releases.
  265. </p>
  266. <h3 id="compiler">Compiler</h3>
  267. <p>
  268. As described above, the compiler in Go 1.5 is a single Go program,
  269. translated from the old C source, that replaces <code>6g</code>, <code>8g</code>,
  270. and so on.
  271. Its target is configured by the environment variables <code>GOOS</code> and <code>GOARCH</code>.
  272. </p>
  273. <p>
  274. The 1.5 compiler is mostly equivalent to the old,
  275. but some internal details have changed.
  276. One significant change is that evaluation of constants now uses
  277. the <a href="/pkg/math/big/"><code>math/big</code></a> package
  278. rather than a custom (and less well tested) implementation of high precision
  279. arithmetic.
  280. We do not expect this to affect the results.
  281. </p>
  282. <p>
  283. For the amd64 architecture only, the compiler has a new option, <code>-dynlink</code>,
  284. that assists dynamic linking by supporting references to Go symbols
  285. defined in external shared libraries.
  286. </p>
  287. <h3 id="assembler">Assembler</h3>
  288. <p>
  289. Like the compiler and linker, the assembler in Go 1.5 is a single program
  290. that replaces the suite of assemblers (<code>6a</code>,
  291. <code>8a</code>, etc.) and the environment variables
  292. <code>GOARCH</code> and <code>GOOS</code>
  293. configure the architecture and operating system.
  294. Unlike the other programs, the assembler is a wholly new program
  295. written in Go.
  296. </p>
  297. <p>
  298. The new assembler is very nearly compatible with the previous
  299. ones, but there are a few changes that may affect some
  300. assembler source files.
  301. See the updated <a href="/doc/asm">assembler guide</a>
  302. for more specific information about these changes. In summary:
  303. </p>
  304. <p>
  305. First, the expression evaluation used for constants is a little
  306. different.
  307. It now uses unsigned 64-bit arithmetic and the precedence
  308. of operators (<code>+</code>, <code>-</code>, <code><<</code>, etc.)
  309. comes from Go, not C.
  310. We expect these changes to affect very few programs but
  311. manual verification may be required.
  312. </p>
  313. <p>
  314. Perhaps more important is that on machines where
  315. <code>SP</code> or <code>PC</code> is only an alias
  316. for a numbered register,
  317. such as <code>R13</code> for the stack pointer and
  318. <code>R15</code> for the hardware program counter
  319. on ARM,
  320. a reference to such a register that does not include a symbol
  321. is now illegal.
  322. For example, <code>SP</code> and <code>4(SP)</code> are
  323. illegal but <code>sym+4(SP)</code> is fine.
  324. On such machines, to refer to the hardware register use its
  325. true <code>R</code> name.
  326. </p>
  327. <p>
  328. One minor change is that some of the old assemblers
  329. permitted the notation
  330. </p>
  331. <pre>
  332. constant=value
  333. </pre>
  334. <p>
  335. to define a named constant.
  336. Since this is always possible to do with the traditional
  337. C-like <code>#define</code> notation, which is still
  338. supported (the assembler includes an implementation
  339. of a simplified C preprocessor), the feature was removed.
  340. </p>
  341. <h3 id="link">Linker</h3>
  342. <p>
  343. The linker in Go 1.5 is now one Go program,
  344. that replaces <code>6l</code>, <code>8l</code>, etc.
  345. Its operating system and instruction set are specified
  346. by the environment variables <code>GOOS</code> and <code>GOARCH</code>.
  347. </p>
  348. <p>
  349. There are several other changes.
  350. The most significant is the addition of a <code>-buildmode</code> option that
  351. expands the style of linking; it now supports
  352. situations such as building shared libraries and allowing other languages
  353. to call into Go libraries.
  354. Some of these were outlined in a <a href="https://golang.org/s/execmodes">design document</a>.
  355. For a list of the available build modes and their use, run
  356. </p>
  357. <pre>
  358. $ go help buildmode
  359. </pre>
  360. <p>
  361. Another minor change is that the linker no longer records build time stamps in
  362. the header of Windows executables.
  363. Also, although this may be fixed, Windows cgo executables are missing some
  364. DWARF information.
  365. </p>
  366. <p>
  367. Finally, the <code>-X</code> flag, which takes two arguments,
  368. as in
  369. </p>
  370. <pre>
  371. -X importpath.name value
  372. </pre>
  373. <p>
  374. now also accepts a more common Go flag style with a single argument
  375. that is itself a <code>name=value</code> pair:
  376. </p>
  377. <pre>
  378. -X importpath.name=value
  379. </pre>
  380. <p>
  381. Although the old syntax still works, it is recommended that uses of this
  382. flag in scripts and the like be updated to the new form.
  383. </p>
  384. <h3 id="go_command">Go command</h3>
  385. <p>
  386. The <a href="/cmd/go"><code>go</code></a> command's basic operation
  387. is unchanged, but there are a number of changes worth noting.
  388. </p>
  389. <p>
  390. The previous release introduced the idea of a directory internal to a package
  391. being unimportable through the <code>go</code> command.
  392. In 1.4, it was tested with the introduction of some internal elements
  393. in the core repository.
  394. As suggested in the <a href="https://golang.org/s/go14internal">design document</a>,
  395. that change is now being made available to all repositories.
  396. The rules are explained in the design document, but in summary any
  397. package in or under a directory named <code>internal</code> may
  398. be imported by packages rooted in the same subtree.
  399. Existing packages with directory elements named <code>internal</code> may be
  400. inadvertently broken by this change, which was why it was advertised
  401. in the last release.
  402. </p>
  403. <p>
  404. Another change in how packages are handled is the experimental
  405. addition of support for "vendoring".
  406. For details, see the documentation for the <a href="/cmd/go/#hdr-Vendor_Directories"><code>go</code> command</a>
  407. and the <a href="https://golang.org/s/go15vendor">design document</a>.
  408. </p>
  409. <p>
  410. There have also been several minor changes.
  411. Read the <a href="/cmd/go">documentation</a> for full details.
  412. </p>
  413. <ul>
  414. <li>
  415. SWIG support has been updated such that
  416. <code>.swig</code> and <code>.swigcxx</code>
  417. now require SWIG 3.0.6 or later.
  418. </li>
  419. <li>
  420. The <code>install</code> subcommand now removes the
  421. binary created by the <code>build</code> subcommand
  422. in the source directory, if present,
  423. to avoid problems having two binaries present in the tree.
  424. </li>
  425. <li>
  426. The <code>std</code> (standard library) wildcard package name
  427. now excludes commands.
  428. A new <code>cmd</code> wildcard covers the commands.
  429. </li>
  430. <li>
  431. A new <code>-asmflags</code> build option
  432. sets flags to pass to the assembler.
  433. However,
  434. the <code>-ccflags</code> build option has been dropped;
  435. it was specific to the old, now deleted C compiler .
  436. </li>
  437. <li>
  438. A new <code>-buildmode</code> build option
  439. sets the build mode, described above.
  440. </li>
  441. <li>
  442. A new <code>-pkgdir</code> build option
  443. sets the location of installed package archives,
  444. to help isolate custom builds.
  445. </li>
  446. <li>
  447. A new <code>-toolexec</code> build option
  448. allows substitution of a different command to invoke
  449. the compiler and so on.
  450. This acts as a custom replacement for <code>go tool</code>.
  451. </li>
  452. <li>
  453. The <code>test</code> subcommand now has a <code>-count</code>
  454. flag to specify how many times to run each test and benchmark.
  455. The <a href="/pkg/testing/"><code>testing</code></a> package
  456. does the work here, through the <code>-test.count</code> flag.
  457. </li>
  458. <li>
  459. The <code>generate</code> subcommand has a couple of new features.
  460. The <code>-run</code> option specifies a regular expression to select which directives
  461. to execute; this was proposed but never implemented in 1.4.
  462. The executing pattern now has access to two new environment variables:
  463. <code>$GOLINE</code> returns the source line number of the directive
  464. and <code>$DOLLAR</code> expands to a dollar sign.
  465. </li>
  466. <li>
  467. The <code>get</code> subcommand now has a <code>-insecure</code>
  468. flag that must be enabled if fetching from an insecure repository, one that
  469. does not encrypt the connection.
  470. </li>
  471. </ul>
  472. <h3 id="vet_command">Go vet command</h3>
  473. <p>
  474. The <a href="/cmd/vet"><code>go tool vet</code></a> command now does
  475. more thorough validation of struct tags.
  476. </p>
  477. <h3 id="trace_command">Trace command</h3>
  478. <p>
  479. A new tool is available for dynamic execution tracing of Go programs.
  480. The usage is analogous to how the test coverage tool works.
  481. Generation of traces is integrated into <code>go test</code>,
  482. and then a separate execution of the tracing tool itself analyzes the results:
  483. </p>
  484. <pre>
  485. $ go test -trace=trace.out path/to/package
  486. $ go tool trace [flags] pkg.test trace.out
  487. </pre>
  488. <p>
  489. The flags enable the output to be displayed in a browser window.
  490. For details, run <code>go tool trace -help</code>.
  491. There is also a description of the tracing facility in this
  492. <a href="https://talks.golang.org/2015/dynamic-tools.slide">talk</a>
  493. from GopherCon 2015.
  494. </p>
  495. <h3 id="doc_command">Go doc command</h3>
  496. <p>
  497. A few releases back, the <code>go doc</code>
  498. command was deleted as being unnecessary.
  499. One could always run "<code>godoc .</code>" instead.
  500. The 1.5 release introduces a new <a href="/cmd/doc"><code>go doc</code></a>
  501. command with a more convenient command-line interface than
  502. <code>godoc</code>'s.
  503. It is designed for command-line usage specifically, and provides a more
  504. compact and focused presentation of the documentation for a package
  505. or its elements, according to the invocation.
  506. It also provides case-insensitive matching and
  507. support for showing the documentation for unexported symbols.
  508. For details run "<code>go help doc</code>".
  509. </p>
  510. <h3 id="cgo">Cgo</h3>
  511. <p>
  512. When parsing <code>#cgo</code> lines,
  513. the invocation <code>${SRCDIR}</code> is now
  514. expanded into the path to the source directory.
  515. This allows options to be passed to the
  516. compiler and linker that involve file paths relative to the
  517. source code directory. Without the expansion the paths would be
  518. invalid when the current working directory changes.
  519. </p>
  520. <p>
  521. Solaris now has full cgo support.
  522. </p>
  523. <p>
  524. On Windows, cgo now uses external linking by default.
  525. </p>
  526. <p>
  527. When a C struct ends with a zero-sized field, but the struct itself is
  528. not zero-sized, Go code can no longer refer to the zero-sized field.
  529. Any such references will have to be rewritten.
  530. </p>
  531. <h2 id="performance">Performance</h2>
  532. <p>
  533. As always, the changes are so general and varied that precise statements
  534. about performance are difficult to make.
  535. The changes are even broader ranging than usual in this release, which
  536. includes a new garbage collector and a conversion of the runtime to Go.
  537. Some programs may run faster, some slower.
  538. On average the programs in the Go 1 benchmark suite run a few percent faster in Go 1.5
  539. than they did in Go 1.4,
  540. while as mentioned above the garbage collector's pauses are
  541. dramatically shorter, and almost always under 10 milliseconds.
  542. </p>
  543. <p>
  544. Builds in Go 1.5 will be slower by a factor of about two.
  545. The automatic translation of the compiler and linker from C to Go resulted in
  546. unidiomatic Go code that performs poorly compared to well-written Go.
  547. Analysis tools and refactoring helped to improve the code, but much remains to be done.
  548. Further profiling and optimization will continue in Go 1.6 and future releases.
  549. For more details, see these <a href="https://talks.golang.org/2015/gogo.slide">slides</a>
  550. and associated <a href="https://www.youtube.com/watch?v=cF1zJYkBW4A">video</a>.
  551. </p>
  552. <h2 id="library">Core library</h2>
  553. <h3 id="flag">Flag</h3>
  554. <p>
  555. The flag package's
  556. <a href="/pkg/flag/#PrintDefaults"><code>PrintDefaults</code></a>
  557. function, and method on <a href="/pkg/flag/#FlagSet"><code>FlagSet</code></a>,
  558. have been modified to create nicer usage messages.
  559. The format has been changed to be more human-friendly and in the usage
  560. messages a word quoted with `backquotes` is taken to be the name of the
  561. flag's operand to display in the usage message.
  562. For instance, a flag created with the invocation,
  563. </p>
  564. <pre>
  565. cpuFlag = flag.Int("cpu", 1, "run `N` processes in parallel")
  566. </pre>
  567. <p>
  568. will show the help message,
  569. </p>
  570. <pre>
  571. -cpu N
  572. run N processes in parallel (default 1)
  573. </pre>
  574. <p>
  575. Also, the default is now listed only when it is not the zero value for the type.
  576. </p>
  577. <h3 id="math_big">Floats in math/big</h3>
  578. <p>
  579. The <a href="/pkg/math/big/"><code>math/big</code></a> package
  580. has a new, fundamental data type,
  581. <a href="/pkg/math/big/#Float"><code>Float</code></a>,
  582. which implements arbitrary-precision floating-point numbers.
  583. A <code>Float</code> value is represented by a boolean sign,
  584. a variable-length mantissa, and a 32-bit fixed-size signed exponent.
  585. The precision of a <code>Float</code> (the mantissa size in bits)
  586. can be specified explicitly or is otherwise determined by the first
  587. operation that creates the value.
  588. Once created, the size of a <code>Float</code>'s mantissa may be modified with the
  589. <a href="/pkg/math/big/#Float.SetPrec"><code>SetPrec</code></a> method.
  590. <code>Floats</code> support the concept of infinities, such as are created by
  591. overflow, but values that would lead to the equivalent of IEEE 754 NaNs
  592. trigger a panic.
  593. <code>Float</code> operations support all IEEE-754 rounding modes.
  594. When the precision is set to 24 (53) bits,
  595. operations that stay within the range of normalized <code>float32</code>
  596. (<code>float64</code>)
  597. values produce the same results as the corresponding IEEE-754
  598. arithmetic on those values.
  599. </p>
  600. <h3 id="go_types">Go types</h3>
  601. <p>
  602. The <a href="/pkg/go/types/"><code>go/types</code></a> package
  603. up to now has been maintained in the <code>golang.org/x</code>
  604. repository; as of Go 1.5 it has been relocated to the main repository.
  605. The code at the old location is now deprecated.
  606. There is also a modest API change in the package, discussed below.
  607. </p>
  608. <p>
  609. Associated with this move, the
  610. <a href="/pkg/go/constant/"><code>go/constant</code></a>
  611. package also moved to the main repository;
  612. it was <code>golang.org/x/tools/exact</code> before.
  613. The <a href="/pkg/go/importer/"><code>go/importer</code></a> package
  614. also moved to the main repository,
  615. as well as some tools described above.
  616. </p>
  617. <h3 id="net">Net</h3>
  618. <p>
  619. The DNS resolver in the net package has almost always used <code>cgo</code> to access
  620. the system interface.
  621. A change in Go 1.5 means that on most Unix systems DNS resolution
  622. will no longer require <code>cgo</code>, which simplifies execution
  623. on those platforms.
  624. Now, if the system's networking configuration permits, the native Go resolver
  625. will suffice.
  626. The important effect of this change is that each DNS resolution occupies a goroutine
  627. rather than a thread,
  628. so a program with multiple outstanding DNS requests will consume fewer operating
  629. system resources.
  630. </p>
  631. <p>
  632. The decision of how to run the resolver applies at run time, not build time.
  633. The <code>netgo</code> build tag that has been used to enforce the use
  634. of the Go resolver is no longer necessary, although it still works.
  635. A new <code>netcgo</code> build tag forces the use of the <code>cgo</code> resolver at
  636. build time.
  637. To force <code>cgo</code> resolution at run time set
  638. <code>GODEBUG=netdns=cgo</code> in the environment.
  639. More debug options are documented <a href="https://golang.org/cl/11584">here</a>.
  640. </p>
  641. <p>
  642. This change applies to Unix systems only.
  643. Windows, Mac OS X, and Plan 9 systems behave as before.
  644. </p>
  645. <h3 id="reflect">Reflect</h3>
  646. <p>
  647. The <a href="/pkg/reflect/"><code>reflect</code></a> package
  648. has two new functions: <a href="/pkg/reflect/#ArrayOf"><code>ArrayOf</code></a>
  649. and <a href="/pkg/reflect/#FuncOf"><code>FuncOf</code></a>.
  650. These functions, analogous to the extant
  651. <a href="/pkg/reflect/#SliceOf"><code>SliceOf</code></a> function,
  652. create new types at runtime to describe arrays and functions.
  653. </p>
  654. <h3 id="hardening">Hardening</h3>
  655. <p>
  656. Several dozen bugs were found in the standard library
  657. through randomized testing with the
  658. <a href="https://github.com/dvyukov/go-fuzz"><code>go-fuzz</code></a> tool.
  659. Bugs were fixed in the
  660. <a href="/pkg/archive/tar/"><code>archive/tar</code></a>,
  661. <a href="/pkg/archive/zip/"><code>archive/zip</code></a>,
  662. <a href="/pkg/compress/flate/"><code>compress/flate</code></a>,
  663. <a href="/pkg/encoding/gob/"><code>encoding/gob</code></a>,
  664. <a href="/pkg/fmt/"><code>fmt</code></a>,
  665. <a href="/pkg/html/template/"><code>html/template</code></a>,
  666. <a href="/pkg/image/gif/"><code>image/gif</code></a>,
  667. <a href="/pkg/image/jpeg/"><code>image/jpeg</code></a>,
  668. <a href="/pkg/image/png/"><code>image/png</code></a>, and
  669. <a href="/pkg/text/template/"><code>text/template</code></a>,
  670. packages.
  671. The fixes harden the implementation against incorrect and malicious inputs.
  672. </p>
  673. <h3 id="minor_library_changes">Minor changes to the library</h3>
  674. <ul>
  675. <li>
  676. The <a href="/pkg/archive/zip/"><code>archive/zip</code></a> package's
  677. <a href="/pkg/archive/zip/#Writer"><code>Writer</code></a> type now has a
  678. <a href="/pkg/archive/zip/#Writer.SetOffset"><code>SetOffset</code></a>
  679. method to specify the location within the output stream at which to write the archive.
  680. </li>
  681. <li>
  682. The <a href="/pkg/bufio/#Reader"><code>Reader</code></a> in the
  683. <a href="/pkg/bufio/"><code>bufio</code></a> package now has a
  684. <a href="/pkg/bufio/#Reader.Discard"><code>Discard</code></a>
  685. method to discard data from the input.
  686. </li>
  687. <li>
  688. In the <a href="/pkg/bytes/"><code>bytes</code></a> package,
  689. the <a href="/pkg/bytes/#Buffer"><code>Buffer</code></a> type
  690. now has a <a href="/pkg/bytes/#Buffer.Cap"><code>Cap</code></a> method
  691. that reports the number of bytes allocated within the buffer.
  692. Similarly, in both the <a href="/pkg/bytes/"><code>bytes</code></a>
  693. and <a href="/pkg/strings/"><code>strings</code></a> packages,
  694. the <a href="/pkg/bytes/#Reader"><code>Reader</code></a>
  695. type now has a <a href="/pkg/bytes/#Reader.Size"><code>Size</code></a>
  696. method that reports the original length of the underlying slice or string.
  697. </li>
  698. <li>
  699. Both the <a href="/pkg/bytes/"><code>bytes</code></a> and
  700. <a href="/pkg/strings/"><code>strings</code></a> packages
  701. also now have a <a href="/pkg/bytes/#LastIndexByte"><code>LastIndexByte</code></a>
  702. function that locates the rightmost byte with that value in the argument.
  703. </li>
  704. <li>
  705. The <a href="/pkg/crypto/"><code>crypto</code></a> package
  706. has a new interface, <a href="/pkg/crypto/#Decrypter"><code>Decrypter</code></a>,
  707. that abstracts the behavior of a private key used in asymmetric decryption.
  708. </li>
  709. <li>
  710. In the <a href="/pkg/crypto/cipher/"><code>crypto/cipher</code></a> package,
  711. the documentation for the <a href="/pkg/crypto/cipher/#Stream"><code>Stream</code></a>
  712. interface has been clarified regarding the behavior when the source and destination are
  713. different lengths.
  714. If the destination is shorter than the source, the method will panic.
  715. This is not a change in the implementation, only the documentation.
  716. </li>
  717. <li>
  718. Also in the <a href="/pkg/crypto/cipher/"><code>crypto/cipher</code></a> package,
  719. there is now support for nonce lengths other than 96 bytes in AES's Galois/Counter mode (GCM),
  720. which some protocols require.
  721. </li>
  722. <li>
  723. In the <a href="/pkg/crypto/elliptic/"><code>crypto/elliptic</code></a> package,
  724. there is now a <code>Name</code> field in the
  725. <a href="/pkg/crypto/elliptic/#CurveParams"><code>CurveParams</code></a> struct,
  726. and the curves implemented in the package have been given names.
  727. These names provide a safer way to select a curve, as opposed to
  728. selecting its bit size, for cryptographic systems that are curve-dependent.
  729. </li>
  730. <li>
  731. Also in the <a href="/pkg/crypto/elliptic/"><code>crypto/elliptic</code></a> package,
  732. the <a href="/pkg/crypto/elliptic/#Unmarshal"><code>Unmarshal</code></a> function
  733. now verifies that the point is actually on the curve.
  734. (If it is not, the function returns nils).
  735. This change guards against certain attacks.
  736. </li>
  737. <li>
  738. The <a href="/pkg/crypto/sha512/"><code>crypto/sha512</code></a>
  739. package now has support for the two truncated versions of
  740. the SHA-512 hash algorithm, SHA-512/224 and SHA-512/256.
  741. </li>
  742. <li>
  743. The <a href="/pkg/crypto/tls/"><code>crypto/tls</code></a> package
  744. minimum protocol version now defaults to TLS 1.0.
  745. The old default, SSLv3, is still available through <a href="/pkg/crypto/tls/#Config"><code>Config</code></a> if needed.
  746. </li>
  747. <li>
  748. The <a href="/pkg/crypto/tls/"><code>crypto/tls</code></a> package
  749. now supports Signed Certificate Timestamps (SCTs) as specified in RFC 6962.
  750. The server serves them if they are listed in the
  751. <a href="/pkg/crypto/tls/#Certificate"><code>Certificate</code></a> struct,
  752. and the client requests them and exposes them, if present,
  753. in its <a href="/pkg/crypto/tls/#ConnectionState"><code>ConnectionState</code></a> struct.
  754. <li>
  755. The stapled OCSP response to a <a href="/pkg/crypto/tls/"><code>crypto/tls</code></a> client connection,
  756. previously only available via the
  757. <a href="/pkg/crypto/tls/#Conn.OCSPResponse"><code>OCSPResponse</code></a> method,
  758. is now exposed in the <a href="/pkg/crypto/tls/#ConnectionState"><code>ConnectionState</code></a> struct.
  759. </li>
  760. <li>
  761. The <a href="/pkg/crypto/tls/"><code>crypto/tls</code></a> server implementation
  762. will now always call the
  763. <code>GetCertificate</code> function in
  764. the <a href="/pkg/crypto/tls/#Config"><code>Config</code></a> struct
  765. to select a certificate for the connection when none is supplied.
  766. </li>
  767. <li>
  768. Finally, the session ticket keys in the
  769. <a href="/pkg/crypto/tls/"><code>crypto/tls</code></a> package
  770. can now be changed while the server is running.
  771. This is done through the new
  772. <a href="/pkg/crypto/tls/#Config.SetSessionTicketKeys"><code>SetSessionTicketKeys</code></a>
  773. method of the
  774. <a href="/pkg/crypto/tls/#Config"><code>Config</code></a> type.
  775. </li>
  776. <li>
  777. In the <a href="/pkg/crypto/x509/"><code>crypto/x509</code></a> package,
  778. wildcards are now accepted only in the leftmost label as defined in
  779. <a href="https://tools.ietf.org/html/rfc6125#section-6.4.3">the specification</a>.
  780. </li>
  781. <li>
  782. Also in the <a href="/pkg/crypto/x509/"><code>crypto/x509</code></a> package,
  783. the handling of unknown critical extensions has been changed.
  784. They used to cause parse errors but now they are parsed and caused errors only
  785. in <a href="/pkg/crypto/x509/#Certificate.Verify"><code>Verify</code></a>.
  786. The new field <code>UnhandledCriticalExtensions</code> of
  787. <a href="/pkg/crypto/x509/#Certificate"><code>Certificate</code></a> records these extensions.
  788. </li>
  789. <li>
  790. The <a href="/pkg/database/sql/#DB"><code>DB</code></a> type of the
  791. <a href="/pkg/database/sql/"><code>database/sql</code></a> package
  792. now has a <a href="/pkg/database/sql/#DB.Stats"><code>Stats</code></a> method
  793. to retrieve database statistics.
  794. </li>
  795. <li>
  796. The <a href="/pkg/debug/dwarf/"><code>debug/dwarf</code></a>
  797. package has extensive additions to better support DWARF version 4.
  798. See for example the definition of the new type
  799. <a href="/pkg/debug/dwarf/#Class"><code>Class</code></a>.
  800. </li>
  801. <li>
  802. The <a href="/pkg/debug/dwarf/"><code>debug/dwarf</code></a> package
  803. also now supports decoding of DWARF line tables.
  804. </li>
  805. <li>
  806. The <a href="/pkg/debug/elf/"><code>debug/elf</code></a>
  807. package now has support for the 64-bit PowerPC architecture.
  808. </li>
  809. <li>
  810. The <a href="/pkg/encoding/base64/"><code>encoding/base64</code></a> package
  811. now supports unpadded encodings through two new encoding variables,
  812. <a href="/pkg/encoding/base64/#RawStdEncoding"><code>RawStdEncoding</code></a> and
  813. <a href="/pkg/encoding/base64/#RawURLEncoding"><code>RawURLEncoding</code></a>.
  814. </li>
  815. <li>
  816. The <a href="/pkg/encoding/json/"><code>encoding/json</code></a> package
  817. now returns an <a href="/pkg/encoding/json/#UnmarshalTypeError"><code>UnmarshalTypeError</code></a>
  818. if a JSON value is not appropriate for the target variable or component
  819. to which it is being unmarshaled.
  820. </li>
  821. <li>
  822. The <code>encoding/json</code>'s
  823. <a href="/pkg/encoding/json/#Decoder"><code>Decoder</code></a>
  824. type has a new method that provides a streaming interface for decoding
  825. a JSON document:
  826. <a href="/pkg/encoding/json/#Decoder.Token"><code>Token</code></a>.
  827. It also interoperates with the existing functionality of <code>Decode</code>,
  828. which will continue a decode operation already started with <code>Decoder.Token</code>.
  829. </li>
  830. <li>
  831. The <a href="/pkg/flag/"><code>flag</code></a> package
  832. has a new function, <a href="/pkg/flag/#UnquoteUsage"><code>UnquoteUsage</code></a>,
  833. to assist in the creation of usage messages using the new convention
  834. described above.
  835. </li>
  836. <li>
  837. In the <a href="/pkg/fmt/"><code>fmt</code></a> package,
  838. a value of type <a href="/pkg/reflect/#Value"><code>Value</code></a> now
  839. prints what it holds, rather than use the <code>reflect.Value</code>'s <code>Stringer</code>
  840. method, which produces things like <code>&lt;int Value&gt;</code>.
  841. </li>
  842. <li>
  843. The <a href="/pkg/ast/#EmptyStmt"><code>EmptyStmt</code></a> type
  844. in the <a href="/pkg/go/ast/"><code>go/ast</code></a> package now
  845. has a boolean <code>Implicit</code> field that records whether the
  846. semicolon was implicitly added or was present in the source.
  847. </li>
  848. <li>
  849. For forward compatibility the <a href="/pkg/go/build/"><code>go/build</code></a> package
  850. reserves <code>GOARCH</code> values for a number of architectures that Go might support one day.
  851. This is not a promise that it will.
  852. Also, the <a href="/pkg/go/build/#Package"><code>Package</code></a> struct
  853. now has a <code>PkgTargetRoot</code> field that stores the
  854. architecture-dependent root directory in which to install, if known.
  855. </li>
  856. <li>
  857. The (newly migrated) <a href="/pkg/go/types/"><code>go/types</code></a>
  858. package allows one to control the prefix attached to package-level names using
  859. the new <a href="/pkg/go/types/#Qualifier"><code>Qualifier</code></a>
  860. function type as an argument to several functions. This is an API change for
  861. the package, but since it is new to the core, it is not breaking the Go 1 compatibility
  862. rules since code that uses the package must explicitly ask for it at its new location.
  863. To update, run
  864. <a href="https://golang.org/cmd/go/#hdr-Run_go_tool_fix_on_packages"><code>go fix</code></a> on your package.
  865. </li>
  866. <li>
  867. In the <a href="/pkg/image/"><code>image</code></a> package,
  868. the <a href="/pkg/image/#Rectangle"><code>Rectangle</code></a> type
  869. now implements the <a href="/pkg/image/#Image"><code>Image</code></a> interface,
  870. so a <code>Rectangle</code> can serve as a mask when drawing.
  871. </li>
  872. <li>
  873. Also in the <a href="/pkg/image/"><code>image</code></a> package,
  874. to assist in the handling of some JPEG images,
  875. there is now support for 4:1:1 and 4:1:0 YCbCr subsampling and basic
  876. CMYK support, represented by the new <code>image.CMYK</code> struct.
  877. </li>
  878. <li>
  879. The <a href="/pkg/image/color/"><code>image/color</code></a> package
  880. adds basic CMYK support, through the new
  881. <a href="/pkg/image/color/#CMYK"><code>CMYK</code></a> struct,
  882. the <a href="/pkg/image/color/#CMYKModel"><code>CMYKModel</code></a> color model, and the
  883. <a href="/pkg/image/color/#CMYKToRGB"><code>CMYKToRGB</code></a> function, as
  884. needed by some JPEG images.
  885. </li>
  886. <li>
  887. Also in the <a href="/pkg/image/color/"><code>image/color</code></a> package,
  888. the conversion of a <a href="/pkg/image/color/#YCbCr"><code>YCbCr</code></a>
  889. value to <code>RGBA</code> has become more precise.
  890. Previously, the low 8 bits were just an echo of the high 8 bits;
  891. now they contain more accurate information.
  892. Because of the echo property of the old code, the operation
  893. <code>uint8(r)</code> to extract an 8-bit red value worked, but is incorrect.
  894. In Go 1.5, that operation may yield a different value.
  895. The correct code is, and always was, to select the high 8 bits:
  896. <code>uint8(r&gt;&gt;8)</code>.
  897. Incidentally, the <code>image/draw</code> package
  898. provides better support for such conversions; see
  899. <a href="https://blog.golang.org/go-imagedraw-package">this blog post</a>
  900. for more information.
  901. </li>
  902. <li>
  903. Finally, as of Go 1.5 the closest match check in
  904. <a href="/pkg/image/color/#Palette.Index"><code>Index</code></a>
  905. now honors the alpha channel.
  906. </li>
  907. <li>
  908. The <a href="/pkg/image/gif/"><code>image/gif</code></a> package
  909. includes a couple of generalizations.
  910. A multiple-frame GIF file can now have an overall bounds different
  911. from all the contained single frames' bounds.
  912. Also, the <a href="/pkg/image/gif/#GIF"><code>GIF</code></a> struct
  913. now has a <code>Disposal</code> field
  914. that specifies the disposal method for each frame.
  915. </li>
  916. <li>
  917. The <a href="/pkg/io/"><code>io</code></a> package
  918. adds a <a href="/pkg/io/#CopyBuffer"><code>CopyBuffer</code></a> function
  919. that is like <a href="/pkg/io/#Copy"><code>Copy</code></a> but
  920. uses a caller-provided buffer, permitting control of allocation and buffer size.
  921. </li>
  922. <li>
  923. The <a href="/pkg/log/"><code>log</code></a> package
  924. has a new <a href="/pkg/log/#LUTC"><code>LUTC</code></a> flag
  925. that causes time stamps to be printed in the UTC time zone.
  926. It also adds a <a href="/pkg/log/#Logger.SetOutput"><code>SetOutput</code></a> method
  927. for user-created loggers.
  928. </li>
  929. <li>
  930. In Go 1.4, <a href="/pkg/math/#Max"><code>Max</code></a> was not detecting all possible NaN bit patterns.
  931. This is fixed in Go 1.5, so programs that use <code>math.Max</code> on data including NaNs may behave differently,
  932. but now correctly according to the IEEE754 definition of NaNs.
  933. </li>
  934. <li>
  935. The <a href="/pkg/math/big/"><code>math/big</code></a> package
  936. adds a new <a href="/pkg/math/big/#Jacobi"><code>Jacobi</code></a>
  937. function for integers and a new
  938. <a href="/pkg/math/big/#Int.ModSqrt"><code>ModSqrt</code></a>
  939. method for the <a href="/pkg/math/big/#Int"><code>Int</code></a> type.
  940. </li>
  941. <li>
  942. The mime package
  943. adds a new <a href="/pkg/mime/#WordDecoder"><code>WordDecoder</code></a> type
  944. to decode MIME headers containing RFC 204-encoded words.
  945. It also provides <a href="/pkg/mime/#BEncoding"><code>BEncoding</code></a> and
  946. <a href="/pkg/mime/#QEncoding"><code>QEncoding</code></a>
  947. as implementations of the encoding schemes of RFC 2045 and RFC 2047.
  948. </li>
  949. <li>
  950. The <a href="/pkg/mime/"><code>mime</code></a> package also adds an
  951. <a href="/pkg/mime/#ExtensionsByType"><code>ExtensionsByType</code></a>
  952. function that returns the MIME extensions know to be associated with a given MIME type.
  953. </li>
  954. <li>
  955. There is a new <a href="/pkg/mime/quotedprintable/"><code>mime/quotedprintable</code></a>
  956. package that implements the quoted-printable encoding defined by RFC 2045.
  957. </li>
  958. <li>
  959. The <a href="/pkg/net/"><code>net</code></a> package will now
  960. <a href="/pkg/net/#Dial"><code>Dial</code></a> hostnames by trying each
  961. IP address in order until one succeeds.
  962. The <code><a href="/pkg/net/#Dialer">Dialer</a>.DualStack</code>
  963. mode now implements Happy Eyeballs
  964. (<a href="https://tools.ietf.org/html/rfc6555">RFC 6555</a>) by giving the
  965. first address family a 300ms head start; this value can be overridden by
  966. the new <code>Dialer.FallbackDelay</code>.
  967. </li>
  968. <li>
  969. A number of inconsistencies in the types returned by errors in the
  970. <a href="/pkg/net/"><code>net</code></a> package have been
  971. tidied up.
  972. Most now return an
  973. <a href="/pkg/net/#OpError"><code>OpError</code></a> value
  974. with more information than before.
  975. Also, the <a href="/pkg/net/#OpError"><code>OpError</code></a>
  976. type now includes a <code>Source</code> field that holds the local
  977. network address.
  978. </li>
  979. <li>
  980. The <a href="/pkg/net/http/"><code>net/http</code></a> package now
  981. has support for setting trailers from a server <a href="/pkg/net/http/#Handler"><code>Handler</code></a>.
  982. For details, see the documentation for
  983. <a href="/pkg/net/http/#ResponseWriter"><code>ResponseWriter</code></a>.
  984. </li>
  985. <li>
  986. There is a new method to cancel a <a href="/pkg/net/http/"><code>net/http</code></a>
  987. <code>Request</code> by setting the new
  988. <a href="/pkg/net/http/#Request"><code>Request.Cancel</code></a>
  989. field.
  990. It is supported by <code>http.Transport</code>.
  991. The <code>Cancel</code> field's type is compatible with the
  992. <a href="https://godoc.org/golang.org/x/net/context"><code>context.Context.Done</code></a>
  993. return value.
  994. </li>
  995. <li>
  996. Also in the <a href="/pkg/net/http/"><code>net/http</code></a> package,
  997. there is code to ignore the zero <a href="/pkg/time/#Time"><code>Time</code></a> value
  998. in the <a href="/pkg/net/#ServeContent"><code>ServeContent</code></a> function.
  999. As of Go 1.5, it now also ignores a time value equal to the Unix epoch.
  1000. </li>
  1001. <li>
  1002. The <a href="/pkg/net/http/fcgi/"><code>net/http/fcgi</code></a> package
  1003. exports two new errors,
  1004. <a href="/pkg/net/http/fcgi/#ErrConnClosed"><code>ErrConnClosed</code></a> and
  1005. <a href="/pkg/net/http/fcgi/#ErrRequestAborted"><code>ErrRequestAborted</code></a>,
  1006. to report the corresponding error conditions.
  1007. </li>
  1008. <li>
  1009. The <a href="/pkg/net/http/cgi/"><code>net/http/cgi</code></a> package
  1010. had a bug that mishandled the values of the environment variables
  1011. <code>REMOTE_ADDR</code> and <code>REMOTE_HOST</code>.
  1012. This has been fixed.
  1013. Also, starting with Go 1.5 the package sets the <code>REMOTE_PORT</code>
  1014. variable.
  1015. </li>
  1016. <li>
  1017. The <a href="/pkg/net/mail/"><code>net/mail</code></a> package
  1018. adds an <a href="/pkg/net/mail/#AddressParser"><code>AddressParser</code></a>
  1019. type that can parse mail addresses.
  1020. </li>
  1021. <li>
  1022. The <a href="/pkg/net/smtp/"><code>net/smtp</code></a> package
  1023. now has a <a href="/pkg/net/smtp/#Client.TLSConnectionState"><code>TLSConnectionState</code></a>
  1024. accessor to the <a href="/pkg/net/smtp/#Client"><code>Client</code></a>
  1025. type that returns the client's TLS state.
  1026. </li>
  1027. <li>
  1028. The <a href="/pkg/os/"><code>os</code></a> package
  1029. has a new <a href="/pkg/os/#LookupEnv"><code>LookupEnv</code></a> function
  1030. that is similar to <a href="/pkg/os/#Getenv"><code>Getenv</code></a>
  1031. but can distinguish between an empty environment variable and a missing one.
  1032. </li>
  1033. <li>
  1034. The <a href="/pkg/os/signal/"><code>os/signal</code></a> package
  1035. adds new <a href="/pkg/os/signal/#Ignore"><code>Ignore</code></a> and
  1036. <a href="/pkg/os/signal/#Reset"><code>Reset</code></a> functions.
  1037. </li>
  1038. <li>
  1039. The <a href="/pkg/runtime/"><code>runtime</code></a>,
  1040. <a href="/pkg/runtime/trace/"><code>runtime/trace</code></a>,
  1041. and <a href="/pkg/net/http/pprof/"><code>net/http/pprof</code></a> packages
  1042. each have new functions to support the tracing facilities described above:
  1043. <a href="/pkg/runtime/#ReadTrace"><code>ReadTrace</code></a>,
  1044. <a href="/pkg/runtime/#StartTrace"><code>StartTrace</code></a>,
  1045. <a href="/pkg/runtime/#StopTrace"><code>StopTrace</code></a>,
  1046. <a href="/pkg/runtime/trace/#Start"><code>Start</code></a>,
  1047. <a href="/pkg/runtime/trace/#Stop"><code>Stop</code></a>, and
  1048. <a href="/pkg/net/http/pprof/#Trace"><code>Trace</code></a>.
  1049. See the respective documentation for details.
  1050. </li>
  1051. <li>
  1052. The <a href="/pkg/runtime/pprof/"><code>runtime/pprof</code></a> package
  1053. by default now includes overall memory statistics in all memory profiles.
  1054. </li>
  1055. <li>
  1056. The <a href="/pkg/strings/"><code>strings</code></a> package
  1057. has a new <a href="/pkg/strings/#Compare"><code>Compare</code></a> function.
  1058. This is present to provide symmetry with the <a href="/pkg/bytes/"><code>bytes</code></a> package
  1059. but is otherwise unnecessary as strings support comparison natively.
  1060. </li>
  1061. <li>
  1062. The <a href="/pkg/sync/#WaitGroup"><code>WaitGroup</code></a> implementation in
  1063. package <a href="/pkg/sync/"><code>sync</code></a>
  1064. now diagnoses code that races a call to <a href="/pkg/sync/#WaitGroup.Add"><code>Add</code></a>
  1065. against a return from <a href="/pkg/sync/#WaitGroup.Wait"><code>Wait</code></a>.
  1066. If it detects this condition, the implementation panics.
  1067. </li>
  1068. <li>
  1069. In the <a href="/pkg/syscall/"><code>syscall</code></a> package,
  1070. the Linux <code>SysProcAttr</code> struct now has a
  1071. <code>GidMappingsEnableSetgroups</code> field, made necessary
  1072. by security changes in Linux 3.19.
  1073. On all Unix systems, the struct also has new <code>Foreground</code> and <code>Pgid</code> fields
  1074. to provide more control when exec'ing.
  1075. On Darwin, there is now a <code>Syscall9</code> function
  1076. to support calls with too many arguments.
  1077. </li>
  1078. <li>
  1079. The <a href="/pkg/testing/quick/"><code>testing/quick</code></a> will now
  1080. generate <code>nil</code> values for pointer types,
  1081. making it possible to use with recursive data structures.
  1082. Also, the package now supports generation of array types.
  1083. </li>
  1084. <li>
  1085. In the <a href="/pkg/text/template/"><code>text/template</code></a> and
  1086. <a href="/pkg/html/template/"><code>html/template</code></a> packages,
  1087. integer constants too large to be represented as a Go integer now trigger a
  1088. parse error. Before, they were silently converted to floating point, losing
  1089. precision.
  1090. </li>
  1091. <li>
  1092. Also in the <a href="/pkg/text/template/"><code>text/template</code></a> and
  1093. <a href="/pkg/html/template/"><code>html/template</code></a> packages,
  1094. a new <a href="/pkg/text/template/#Template.Option"><code>Option</code></a> method
  1095. allows customization of the behavior of the template during execution.
  1096. The sole implemented option allows control over how a missing key is
  1097. handled when indexing a map.
  1098. The default, which can now be overridden, is as before: to continue with an invalid value.
  1099. </li>
  1100. <li>
  1101. The <a href="/pkg/time/"><code>time</code></a> package's
  1102. <code>Time</code> type has a new method
  1103. <a href="/pkg/time/#Time.AppendFormat"><code>AppendFormat</code></a>,
  1104. which can be used to avoid allocation when printing a time value.
  1105. </li>
  1106. <li>
  1107. The <a href="/pkg/unicode/"><code>unicode</code></a> package and associated
  1108. support throughout the system has been upgraded from version 7.0 to
  1109. <a href="http://www.unicode.org/versions/Unicode8.0.0/">Unicode 8.0</a>.
  1110. </li>
  1111. </ul>