go1.6.html 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923
  1. <!--{
  2. "Title": "Go 1.6 Release Notes",
  3. "Path": "/doc/go1.6",
  4. "Template": true
  5. }-->
  6. <!--
  7. Edit .,s;^PKG:([a-z][A-Za-z0-9_/]+);<a href="/pkg/\1/"><code>\1</code></a>;g
  8. Edit .,s;^([a-z][A-Za-z0-9_/]+)\.([A-Z][A-Za-z0-9_]+\.)?([A-Z][A-Za-z0-9_]+)([ .',]|$);<a href="/pkg/\1/#\2\3"><code>\3</code></a>\4;g
  9. -->
  10. <style>
  11. main ul li { margin: 0.5em 0; }
  12. </style>
  13. <h2 id="introduction">Introduction to Go 1.6</h2>
  14. <p>
  15. The latest Go release, version 1.6, arrives six months after 1.5.
  16. Most of its changes are in the implementation of the language, runtime, and libraries.
  17. There are no changes to the language specification.
  18. As always, the release maintains the Go 1 <a href="/doc/go1compat.html">promise of compatibility</a>.
  19. We expect almost all Go programs to continue to compile and run as before.
  20. </p>
  21. <p>
  22. The release adds new ports to <a href="#ports">Linux on 64-bit MIPS and Android on 32-bit x86</a>;
  23. defined and enforced <a href="#cgo">rules for sharing Go pointers with C</a>;
  24. transparent, automatic <a href="#http2">support for HTTP/2</a>;
  25. and a new mechanism for <a href="#template">template reuse</a>.
  26. </p>
  27. <h2 id="language">Changes to the language</h2>
  28. <p>
  29. There are no language changes in this release.
  30. </p>
  31. <h2 id="ports">Ports</h2>
  32. <p>
  33. Go 1.6 adds experimental ports to
  34. Linux on 64-bit MIPS (<code>linux/mips64</code> and <code>linux/mips64le</code>).
  35. These ports support <code>cgo</code> but only with internal linking.
  36. </p>
  37. <p>
  38. Go 1.6 also adds an experimental port to Android on 32-bit x86 (<code>android/386</code>).
  39. </p>
  40. <p>
  41. On FreeBSD, Go 1.6 defaults to using <code>clang</code>, not <code>gcc</code>, as the external C compiler.
  42. </p>
  43. <p>
  44. On Linux on little-endian 64-bit PowerPC (<code>linux/ppc64le</code>),
  45. Go 1.6 now supports <code>cgo</code> with external linking and
  46. is roughly feature complete.
  47. </p>
  48. <p>
  49. On NaCl, Go 1.5 required SDK version pepper-41.
  50. Go 1.6 adds support for later SDK versions.
  51. </p>
  52. <p>
  53. On 32-bit x86 systems using the <code>-dynlink</code> or <code>-shared</code> compilation modes,
  54. the register CX is now overwritten by certain memory references and should
  55. be avoided in hand-written assembly.
  56. See the <a href="/doc/asm#x86">assembly documentation</a> for details.
  57. </p>
  58. <h2 id="tools">Tools</h2>
  59. <h3 id="cgo">Cgo</h3>
  60. <p>
  61. There is one major change to <a href="/cmd/cgo/"><code>cgo</code></a>, along with one minor change.
  62. </p>
  63. <p>
  64. The major change is the definition of rules for sharing Go pointers with C code,
  65. to ensure that such C code can coexist with Go's garbage collector.
  66. Briefly, Go and C may share memory allocated by Go
  67. when a pointer to that memory is passed to C as part of a <code>cgo</code> call,
  68. provided that the memory itself contains no pointers to Go-allocated memory,
  69. and provided that C does not retain the pointer after the call returns.
  70. These rules are checked by the runtime during program execution:
  71. if the runtime detects a violation, it prints a diagnosis and crashes the program.
  72. The checks can be disabled by setting the environment variable
  73. <code>GODEBUG=cgocheck=0</code>, but note that the vast majority of
  74. code identified by the checks is subtly incompatible with garbage collection
  75. in one way or another.
  76. Disabling the checks will typically only lead to more mysterious failure modes.
  77. Fixing the code in question should be strongly preferred
  78. over turning off the checks.
  79. See the <a href="/cmd/cgo/#hdr-Passing_pointers"><code>cgo</code> documentation</a> for more details.
  80. </p>
  81. <p>
  82. The minor change is
  83. the addition of explicit <code>C.complexfloat</code> and <code>C.complexdouble</code> types,
  84. separate from Go's <code>complex64</code> and <code>complex128</code>.
  85. Matching the other numeric types, C's complex types and Go's complex type are
  86. no longer interchangeable.
  87. </p>
  88. <h3 id="compiler">Compiler Toolchain</h3>
  89. <p>
  90. The compiler toolchain is mostly unchanged.
  91. Internally, the most significant change is that the parser is now hand-written
  92. instead of generated from <a href="/cmd/yacc/">yacc</a>.
  93. </p>
  94. <p>
  95. The compiler, linker, and <code>go</code> command have a new flag <code>-msan</code>,
  96. analogous to <code>-race</code> and only available on linux/amd64,
  97. that enables interoperation with the <a href="https://clang.llvm.org/docs/MemorySanitizer.html">Clang MemorySanitizer</a>.
  98. Such interoperation is useful mainly for testing a program containing suspect C or C++ code.
  99. </p>
  100. <p>
  101. The linker has a new option <code>-libgcc</code> to set the expected location
  102. of the C compiler support library when linking <a href="/cmd/cgo/"><code>cgo</code></a> code.
  103. The option is only consulted when using <code>-linkmode=internal</code>,
  104. and it may be set to <code>none</code> to disable the use of a support library.
  105. </p>
  106. <p>
  107. The implementation of <a href="/doc/go1.5#link">build modes started in Go 1.5</a> has been expanded to more systems.
  108. This release adds support for the <code>c-shared</code> mode on <code>android/386</code>, <code>android/amd64</code>,
  109. <code>android/arm64</code>, <code>linux/386</code>, and <code>linux/arm64</code>;
  110. for the <code>shared</code> mode on <code>linux/386</code>, <code>linux/arm</code>, <code>linux/amd64</code>, and <code>linux/ppc64le</code>;
  111. and for the new <code>pie</code> mode (generating position-independent executables) on
  112. <code>android/386</code>, <code>android/amd64</code>, <code>android/arm</code>, <code>android/arm64</code>, <code>linux/386</code>,
  113. <code>linux/amd64</code>, <code>linux/arm</code>, <code>linux/arm64</code>, and <code>linux/ppc64le</code>.
  114. See the <a href="https://golang.org/s/execmodes">design document</a> for details.
  115. </p>
  116. <p>
  117. As a reminder, the linker's <code>-X</code> flag changed in Go 1.5.
  118. In Go 1.4 and earlier, it took two arguments, as in
  119. </p>
  120. <pre>
  121. -X importpath.name value
  122. </pre>
  123. <p>
  124. Go 1.5 added an alternative syntax using a single argument
  125. that is itself a <code>name=value</code> pair:
  126. </p>
  127. <pre>
  128. -X importpath.name=value
  129. </pre>
  130. <p>
  131. In Go 1.5 the old syntax was still accepted, after printing a warning
  132. suggesting use of the new syntax instead.
  133. Go 1.6 continues to accept the old syntax and print the warning.
  134. Go 1.7 will remove support for the old syntax.
  135. </p>
  136. <h3 id="gccgo">Gccgo</h3>
  137. <p>
  138. The release schedules for the GCC and Go projects do not coincide.
  139. GCC release 5 contains the Go 1.4 version of gccgo.
  140. The next release, GCC 6, will have the Go 1.6.1 version of gccgo.
  141. </p>
  142. <h3 id="go_command">Go command</h3>
  143. <p>
  144. The <a href="/cmd/go"><code>go</code></a> command's basic operation
  145. is unchanged, but there are a number of changes worth noting.
  146. </p>
  147. <p>
  148. Go 1.5 introduced experimental support for vendoring,
  149. enabled by setting the <code>GO15VENDOREXPERIMENT</code> environment variable to <code>1</code>.
  150. Go 1.6 keeps the vendoring support, no longer considered experimental,
  151. and enables it by default.
  152. It can be disabled explicitly by setting
  153. the <code>GO15VENDOREXPERIMENT</code> environment variable to <code>0</code>.
  154. Go 1.7 will remove support for the environment variable.
  155. </p>
  156. <p>
  157. The most likely problem caused by enabling vendoring by default happens
  158. in source trees containing an existing directory named <code>vendor</code> that
  159. does not expect to be interpreted according to new vendoring semantics.
  160. In this case, the simplest fix is to rename the directory to anything other
  161. than <code>vendor</code> and update any affected import paths.
  162. </p>
  163. <p>
  164. For details about vendoring,
  165. see the documentation for the <a href="/cmd/go/#hdr-Vendor_Directories"><code>go</code> command</a>
  166. and the <a href="https://golang.org/s/go15vendor">design document</a>.
  167. </p>
  168. <p>
  169. There is a new build flag, <code>-msan</code>,
  170. that compiles Go with support for the LLVM memory sanitizer.
  171. This is intended mainly for use when linking against C or C++ code
  172. that is being checked with the memory sanitizer.
  173. </p>
  174. <h3 id="doc_command">Go doc command</h3>
  175. <p>
  176. Go 1.5 introduced the
  177. <a href="/cmd/go/#hdr-Show_documentation_for_package_or_symbol"><code>go doc</code></a> command,
  178. which allows references to packages using only the package name, as in
  179. <code>go</code> <code>doc</code> <code>http</code>.
  180. In the event of ambiguity, the Go 1.5 behavior was to use the package
  181. with the lexicographically earliest import path.
  182. In Go 1.6, ambiguity is resolved by preferring import paths with
  183. fewer elements, breaking ties using lexicographic comparison.
  184. An important effect of this change is that original copies of packages
  185. are now preferred over vendored copies.
  186. Successful searches also tend to run faster.
  187. </p>
  188. <h3 id="vet_command">Go vet command</h3>
  189. <p>
  190. The <a href="/cmd/vet"><code>go vet</code></a> command now diagnoses
  191. passing function or method values as arguments to <code>Printf</code>,
  192. such as when passing <code>f</code> where <code>f()</code> was intended.
  193. </p>
  194. <h2 id="performance">Performance</h2>
  195. <p>
  196. As always, the changes are so general and varied that precise statements
  197. about performance are difficult to make.
  198. Some programs may run faster, some slower.
  199. On average the programs in the Go 1 benchmark suite run a few percent faster in Go 1.6
  200. than they did in Go 1.5.
  201. The garbage collector's pauses are even lower than in Go 1.5,
  202. especially for programs using
  203. a large amount of memory.
  204. </p>
  205. <p>
  206. There have been significant optimizations bringing more than 10% improvements
  207. to implementations of the
  208. <a href="/pkg/compress/bzip2/"><code>compress/bzip2</code></a>,
  209. <a href="/pkg/compress/gzip/"><code>compress/gzip</code></a>,
  210. <a href="/pkg/crypto/aes/"><code>crypto/aes</code></a>,
  211. <a href="/pkg/crypto/elliptic/"><code>crypto/elliptic</code></a>,
  212. <a href="/pkg/crypto/ecdsa/"><code>crypto/ecdsa</code></a>, and
  213. <a href="/pkg/sort/"><code>sort</code></a> packages.
  214. </p>
  215. <h2 id="library">Core library</h2>
  216. <h3 id="http2">HTTP/2</h3>
  217. <p>
  218. Go 1.6 adds transparent support in the
  219. <a href="/pkg/net/http/"><code>net/http</code></a> package
  220. for the new <a href="https://http2.github.io/">HTTP/2 protocol</a>.
  221. Go clients and servers will automatically use HTTP/2 as appropriate when using HTTPS.
  222. There is no exported API specific to details of the HTTP/2 protocol handling,
  223. just as there is no exported API specific to HTTP/1.1.
  224. </p>
  225. <p>
  226. Programs that must disable HTTP/2 can do so by setting
  227. <a href="/pkg/net/http/#Transport"><code>Transport.TLSNextProto</code></a> (for clients)
  228. or
  229. <a href="/pkg/net/http/#Server"><code>Server.TLSNextProto</code></a> (for servers)
  230. to a non-nil, empty map.
  231. </p>
  232. <p>
  233. Programs that must adjust HTTP/2 protocol-specific details can import and use
  234. <a href="https://golang.org/x/net/http2"><code>golang.org/x/net/http2</code></a>,
  235. in particular its
  236. <a href="https://godoc.org/golang.org/x/net/http2/#ConfigureServer">ConfigureServer</a>
  237. and
  238. <a href="https://godoc.org/golang.org/x/net/http2/#ConfigureTransport">ConfigureTransport</a>
  239. functions.
  240. </p>
  241. <h3 id="runtime">Runtime</h3>
  242. <p>
  243. The runtime has added lightweight, best-effort detection of concurrent misuse of maps.
  244. As always, if one goroutine is writing to a map, no other goroutine should be
  245. reading or writing the map concurrently.
  246. If the runtime detects this condition, it prints a diagnosis and crashes the program.
  247. The best way to find out more about the problem is to run the program
  248. under the
  249. <a href="https://blog.golang.org/race-detector">race detector</a>,
  250. which will more reliably identify the race
  251. and give more detail.
  252. </p>
  253. <p>
  254. For program-ending panics, the runtime now by default
  255. prints only the stack of the running goroutine,
  256. not all existing goroutines.
  257. Usually only the current goroutine is relevant to a panic,
  258. so omitting the others significantly reduces irrelevant output
  259. in a crash message.
  260. To see the stacks from all goroutines in crash messages, set the environment variable
  261. <code>GOTRACEBACK</code> to <code>all</code>
  262. or call
  263. <a href="/pkg/runtime/debug/#SetTraceback"><code>debug.SetTraceback</code></a>
  264. before the crash, and rerun the program.
  265. See the <a href="/pkg/runtime/#hdr-Environment_Variables">runtime documentation</a> for details.
  266. </p>
  267. <p>
  268. <em>Updating</em>:
  269. Uncaught panics intended to dump the state of the entire program,
  270. such as when a timeout is detected or when explicitly handling a received signal,
  271. should now call <code>debug.SetTraceback("all")</code> before panicking.
  272. Searching for uses of
  273. <a href="/pkg/os/signal/#Notify"><code>signal.Notify</code></a> may help identify such code.
  274. </p>
  275. <p>
  276. On Windows, Go programs in Go 1.5 and earlier forced
  277. the global Windows timer resolution to 1ms at startup
  278. by calling <code>timeBeginPeriod(1)</code>.
  279. Go no longer needs this for good scheduler performance,
  280. and changing the global timer resolution caused problems on some systems,
  281. so the call has been removed.
  282. </p>
  283. <p>
  284. When using <code>-buildmode=c-archive</code> or
  285. <code>-buildmode=c-shared</code> to build an archive or a shared
  286. library, the handling of signals has changed.
  287. In Go 1.5 the archive or shared library would install a signal handler
  288. for most signals.
  289. In Go 1.6 it will only install a signal handler for the
  290. synchronous signals needed to handle run-time panics in Go code:
  291. SIGBUS, SIGFPE, SIGSEGV.
  292. See the <a href="/pkg/os/signal">os/signal</a> package for more
  293. details.
  294. </p>
  295. <h3 id="reflect">Reflect</h3>
  296. <p>
  297. The
  298. <a href="/pkg/reflect/"><code>reflect</code></a> package has
  299. <a href="https://golang.org/issue/12367">resolved a long-standing incompatibility</a>
  300. between the gc and gccgo toolchains
  301. regarding embedded unexported struct types containing exported fields.
  302. Code that walks data structures using reflection, especially to implement
  303. serialization in the spirit
  304. of the
  305. <a href="/pkg/encoding/json/"><code>encoding/json</code></a> and
  306. <a href="/pkg/encoding/xml/"><code>encoding/xml</code></a> packages,
  307. may need to be updated.
  308. </p>
  309. <p>
  310. The problem arises when using reflection to walk through
  311. an embedded unexported struct-typed field
  312. into an exported field of that struct.
  313. In this case, <code>reflect</code> had incorrectly reported
  314. the embedded field as exported, by returning an empty <code>Field.PkgPath</code>.
  315. Now it correctly reports the field as unexported
  316. but ignores that fact when evaluating access to exported fields
  317. contained within the struct.
  318. </p>
  319. <p>
  320. <em>Updating</em>:
  321. Typically, code that previously walked over structs and used
  322. </p>
  323. <pre>
  324. f.PkgPath != ""
  325. </pre>
  326. <p>
  327. to exclude inaccessible fields
  328. should now use
  329. </p>
  330. <pre>
  331. f.PkgPath != "" &amp;&amp; !f.Anonymous
  332. </pre>
  333. <p>
  334. For example, see the changes to the implementations of
  335. <a href="https://go-review.googlesource.com/#/c/14011/2/src/encoding/json/encode.go"><code>encoding/json</code></a> and
  336. <a href="https://go-review.googlesource.com/#/c/14012/2/src/encoding/xml/typeinfo.go"><code>encoding/xml</code></a>.
  337. </p>
  338. <h3 id="sort">Sorting</h3>
  339. <p>
  340. In the
  341. <a href="/pkg/sort/"><code>sort</code></a>
  342. package,
  343. the implementation of
  344. <a href="/pkg/sort/#Sort"><code>Sort</code></a>
  345. has been rewritten to make about 10% fewer calls to the
  346. <a href="/pkg/sort/#Interface"><code>Interface</code></a>'s
  347. <code>Less</code> and <code>Swap</code>
  348. methods, with a corresponding overall time savings.
  349. The new algorithm does choose a different ordering than before
  350. for values that compare equal (those pairs for which <code>Less(i,</code> <code>j)</code> and <code>Less(j,</code> <code>i)</code> are false).
  351. </p>
  352. <p>
  353. <em>Updating</em>:
  354. The definition of <code>Sort</code> makes no guarantee about the final order of equal values,
  355. but the new behavior may still break programs that expect a specific order.
  356. Such programs should either refine their <code>Less</code> implementations
  357. to report the desired order
  358. or should switch to
  359. <a href="/pkg/sort/#Stable"><code>Stable</code></a>,
  360. which preserves the original input order
  361. of equal values.
  362. </p>
  363. <h3 id="template">Templates</h3>
  364. <p>
  365. In the
  366. <a href="/pkg/text/template/">text/template</a> package,
  367. there are two significant new features to make writing templates easier.
  368. </p>
  369. <p>
  370. First, it is now possible to <a href="/pkg/text/template/#hdr-Text_and_spaces">trim spaces around template actions</a>,
  371. which can make template definitions more readable.
  372. A minus sign at the beginning of an action says to trim space before the action,
  373. and a minus sign at the end of an action says to trim space after the action.
  374. For example, the template
  375. </p>
  376. <pre>
  377. {{"{{"}}23 -}}
  378. &lt;
  379. {{"{{"}}- 45}}
  380. </pre>
  381. <p>
  382. formats as <code>23&lt;45</code>.
  383. </p>
  384. <p>
  385. Second, the new <a href="/pkg/text/template/#hdr-Actions"><code>{{"{{"}}block}}</code> action</a>,
  386. combined with allowing redefinition of named templates,
  387. provides a simple way to define pieces of a template that
  388. can be replaced in different instantiations.
  389. There is <a href="/pkg/text/template/#example_Template_block">an example</a>
  390. in the <code>text/template</code> package that demonstrates this new feature.
  391. </p>
  392. <h3 id="minor_library_changes">Minor changes to the library</h3>
  393. <ul>
  394. <li>
  395. The <a href="/pkg/archive/tar/"><code>archive/tar</code></a> package's
  396. implementation corrects many bugs in rare corner cases of the file format.
  397. One visible change is that the
  398. <a href="/pkg/archive/tar/#Reader"><code>Reader</code></a> type's
  399. <a href="/pkg/archive/tar/#Reader.Read"><code>Read</code></a> method
  400. now presents the content of special file types as being empty,
  401. returning <code>io.EOF</code> immediately.
  402. </li>
  403. <li>
  404. In the <a href="/pkg/archive/zip/"><code>archive/zip</code></a> package, the
  405. <a href="/pkg/archive/zip/#Reader"><code>Reader</code></a> type now has a
  406. <a href="/pkg/archive/zip/#Reader.RegisterDecompressor"><code>RegisterDecompressor</code></a> method,
  407. and the
  408. <a href="/pkg/archive/zip/#Writer"><code>Writer</code></a> type now has a
  409. <a href="/pkg/archive/zip/#Writer.RegisterCompressor"><code>RegisterCompressor</code></a> method,
  410. enabling control over compression options for individual zip files.
  411. These take precedence over the pre-existing global
  412. <a href="/pkg/archive/zip/#RegisterDecompressor"><code>RegisterDecompressor</code></a> and
  413. <a href="/pkg/archive/zip/#RegisterCompressor"><code>RegisterCompressor</code></a> functions.
  414. </li>
  415. <li>
  416. The <a href="/pkg/bufio/"><code>bufio</code></a> package's
  417. <a href="/pkg/bufio/#Scanner"><code>Scanner</code></a> type now has a
  418. <a href="/pkg/bufio/#Scanner.Buffer"><code>Buffer</code></a> method,
  419. to specify an initial buffer and maximum buffer size to use during scanning.
  420. This makes it possible, when needed, to scan tokens larger than
  421. <code>MaxScanTokenSize</code>.
  422. Also for the <code>Scanner</code>, the package now defines the
  423. <a href="/pkg/bufio/#ErrFinalToken"><code>ErrFinalToken</code></a> error value, for use by
  424. <a href="/pkg/bufio/#SplitFunc">split functions</a> to abort processing or to return a final empty token.
  425. </li>
  426. <li>
  427. The <a href="/pkg/compress/flate/"><code>compress/flate</code></a> package
  428. has deprecated its
  429. <a href="/pkg/compress/flate/#ReadError"><code>ReadError</code></a> and
  430. <a href="/pkg/compress/flate/#WriteError"><code>WriteError</code></a> error implementations.
  431. In Go 1.5 they were only rarely returned when an error was encountered;
  432. now they are never returned, although they remain defined for compatibility.
  433. </li>
  434. <li>
  435. The <a href="/pkg/compress/flate/"><code>compress/flate</code></a>,
  436. <a href="/pkg/compress/gzip/"><code>compress/gzip</code></a>, and
  437. <a href="/pkg/compress/zlib/"><code>compress/zlib</code></a> packages
  438. now report
  439. <a href="/pkg/io/#ErrUnexpectedEOF"><code>io.ErrUnexpectedEOF</code></a> for truncated input streams, instead of
  440. <a href="/pkg/io/#EOF"><code>io.EOF</code></a>.
  441. </li>
  442. <li>
  443. The <a href="/pkg/crypto/cipher/"><code>crypto/cipher</code></a> package now
  444. overwrites the destination buffer in the event of a GCM decryption failure.
  445. This is to allow the AESNI code to avoid using a temporary buffer.
  446. </li>
  447. <li>
  448. The <a href="/pkg/crypto/tls/"><code>crypto/tls</code></a> package
  449. has a variety of minor changes.
  450. It now allows
  451. <a href="/pkg/crypto/tls/#Listen"><code>Listen</code></a>
  452. to succeed when the
  453. <a href="/pkg/crypto/tls/#Config"><code>Config</code></a>
  454. has a nil <code>Certificates</code>, as long as the <code>GetCertificate</code> callback is set,
  455. it adds support for RSA with AES-GCM cipher suites,
  456. and
  457. it adds a
  458. <a href="/pkg/crypto/tls/#RecordHeaderError"><code>RecordHeaderError</code></a>
  459. to allow clients (in particular, the <a href="/pkg/net/http/"><code>net/http</code></a> package)
  460. to report a better error when attempting a TLS connection to a non-TLS server.
  461. </li>
  462. <li>
  463. The <a href="/pkg/crypto/x509/"><code>crypto/x509</code></a> package
  464. now permits certificates to contain negative serial numbers
  465. (technically an error, but unfortunately common in practice),
  466. and it defines a new
  467. <a href="/pkg/crypto/x509/#InsecureAlgorithmError"><code>InsecureAlgorithmError</code></a>
  468. to give a better error message when rejecting a certificate
  469. signed with an insecure algorithm like MD5.
  470. </li>
  471. <li>
  472. The <a href="/pkg/debug/dwarf"><code>debug/dwarf</code></a> and
  473. <a href="/pkg/debug/elf/"><code>debug/elf</code></a> packages
  474. together add support for compressed DWARF sections.
  475. User code needs no updating: the sections are decompressed automatically when read.
  476. </li>
  477. <li>
  478. The <a href="/pkg/debug/elf/"><code>debug/elf</code></a> package
  479. adds support for general compressed ELF sections.
  480. User code needs no updating: the sections are decompressed automatically when read.
  481. However, compressed
  482. <a href="/pkg/debug/elf/#Section"><code>Sections</code></a> do not support random access:
  483. they have a nil <code>ReaderAt</code> field.
  484. </li>
  485. <li>
  486. The <a href="/pkg/encoding/asn1/"><code>encoding/asn1</code></a> package
  487. now exports
  488. <a href="/pkg/encoding/asn1/#pkg-constants">tag and class constants</a>
  489. useful for advanced parsing of ASN.1 structures.
  490. </li>
  491. <li>
  492. Also in the <a href="/pkg/encoding/asn1/"><code>encoding/asn1</code></a> package,
  493. <a href="/pkg/encoding/asn1/#Unmarshal"><code>Unmarshal</code></a> now rejects various non-standard integer and length encodings.
  494. </li>
  495. <li>
  496. The <a href="/pkg/encoding/base64"><code>encoding/base64</code></a> package's
  497. <a href="/pkg/encoding/base64/#Decoder"><code>Decoder</code></a> has been fixed
  498. to process the final bytes of its input. Previously it processed as many four-byte tokens as
  499. possible but ignored the remainder, up to three bytes.
  500. The <code>Decoder</code> therefore now handles inputs in unpadded encodings (like
  501. <a href="/pkg/encoding/base64/#RawURLEncoding">RawURLEncoding</a>) correctly,
  502. but it also rejects inputs in padded encodings that are truncated or end with invalid bytes,
  503. such as trailing spaces.
  504. </li>
  505. <li>
  506. The <a href="/pkg/encoding/json/"><code>encoding/json</code></a> package
  507. now checks the syntax of a
  508. <a href="/pkg/encoding/json/#Number"><code>Number</code></a>
  509. before marshaling it, requiring that it conforms to the JSON specification for numeric values.
  510. As in previous releases, the zero <code>Number</code> (an empty string) is marshaled as a literal 0 (zero).
  511. </li>
  512. <li>
  513. The <a href="/pkg/encoding/xml/"><code>encoding/xml</code></a> package's
  514. <a href="/pkg/encoding/xml/#Marshal"><code>Marshal</code></a>
  515. function now supports a <code>cdata</code> attribute, such as <code>chardata</code>
  516. but encoding its argument in one or more <code>&lt;![CDATA[ ... ]]&gt;</code> tags.
  517. </li>
  518. <li>
  519. Also in the <a href="/pkg/encoding/xml/"><code>encoding/xml</code></a> package,
  520. <a href="/pkg/encoding/xml/#Decoder"><code>Decoder</code></a>'s
  521. <a href="/pkg/encoding/xml/#Decoder.Token"><code>Token</code></a> method
  522. now reports an error when encountering EOF before seeing all open tags closed,
  523. consistent with its general requirement that tags in the input be properly matched.
  524. To avoid that requirement, use
  525. <a href="/pkg/encoding/xml/#Decoder.RawToken"><code>RawToken</code></a>.
  526. </li>
  527. <li>
  528. The <a href="/pkg/fmt/"><code>fmt</code></a> package now allows
  529. any integer type as an argument to
  530. <a href="/pkg/fmt/#Printf"><code>Printf</code></a>'s <code>*</code> width and precision specification.
  531. In previous releases, the argument to <code>*</code> was required to have type <code>int</code>.
  532. </li>
  533. <li>
  534. Also in the <a href="/pkg/fmt/"><code>fmt</code></a> package,
  535. <a href="/pkg/fmt/#Scanf"><code>Scanf</code></a> can now scan hexadecimal strings using %X, as an alias for %x.
  536. Both formats accept any mix of upper- and lower-case hexadecimal.
  537. </li>
  538. <li>
  539. The <a href="/pkg/image/"><code>image</code></a>
  540. and
  541. <a href="/pkg/image/color/"><code>image/color</code></a> packages
  542. add
  543. <a href="/pkg/image/#NYCbCrA"><code>NYCbCrA</code></a>
  544. and
  545. <a href="/pkg/image/color/#NYCbCrA"><code>NYCbCrA</code></a>
  546. types, to support Y'CbCr images with non-premultiplied alpha.
  547. </li>
  548. <li>
  549. The <a href="/pkg/io/"><code>io</code></a> package's
  550. <a href="/pkg/io/#MultiWriter"><code>MultiWriter</code></a>
  551. implementation now implements a <code>WriteString</code> method,
  552. for use by
  553. <a href="/pkg/io/#WriteString"><code>WriteString</code></a>.
  554. </li>
  555. <li>
  556. In the <a href="/pkg/math/big/"><code>math/big</code></a> package,
  557. <a href="/pkg/math/big/#Int"><code>Int</code></a> adds
  558. <a href="/pkg/math/big/#Int.Append"><code>Append</code></a>
  559. and
  560. <a href="/pkg/math/big/#Int.Text"><code>Text</code></a>
  561. methods to give more control over printing.
  562. </li>
  563. <li>
  564. Also in the <a href="/pkg/math/big/"><code>math/big</code></a> package,
  565. <a href="/pkg/math/big/#Float"><code>Float</code></a> now implements
  566. <a href="/pkg/encoding/#TextMarshaler"><code>encoding.TextMarshaler</code></a> and
  567. <a href="/pkg/encoding/#TextUnmarshaler"><code>encoding.TextUnmarshaler</code></a>,
  568. allowing it to be serialized in a natural form by the
  569. <a href="/pkg/encoding/json/"><code>encoding/json</code></a> and
  570. <a href="/pkg/encoding/xml/"><code>encoding/xml</code></a> packages.
  571. </li>
  572. <li>
  573. Also in the <a href="/pkg/math/big/"><code>math/big</code></a> package,
  574. <a href="/pkg/math/big/#Float"><code>Float</code></a>'s
  575. <a href="/pkg/math/big/#Float.Append"><code>Append</code></a> method now supports the special precision argument -1.
  576. As in
  577. <a href="/pkg/strconv/#ParseFloat"><code>strconv.ParseFloat</code></a>,
  578. precision -1 means to use the smallest number of digits necessary such that
  579. <a href="/pkg/math/big/#Float.Parse"><code>Parse</code></a>
  580. reading the result into a <code>Float</code> of the same precision
  581. will yield the original value.
  582. </li>
  583. <li>
  584. The <a href="/pkg/math/rand/"><code>math/rand</code></a> package
  585. adds a
  586. <a href="/pkg/math/rand/#Read"><code>Read</code></a>
  587. function, and likewise
  588. <a href="/pkg/math/rand/#Rand"><code>Rand</code></a> adds a
  589. <a href="/pkg/math/rand/#Rand.Read"><code>Read</code></a> method.
  590. These make it easier to generate pseudorandom test data.
  591. Note that, like the rest of the package,
  592. these should not be used in cryptographic settings;
  593. for such purposes, use the <a href="/pkg/crypto/rand/"><code>crypto/rand</code></a> package instead.
  594. </li>
  595. <li>
  596. The <a href="/pkg/net/"><code>net</code></a> package's
  597. <a href="/pkg/net/#ParseMAC"><code>ParseMAC</code></a> function now accepts 20-byte IP-over-InfiniBand (IPoIB) link-layer addresses.
  598. </li>
  599. <li>
  600. Also in the <a href="/pkg/net/"><code>net</code></a> package,
  601. there have been a few changes to DNS lookups.
  602. First, the
  603. <a href="/pkg/net/#DNSError"><code>DNSError</code></a> error implementation now implements
  604. <a href="/pkg/net/#Error"><code>Error</code></a>,
  605. and in particular its new
  606. <a href="/pkg/net/#DNSError.IsTemporary"><code>IsTemporary</code></a>
  607. method returns true for DNS server errors.
  608. Second, DNS lookup functions such as
  609. <a href="/pkg/net/#LookupAddr"><code>LookupAddr</code></a>
  610. now return rooted domain names (with a trailing dot)
  611. on Plan 9 and Windows, to match the behavior of Go on Unix systems.
  612. </li>
  613. <li>
  614. The <a href="/pkg/net/http/"><code>net/http</code></a> package has
  615. a number of minor additions beyond the HTTP/2 support already discussed.
  616. First, the
  617. <a href="/pkg/net/http/#FileServer"><code>FileServer</code></a> now sorts its generated directory listings by file name.
  618. Second, the
  619. <a href="/pkg/net/http/#ServeFile"><code>ServeFile</code></a> function now refuses to serve a result
  620. if the request's URL path contains &ldquo;..&rdquo; (dot-dot) as a path element.
  621. Programs should typically use <code>FileServer</code> and
  622. <a href="/pkg/net/http/#Dir"><code>Dir</code></a>
  623. instead of calling <code>ServeFile</code> directly.
  624. Programs that need to serve file content in response to requests for URLs containing dot-dot can
  625. still call <a href="/pkg/net/http/#ServeContent"><code>ServeContent</code></a>.
  626. Third, the
  627. <a href="/pkg/net/http/#Client"><code>Client</code></a> now allows user code to set the
  628. <code>Expect:</code> <code>100-continue</code> header (see
  629. <a href="/pkg/net/http/#Transport"><code>Transport.ExpectContinueTimeout</code></a>).
  630. Fourth, there are
  631. <a href="/pkg/net/http/#pkg-constants">five new error codes</a>:
  632. <code>StatusPreconditionRequired</code> (428),
  633. <code>StatusTooManyRequests</code> (429),
  634. <code>StatusRequestHeaderFieldsTooLarge</code> (431), and
  635. <code>StatusNetworkAuthenticationRequired</code> (511) from RFC 6585,
  636. as well as the recently-approved
  637. <code>StatusUnavailableForLegalReasons</code> (451).
  638. Fifth, the implementation and documentation of
  639. <a href="/pkg/net/http/#CloseNotifier"><code>CloseNotifier</code></a>
  640. has been substantially changed.
  641. The <a href="/pkg/net/http/#Hijacker"><code>Hijacker</code></a>
  642. interface now works correctly on connections that have previously
  643. been used with <code>CloseNotifier</code>.
  644. The documentation now describes when <code>CloseNotifier</code>
  645. is expected to work.
  646. </li>
  647. <li>
  648. Also in the <a href="/pkg/net/http/"><code>net/http</code></a> package,
  649. there are a few changes related to the handling of a
  650. <a href="/pkg/net/http/#Request"><code>Request</code></a> data structure with its <code>Method</code> field set to the empty string.
  651. An empty <code>Method</code> field has always been documented as an alias for <code>"GET"</code>
  652. and it remains so.
  653. However, Go 1.6 fixes a few routines that did not treat an empty
  654. <code>Method</code> the same as an explicit <code>"GET"</code>.
  655. Most notably, in previous releases
  656. <a href="/pkg/net/http/#Client"><code>Client</code></a> followed redirects only with
  657. <code>Method</code> set explicitly to <code>"GET"</code>;
  658. in Go 1.6 <code>Client</code> also follows redirects for the empty <code>Method</code>.
  659. Finally,
  660. <a href="/pkg/net/http/#NewRequest"><code>NewRequest</code></a> accepts a <code>method</code> argument that has not been
  661. documented as allowed to be empty.
  662. In past releases, passing an empty <code>method</code> argument resulted
  663. in a <code>Request</code> with an empty <code>Method</code> field.
  664. In Go 1.6, the resulting <code>Request</code> always has an initialized
  665. <code>Method</code> field: if its argument is an empty string, <code>NewRequest</code>
  666. sets the <code>Method</code> field in the returned <code>Request</code> to <code>"GET"</code>.
  667. </li>
  668. <li>
  669. The <a href="/pkg/net/http/httptest/"><code>net/http/httptest</code></a> package's
  670. <a href="/pkg/net/http/httptest/#ResponseRecorder"><code>ResponseRecorder</code></a> now initializes a default Content-Type header
  671. using the same content-sniffing algorithm as in
  672. <a href="/pkg/net/http/#Server"><code>http.Server</code></a>.
  673. </li>
  674. <li>
  675. The <a href="/pkg/net/url/"><code>net/url</code></a> package's
  676. <a href="/pkg/net/url/#Parse"><code>Parse</code></a> is now stricter and more spec-compliant regarding the parsing
  677. of host names.
  678. For example, spaces in the host name are no longer accepted.
  679. </li>
  680. <li>
  681. Also in the <a href="/pkg/net/url/"><code>net/url</code></a> package,
  682. the <a href="/pkg/net/url/#Error"><code>Error</code></a> type now implements
  683. <a href="/pkg/net/#Error"><code>net.Error</code></a>.
  684. </li>
  685. <li>
  686. The <a href="/pkg/os/"><code>os</code></a> package's
  687. <a href="/pkg/os/#IsExist"><code>IsExist</code></a>,
  688. <a href="/pkg/os/#IsNotExist"><code>IsNotExist</code></a>,
  689. and
  690. <a href="/pkg/os/#IsPermission"><code>IsPermission</code></a>
  691. now return correct results when inquiring about an
  692. <a href="/pkg/os/#SyscallError"><code>SyscallError</code></a>.
  693. </li>
  694. <li>
  695. On Unix-like systems, when a write
  696. to <a href="/pkg/os/#pkg-variables"><code>os.Stdout</code>
  697. or <code>os.Stderr</code></a> (more precisely, an <code>os.File</code>
  698. opened for file descriptor 1 or 2) fails due to a broken pipe error,
  699. the program will raise a <code>SIGPIPE</code> signal.
  700. By default this will cause the program to exit; this may be changed by
  701. calling the
  702. <a href="/pkg/os/signal"><code>os/signal</code></a>
  703. <a href="/pkg/os/signal/#Notify"><code>Notify</code></a> function
  704. for <code>syscall.SIGPIPE</code>.
  705. A write to a broken pipe on a file descriptor other 1 or 2 will simply
  706. return <code>syscall.EPIPE</code> (possibly wrapped in
  707. <a href="/pkg/os#PathError"><code>os.PathError</code></a>
  708. and/or <a href="/pkg/os#SyscallError"><code>os.SyscallError</code></a>)
  709. to the caller.
  710. The old behavior of raising an uncatchable <code>SIGPIPE</code> signal
  711. after 10 consecutive writes to a broken pipe no longer occurs.
  712. </li>
  713. <li>
  714. In the <a href="/pkg/os/exec/"><code>os/exec</code></a> package,
  715. <a href="/pkg/os/exec/#Cmd"><code>Cmd</code></a>'s
  716. <a href="/pkg/os/exec/#Cmd.Output"><code>Output</code></a> method continues to return an
  717. <a href="/pkg/os/exec/#ExitError"><code>ExitError</code></a> when a command exits with an unsuccessful status.
  718. If standard error would otherwise have been discarded,
  719. the returned <code>ExitError</code> now holds a prefix and suffix
  720. (currently 32 kB) of the failed command's standard error output,
  721. for debugging or for inclusion in error messages.
  722. The <code>ExitError</code>'s
  723. <a href="/pkg/os/exec/#ExitError.String"><code>String</code></a>
  724. method does not show the captured standard error;
  725. programs must retrieve it from the data structure
  726. separately.
  727. </li>
  728. <li>
  729. On Windows, the <a href="/pkg/path/filepath/"><code>path/filepath</code></a> package's
  730. <a href="/pkg/path/filepath/#Join"><code>Join</code></a> function now correctly handles the case when the base is a relative drive path.
  731. For example, <code>Join(`c:`,</code> <code>`a`)</code> now
  732. returns <code>`c:a`</code> instead of <code>`c:\a`</code> as in past releases.
  733. This may affect code that expects the incorrect result.
  734. </li>
  735. <li>
  736. In the <a href="/pkg/regexp/"><code>regexp</code></a> package,
  737. the
  738. <a href="/pkg/regexp/#Regexp"><code>Regexp</code></a> type has always been safe for use by
  739. concurrent goroutines.
  740. It uses a <a href="/pkg/sync/#Mutex"><code>sync.Mutex</code></a> to protect
  741. a cache of scratch spaces used during regular expression searches.
  742. Some high-concurrency servers using the same <code>Regexp</code> from many goroutines
  743. have seen degraded performance due to contention on that mutex.
  744. To help such servers, <code>Regexp</code> now has a
  745. <a href="/pkg/regexp/#Regexp.Copy"><code>Copy</code></a> method,
  746. which makes a copy of a <code>Regexp</code> that shares most of the structure
  747. of the original but has its own scratch space cache.
  748. Two goroutines can use different copies of a <code>Regexp</code>
  749. without mutex contention.
  750. A copy does have additional space overhead, so <code>Copy</code>
  751. should only be used when contention has been observed.
  752. </li>
  753. <li>
  754. The <a href="/pkg/strconv/"><code>strconv</code></a> package adds
  755. <a href="/pkg/strconv/#IsGraphic"><code>IsGraphic</code></a>,
  756. similar to <a href="/pkg/strconv/#IsPrint"><code>IsPrint</code></a>.
  757. It also adds
  758. <a href="/pkg/strconv/#QuoteToGraphic"><code>QuoteToGraphic</code></a>,
  759. <a href="/pkg/strconv/#QuoteRuneToGraphic"><code>QuoteRuneToGraphic</code></a>,
  760. <a href="/pkg/strconv/#AppendQuoteToGraphic"><code>AppendQuoteToGraphic</code></a>,
  761. and
  762. <a href="/pkg/strconv/#AppendQuoteRuneToGraphic"><code>AppendQuoteRuneToGraphic</code></a>,
  763. analogous to
  764. <a href="/pkg/strconv/#QuoteToASCII"><code>QuoteToASCII</code></a>,
  765. <a href="/pkg/strconv/#QuoteRuneToASCII"><code>QuoteRuneToASCII</code></a>,
  766. and so on.
  767. The <code>ASCII</code> family escapes all space characters except ASCII space (U+0020).
  768. In contrast, the <code>Graphic</code> family does not escape any Unicode space characters (category Zs).
  769. </li>
  770. <li>
  771. In the <a href="/pkg/testing/"><code>testing</code></a> package,
  772. when a test calls
  773. <a href="/pkg/testing/#T.Parallel">t.Parallel</a>,
  774. that test is paused until all non-parallel tests complete, and then
  775. that test continues execution with all other parallel tests.
  776. Go 1.6 changes the time reported for such a test:
  777. previously the time counted only the parallel execution,
  778. but now it also counts the time from the start of testing
  779. until the call to <code>t.Parallel</code>.
  780. </li>
  781. <li>
  782. The <a href="/pkg/text/template/"><code>text/template</code></a> package
  783. contains two minor changes, in addition to the <a href="#template">major changes</a>
  784. described above.
  785. First, it adds a new
  786. <a href="/pkg/text/template/#ExecError"><code>ExecError</code></a> type
  787. returned for any error during
  788. <a href="/pkg/text/template/#Template.Execute"><code>Execute</code></a>
  789. that does not originate in a <code>Write</code> to the underlying writer.
  790. Callers can distinguish template usage errors from I/O errors by checking for
  791. <code>ExecError</code>.
  792. Second, the
  793. <a href="/pkg/text/template/#Template.Funcs"><code>Funcs</code></a> method
  794. now checks that the names used as keys in the
  795. <a href="/pkg/text/template/#FuncMap"><code>FuncMap</code></a>
  796. are identifiers that can appear in a template function invocation.
  797. If not, <code>Funcs</code> panics.
  798. </li>
  799. <li>
  800. The <a href="/pkg/time/"><code>time</code></a> package's
  801. <a href="/pkg/time/#Parse"><code>Parse</code></a> function has always rejected any day of month larger than 31,
  802. such as January 32.
  803. In Go 1.6, <code>Parse</code> now also rejects February 29 in non-leap years,
  804. February 30, February 31, April 31, June 31, September 31, and November 31.
  805. </li>
  806. </ul>