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