github.com/FenixAra/go@v0.0.0-20170127160404-96ea0918e670/doc/go1.8.html (about) 1 <!--{ 2 "Title": "Go 1.8 Release Notes", 3 "Path": "/doc/go1.8", 4 "Template": true 5 }--> 6 7 <!-- 8 NOTE: In this document and others in this directory, the convention is to 9 set fixed-width phrases with non-fixed-width spaces, as in 10 <code>hello</code> <code>world</code>. 11 Do not send CLs removing the interior tags from such phrases. 12 --> 13 14 <style> 15 ul li { margin: 0.5em 0; } 16 </style> 17 18 <h2 id="introduction">DRAFT RELEASE NOTES - Introduction to Go 1.8</h2> 19 20 <p><strong> 21 Go 1.8 is not yet released. These are work-in-progress 22 release notes. Go 1.8 is expected to be released in February 2017. 23 </strong></p> 24 25 <p> 26 The latest Go release, version 1.8, arrives six months after <a href="go1.7">Go 1.7</a>. 27 Most of its changes are in the implementation of the toolchain, runtime, and libraries. 28 There are <a href="#language">two minor changes</a> to the language specification. 29 As always, the release maintains the Go 1 <a href="/doc/go1compat.html">promise of compatibility</a>. 30 We expect almost all Go programs to continue to compile and run as before. 31 </p> 32 33 <p> 34 The release <a href="#ports">adds support for 32-bit MIPS</a>, 35 <a href="#compiler">updates the compiler back end</a> to generate more efficient code, 36 <a href="#gc">reduces GC pauses</a> by eliminating stop-the-world stack rescanning, 37 <a href="#h2push">adds HTTP/2 Push support</a>, 38 <a href="#http_shutdown">adds HTTP graceful shutdown</a>, 39 <a href="#more_context">adds more context support</a>, 40 <a href="#mutex_prof">enables profiling mutexes</a>, 41 and <a href="#sort_slice">simplifies sorting slices</a>. 42 </p> 43 44 <h2 id="language">Changes to the language</h2> 45 46 <p> 47 When explicitly converting a value from one struct type to another, 48 as of Go 1.8 the tags are ignored. Thus two structs that differ 49 only in their tags may be converted from one to the other: 50 </p> 51 52 <pre> 53 func example() { 54 type T1 struct { 55 X int `json:"foo"` 56 } 57 type T2 struct { 58 X int `json:"bar"` 59 } 60 var v1 T1 61 var v2 T2 62 v1 = T1(v2) // now legal 63 } 64 </pre> 65 66 67 <p> <!-- CL 17711 --> 68 The language specification now only requires that implementations 69 support up to 16-bit exponents in floating-point constants. This does not affect 70 either the “<a href="/cmd/compile/"><code>gc</code></a>” or 71 <code>gccgo</code> compilers, both of 72 which still support 32-bit exponents. 73 </p> 74 75 <h2 id="ports">Ports</h2> 76 77 <p> 78 Go now supports 32-bit MIPS on Linux for both big-endian 79 (<code>linux/mips</code>) and little-endian machines 80 (<code>linux/mipsle</code>) that implement the MIPS32r1 instruction set with FPU 81 or kernel FPU emulation. Note that many common MIPS-based routers lack an FPU and 82 have firmware that doesn't enable kernel FPU emulation; Go won't run on such machines. 83 </p> 84 85 <p> 86 On DragonFly BSD, Go now requires DragonFly 4.4.4 or later. <!-- CL 29491, CL 29971 --> 87 </p> 88 89 <p> 90 On OpenBSD, Go now requires OpenBSD 5.9 or later. <!-- CL 34093 --> 91 </p> 92 93 <p> 94 The Plan 9 port's networking support is now much more complete 95 and matches the behavior of Unix and Windows with respect to deadlines 96 and cancelation. For Plan 9 kernel requirements, see the 97 <a href="https://golang.org/wiki/Plan9">Plan 9 wiki page</a>. 98 </p> 99 100 <p> 101 Go 1.8 now only supports OS X 10.8 or later. This is likely the last 102 Go release to support 10.8. Compiling Go or running 103 binaries on older OS X versions is untested. 104 </p> 105 106 <p> 107 Go 1.8 will be the last release to support Linux on ARMv5E and ARMv6 processors: 108 Go 1.9 will likely require the ARMv6K (as found in the Raspberry Pi 1) or later. 109 To identify whether a Linux system is ARMv6K or later, run 110 “<code>go</code> <code>tool</code> <code>dist</code> <code>-check-armv6k</code>” 111 (to facilitate testing, it is also possible to just copy the <code>dist</code> command to the 112 system without installing a full copy of Go 1.8) 113 and if the program terminates with output "ARMv6K supported." then the system 114 implements ARMv6K or later. 115 Go on non-Linux ARM systems already requires ARMv6K or later. 116 </p> 117 118 119 <h3 id="known_issues">Known Issues</h3> 120 121 <p> 122 There are some instabilities on FreeBSD and NetBSD that are known but not understood. 123 These can lead to program crashes in rare cases. 124 See 125 <a href="https://golang.org/issue/15658">issue 15658</a> and 126 <a href="https://golang.org/issue/16511">issue 16511</a>. 127 Any help in solving these issues would be appreciated. 128 </p> 129 130 <h2 id="tools">Tools</h2> 131 132 <h3 id="cmd_asm">Assembler</h3> 133 134 <p> 135 For 64-bit x86 systems, the following instructions have been added: 136 <code>VBROADCASTSD</code>, 137 <code>BROADCASTSS</code>, 138 <code>MOVDDUP</code>, 139 <code>MOVSHDUP</code>, 140 <code>MOVSLDUP</code>, 141 <code>VMOVDDUP</code>, 142 <code>VMOVSHDUP</code>, and 143 <code>VMOVSLDUP</code>. 144 </p> 145 146 <p> 147 For 64-bit PPC systems, the common vector scalar instructions have been 148 added: 149 <code>LXS</code>, 150 <code>LXSDX</code>, 151 <code>LXSI</code>, 152 <code>LXSIWAX</code>, 153 <code>LXSIWZX</code>, 154 <code>LXV</code>, 155 <code>LXVD2X</code>, 156 <code>LXVDSX</code>, 157 <code>LXVW4X</code>, 158 <code>MFVSR</code>, 159 <code>MFVSRD</code>, 160 <code>MFVSRWZ</code>, 161 <code>MTVSR</code>, 162 <code>MTVSRD</code>, 163 <code>MTVSRWA</code>, 164 <code>MTVSRWZ</code>, 165 <code>STXS</code>, 166 <code>STXSDX</code>, 167 <code>STXSI</code>, 168 <code>STXSIWX</code>, 169 <code>STXV</code>, 170 <code>STXVD2X</code>, 171 <code>STXVW4X</code>, 172 <code>XSCV</code>, 173 <code>XSCVDPSP</code>, 174 <code>XSCVDPSPN</code>, 175 <code>XSCVDPSXDS</code>, 176 <code>XSCVDPSXWS</code>, 177 <code>XSCVDPUXDS</code>, 178 <code>XSCVDPUXWS</code>, 179 <code>XSCVSPDP</code>, 180 <code>XSCVSPDPN</code>, 181 <code>XSCVSXDDP</code>, 182 <code>XSCVSXDSP</code>, 183 <code>XSCVUXDDP</code>, 184 <code>XSCVUXDSP</code>, 185 <code>XSCVX</code>, 186 <code>XSCVXP</code>, 187 <code>XVCV</code>, 188 <code>XVCVDPSP</code>, 189 <code>XVCVDPSXDS</code>, 190 <code>XVCVDPSXWS</code>, 191 <code>XVCVDPUXDS</code>, 192 <code>XVCVDPUXWS</code>, 193 <code>XVCVSPDP</code>, 194 <code>XVCVSPSXDS</code>, 195 <code>XVCVSPSXWS</code>, 196 <code>XVCVSPUXDS</code>, 197 <code>XVCVSPUXWS</code>, 198 <code>XVCVSXDDP</code>, 199 <code>XVCVSXDSP</code>, 200 <code>XVCVSXWDP</code>, 201 <code>XVCVSXWSP</code>, 202 <code>XVCVUXDDP</code>, 203 <code>XVCVUXDSP</code>, 204 <code>XVCVUXWDP</code>, 205 <code>XVCVUXWSP</code>, 206 <code>XVCVX</code>, 207 <code>XVCVXP</code>, 208 <code>XXLAND</code>, 209 <code>XXLANDC</code>, 210 <code>XXLANDQ</code>, 211 <code>XXLEQV</code>, 212 <code>XXLNAND</code>, 213 <code>XXLNOR</code>, 214 <code>XXLOR</code>, 215 <code>XXLORC</code>, 216 <code>XXLORQ</code>, 217 <code>XXLXOR</code>, 218 <code>XXMRG</code>, 219 <code>XXMRGHW</code>, 220 <code>XXMRGLW</code>, 221 <code>XXPERM</code>, 222 <code>XXPERMDI</code>, 223 <code>XXSEL</code>, 224 <code>XXSI</code>, 225 <code>XXSLDWI</code>, 226 <code>XXSPLT</code>, and 227 <code>XXSPLTW</code>. 228 </p> 229 230 <h3 id="tool_yacc">Yacc</h3> 231 232 <p> <!-- CL 27324, CL 27325 --> 233 The <code>yacc</code> tool (previously available by running 234 “<code>go</code> <code>tool</code> <code>yacc</code>”) has been removed. 235 As of Go 1.7 it was no longer used by the Go compiler. 236 It has moved to the “tools” repository and is now available at 237 <code><a href="https://godoc.org/golang.org/x/tools/cmd/goyacc">golang.org/x/tools/cmd/goyacc</a></code>. 238 </p> 239 240 <h3 id="tool_fix">Fix</h3> 241 242 <p> <!-- CL 28872 --> 243 The <code>fix</code> tool has a new “<code>context</code>” 244 fix to change imports from “<code>golang.org/x/net/context</code>” 245 to “<a href="/pkg/context/"><code>context</code></a>”. 246 </p> 247 248 <h3 id="tool_pprof">Pprof</h3> 249 250 <p> <!-- CL 33157 --> 251 The <code>pprof</code> tool can now profile TLS servers 252 and skip certificate validation by using the “<code>https+insecure</code>” 253 URL scheme. 254 </p> 255 256 <p> <!-- CL 23781 --> 257 The callgrind output now has instruction-level granularity. 258 </p> 259 260 <h3 id="tool_trace">Trace</h3> 261 262 <p> <!-- CL 23324 --> 263 The <code>trace</code> tool has a new <code>-pprof</code> flag for 264 producing pprof-compatible blocking and latency profiles from an 265 execution trace. 266 </p> 267 268 <p> <!-- CL 30017, CL 30702 --> 269 Garbage collection events are now shown more clearly in the 270 execution trace viewer. Garbage collection activity is shown on its 271 own row and GC helper goroutines are annotated with their roles. 272 </p> 273 274 <h3 id="tool_vet">Vet</h3> 275 276 <p>Vet is stricter in some ways and looser where it 277 previously caused false positives.</p> 278 279 <p>Vet now checks for copying an array of locks, 280 duplicate JSON and XML struct field tags, 281 non-space-separated struct tags, 282 deferred calls to HTTP <code>Response.Body.Close</code> 283 before checking errors, and 284 indexed arguments in <code>Printf</code>. 285 It also improves existing checks.</p> 286 </p> 287 288 <h3 id="compiler">Compiler Toolchain</h3> 289 290 <p> 291 Go 1.7 introduced a new compiler back end for 64-bit x86 systems. 292 In Go 1.8, that back end has been developed further and is now used for 293 all architectures. 294 </p> 295 296 <p> 297 The new back end, based on 298 <a href="https://en.wikipedia.org/wiki/Static_single_assignment_form">static single assignment form</a> (SSA), 299 generates more compact, more efficient code 300 and provides a better platform for optimizations 301 such as bounds check elimination. 302 The new back end reduces the CPU time required by 303 <a href="https://golang.org/test/bench/go1/">our benchmark programs</a> by 20-30% 304 on 32-bit ARM systems. For 64-bit x86 systems, which already used the SSA back end in 305 Go 1.7, the gains are a more modest 0-10%. Other architectures will likely 306 see improvements closer to the 32-bit ARM numbers. 307 </p> 308 309 <p> 310 The temporary <code>-ssa=0</code> compiler flag introduced in Go 1.7 311 to disable the new back end has been removed in Go 1.8. 312 </p> 313 314 <p> 315 In addition to enabling the new compiler back end for all systems, 316 Go 1.8 also introduces a new compiler front end. The new compiler 317 front end should not be noticeable to users but is the foundation for 318 future performance work. 319 </p> 320 321 <p> 322 The compiler and linker have been optimized and run faster in this 323 release than in Go 1.7, although they are still slower than we would 324 like and will continue to be optimized in future releases. 325 Compared to the previous release, Go 1.8 is 326 <a href="https://dave.cheney.net/2016/11/19/go-1-8-toolchain-improvements">about 15% faster</a>. 327 </p> 328 329 <h3 id="cmd_cgo">Cgo</h3> 330 331 <p> <!-- CL 31141 --> 332 The Go tool now remembers the value of the <code>CGO_ENABLED</code> environment 333 variable set during <code>make.bash</code> and applies it to all future compilations 334 by default to fix issue <a href="https://golang.org/issue/12808">#12808</a>. 335 When doing native compilation, it is rarely necessary to explicitly set 336 the <code>CGO_ENABLED</code> environment variable as <code>make.bash</code> 337 will detect the correct setting automatically. The main reason to explicitly 338 set the <code>CGO_ENABLED</code> environment variable is when your environment 339 supports cgo, but you explicitly do not want cgo support, in which case, set 340 <code>CGO_ENABLED=0</code> during <code>make.bash</code> or <code>all.bash</code>. 341 </p> 342 343 <p> <!-- CL 29991 --> 344 The environment variable <code>PKG_CONFIG</code> may now be used to 345 set the program to run to handle <code>#cgo</code> <code>pkg-config</code> 346 directives. The default is <code>pkg-config</code>, the program 347 always used by earlier releases. This is intended to make it easier 348 to cross-compile 349 <a href="/cmd/cgo/">cgo</a> code. 350 </p> 351 352 <p> <!-- CL 32354 --> 353 The <a href="/cmd/cgo/">cgo</a> tool now supports a <code>-srcdir</code> 354 option, which is used by the <a href="/cmd/go/">go</a> command. 355 </p> 356 357 <p> <!-- CL 31768, 31811 --> 358 If <a href="/cmd/cgo/">cgo</a> code calls <code>C.malloc</code>, and 359 <code>malloc</code> returns <code>NULL</code>, the program will now 360 crash with an out of memory error. 361 <code>C.malloc</code> will never return <code>nil</code>. 362 Unlike most C functions, <code>C.malloc</code> may not be used in a 363 two-result form returning an errno value. 364 </p> 365 366 <p> <!-- CL 33237 --> 367 If <a href="/cmd/cgo/">cgo</a> is used to call a C function passing a 368 pointer to a C union, and if the C union can contain any pointer 369 values, and if <a href="/cmd/cgo/#hdr-Passing_pointers">cgo pointer 370 checking</a> is enabled (as it is by default), the union value is now 371 checked for Go pointers. 372 </p> 373 374 <h3 id="gccgo">Gccgo</h3> 375 376 <p> 377 Due to the alignment of Go's semiannual release schedule with GCC's 378 annual release schedule, 379 GCC release 6 contains the Go 1.6.1 version of gccgo. 380 We expect that the next release, GCC 7, will contain the Go 1.8 381 version of gccgo. 382 </p> 383 384 <h3 id="gopath">Default GOPATH</h3> 385 386 <p> 387 The 388 <a href="/cmd/go/#hdr-GOPATH_environment_variable"><code>GOPATH</code> 389 environment variable</a> now has a default value if it 390 is unset. It defaults to 391 <code>$HOME/go</code> on Unix and 392 <code>%USERPROFILE%/go</code> on Windows. 393 </p> 394 395 <h3 id="go_get">Go get</h3> 396 397 <p> <!-- CL 34818 --> 398 The “<code>go</code> <code>get</code>” command now always respects 399 HTTP proxy environment variables, regardless of whether 400 the <code style='white-space:nowrap'>-insecure</code> flag is used. In previous releases, the 401 <code style='white-space:nowrap'>-insecure</code> flag had the side effect of not using proxies. 402 </p> 403 404 <h3 id="go_bug">Go bug</h3> 405 406 <p> 407 The new 408 “<a href="/cmd/go/#hdr-Print_information_for_bug_reports"><code>go</code> <code>bug</code></a>” 409 command starts a bug report on GitHub, prefilled 410 with information about the current system. 411 </p> 412 413 <h3 id="cmd_doc">Go doc</h3> 414 415 <p> <!-- CL 25419 --> 416 The 417 “<a href="/cmd/go/#hdr-Show_documentation_for_package_or_symbol"><code>go</code> <code>doc</code></a>” 418 command now groups constants and variables with their type, 419 following the behavior of 420 <a href="/cmd/godoc/"><code>godoc</code></a>. 421 </p> 422 423 <p> <!-- CL 25420 --> 424 In order to improve the readability of <code>doc</code>'s 425 output, each summary of the first-level items is guaranteed to 426 occupy a single line. 427 </p> 428 429 <p> <!-- CL 31852 --> 430 Documentation for a specific method in an interface definition can 431 now be requested, as in 432 “<code>go</code> <code>doc</code> <code>net.Conn.SetDeadline</code>”. 433 </p> 434 435 <h3 id="plugin">Plugins</h3> 436 437 <p> 438 Go now provides early support for plugins with a “<code>plugin</code>” 439 build mode for generating plugins written in Go, and a 440 new <a href="/pkg/plugin/"><code>plugin</code></a> package for 441 loading such plugins at run time. Plugin support is currently only 442 available on Linux. Please report any issues. 443 </p> 444 445 <h2 id="runtime">Runtime</h2> 446 447 <h3 id="liveness">Argument Liveness</h3> 448 449 <p> 450 <!-- Issue 15843 --> The garbage collector no longer considers 451 arguments live throughout the entirety of a function. For more 452 information, and for how to force a variable to remain live, see 453 the <a href="/pkg/runtime/#KeepAlive"><code>runtime.KeepAlive</code></a> 454 function added in Go 1.7. 455 </p> 456 457 <p> 458 <i>Updating:</i> 459 Code that sets a finalizer on an allocated object may need to add 460 calls to <code>runtime.KeepAlive</code> in functions or methods 461 using that object. 462 Read the 463 <a href="/pkg/runtime/#KeepAlive"><code>KeepAlive</code> 464 documentation</a> and its example for more details. 465 </p> 466 467 <h3 id="mapiter">Concurrent Map Misuse</h3> 468 469 <p> 470 In Go 1.6, the runtime 471 <a href="/doc/go1.6#runtime">added lightweight, 472 best-effort detection of concurrent misuse of maps</a>. This release 473 improves that detector with support for detecting programs that 474 concurrently write to and iterate over a map. 475 </p> 476 <p> 477 As always, if one goroutine is writing to a map, no other goroutine should be 478 reading (which includes iterating) or writing the map concurrently. 479 If the runtime detects this condition, it prints a diagnosis and crashes the program. 480 The best way to find out more about the problem is to run the program 481 under the 482 <a href="https://blog.golang.org/race-detector">race detector</a>, 483 which will more reliably identify the race 484 and give more detail. 485 </p> 486 487 <h3 id="memstats">MemStats Documentation</h3> 488 489 <p> <!-- CL 28972 --> 490 The <a href="/pkg/runtime/#MemStats"><code>runtime.MemStats</code></a> 491 type has been more thoroughly documented. 492 </p> 493 494 <h2 id="performance">Performance</h2> 495 496 <p> 497 As always, the changes are so general and varied that precise statements 498 about performance are difficult to make. 499 Most programs should run a bit faster, 500 due to speedups in the garbage collector and 501 optimizations in the standard library. 502 </p> 503 504 <p> 505 There have been optimizations to implementations in the 506 <a href="/pkg/bytes/"><code>bytes</code></a>, 507 <a href="/pkg/crypto/aes/"><code>crypto/aes</code></a>, 508 <a href="/pkg/crypto/cipher/"><code>crypto/cipher</code></a>, 509 <a href="/pkg/crypto/elliptic/"><code>crypto/elliptic</code></a>, 510 <a href="/pkg/crypto/sha256/"><code>crypto/sha256</code></a>, 511 <a href="/pkg/crypto/sha512/"><code>crypto/sha512</code></a>, 512 <a href="/pkg/encoding/asn1/"><code>encoding/asn1</code></a>, 513 <a href="/pkg/encoding/csv/"><code>encoding/csv</code></a>, 514 <a href="/pkg/encoding/hex/"><code>encoding/hex</code></a>, 515 <a href="/pkg/encoding/json/"><code>encoding/json</code></a>, 516 <a href="/pkg/hash/crc32/"><code>hash/crc32</code></a>, 517 <a href="/pkg/image/color/"><code>image/color</code></a>, 518 <a href="/pkg/image/draw/"><code>image/draw</code></a>, 519 <a href="/pkg/math/"><code>math</code></a>, 520 <a href="/pkg/math/big/"><code>math/big</code></a>, 521 <a href="/pkg/reflect/"><code>reflect</code></a>, 522 <a href="/pkg/regexp/"><code>regexp</code></a>, 523 <a href="/pkg/runtime/"><code>runtime</code></a>, 524 <a href="/pkg/strconv/"><code>strconv</code></a>, 525 <a href="/pkg/strings/"><code>strings</code></a>, 526 <a href="/pkg/syscall/"><code>syscall</code></a>, 527 <a href="/pkg/text/template/"><code>text/template</code></a>, and 528 <a href="/pkg/unicode/utf8/"><code>unicode/utf8</code></a> 529 packages. 530 </p> 531 532 <h3 id="gc">Garbage Collector</h3> 533 534 <p> 535 Garbage collection pauses should be significantly shorter than they 536 were in Go 1.7, usually under 100 microseconds and often as low as 537 10 microseconds. 538 See the 539 <a href="https://github.com/golang/proposal/blob/master/design/17503-eliminate-rescan.md" 540 >document on eliminating stop-the-world stack re-scanning</a> 541 for details. More work remains for Go 1.9. 542 </p> 543 544 <h3 id="defer">Defer</h3> 545 546 <!-- CL 29656, CL 29656 --> 547 <p> 548 The overhead of <a href="/ref/spec/#Defer_statements">deferred 549 function calls</a> has been reduced by about half. 550 </p> 551 552 <h3 id="cgoperf">Cgo</h3> 553 554 <p>The overhead of calls from Go into C has been reduced by about half.</p> 555 556 <h2 id="library">Standard library</h2> 557 558 <h3 id="examples">Examples</h3> 559 560 <p> 561 Examples have been added to the documentation across many packages. 562 </p> 563 564 <h3 id="sort_slice">Sort</h3> 565 566 <p> 567 The <a href="/pkg/sort/">sort</a> package 568 now includes a convenience function 569 <a href="/pkg/sort/#Slice"><code>Slice</code></a> to sort a 570 slice given a <em>less</em> function. 571 572 In many cases this means that writing a new sorter type is not 573 necessary. 574 </p> 575 576 <p> 577 Also new are 578 <a href="/pkg/sort/#SliceStable"><code>SliceStable</code></a> and 579 <a href="/pkg/sort/#SliceIsSorted"><code>SliceIsSorted</code></a>. 580 </p> 581 582 <h3 id="h2push">HTTP/2 Push</h3> 583 584 <p> 585 The <a href="/pkg/net/http/">net/http</a> package now includes a 586 mechanism to 587 send HTTP/2 server pushes from a 588 <a href="/pkg/net/http/#Handler"><code>Handler</code></a>. 589 Similar to the existing <code>Flusher</code> and <code>Hijacker</code> 590 interfaces, an HTTP/2 591 <a href="/pkg/net/http/#ResponseWriter"><code>ResponseWriter</code></a> 592 now implements the new 593 <a href="/pkg/net/http/#Pusher"><code>Pusher</code></a> interface. 594 </p> 595 596 <h3 id="http_shutdown">HTTP Server Graceful Shutdown</h3> 597 598 <p> <!-- CL 32329 --> 599 The HTTP Server now has support for graceful shutdown using the new 600 <a href="/pkg/net/http/#Server.Shutdown"><code>Server.Shutdown</code></a> 601 method and abrupt shutdown using the new 602 <a href="/pkg/net/http/#Server.Close"><code>Server.Close</code></a> 603 method. 604 </p> 605 606 <h3 id="more_context">More Context Support</h3> 607 608 <p> 609 Continuing <a href="/doc/go1.7#context">Go 1.7's adoption</a> 610 of <a href="/pkg/context/#Context"><code>context.Context</code></a> 611 into the standard library, Go 1.8 adds more context support 612 to existing packages: 613 </p> 614 615 <ul> 616 <li>The new <a href="/pkg/net/http/#Server.Shutdown"><code>Server.Shutdown</code></a> 617 takes a context argument.</li> 618 <li>There have been <a href="#database_sql">significant additions</a> to the 619 <a href="/pkg/database/sql/">database/sql</a> package with context support.</li> 620 <li>All nine of the new <code>Lookup</code> methods on the new 621 <a href="/pkg/net/#Resolver"><code>net.Resolver</code></a> now 622 take a context.</li> 623 </ul> 624 625 <h3 id="mutex_prof">Mutex Contention Profiling</h3> 626 627 <p> 628 The runtime and tools now support profiling contended mutexes. 629 </p> 630 631 <p> 632 Most users will want to use the new <code>-mutexprofile</code> 633 flag with “<a href="/cmd/go/#hdr-Description_of_testing_flags"><code>go</code> <code>test</code></a>”, 634 and then use <a href="/cmd/pprof/">pprof</a> on the resultant file. 635 </p> 636 637 <p> 638 Lower-level support is also available via the new 639 <a href="/pkg/runtime/#MutexProfile"><code>MutexProfile</code></a> 640 and 641 <a href="/pkg/runtime/#SetMutexProfileFraction"><code>SetMutexProfileFraction</code></a>. 642 </p> 643 644 <p> 645 A known limitation for Go 1.8 is that the profile only reports contention for 646 <a href="/pkg/sync/#Mutex"><code>sync.Mutex</code></a>, 647 not 648 <a href="/pkg/sync/#RWMutex"><code>sync.RWMutex</code></a>. 649 </p> 650 651 <h3 id="minor_library_changes">Minor changes to the library</h3> 652 653 <p> 654 As always, there are various minor changes and updates to the library, 655 made with the Go 1 <a href="/doc/go1compat">promise of compatibility</a> 656 in mind. The following sections list the user visible changes and additions. 657 Optimizations and minor bug fixes are not listed. 658 </p> 659 660 <dl id="archive_tar"><dt><a href="/pkg/archive/tar/">archive/tar</a></dt> 661 <dd> 662 663 <p> <!-- CL 28471, CL 31440, CL 31441, CL 31444, CL 28418, CL 31439 --> 664 The tar implementation corrects many bugs in corner cases of the file format. 665 The <a href="/pkg/archive/tar/#Reader"><code>Reader</code></a> 666 is now able to process tar files in the PAX format with entries larger than 8GB. 667 The <a href="/pkg/archive/tar/#Writer"><code>Writer</code></a> 668 no longer produces invalid tar files in some situations involving long pathnames. 669 </p> 670 671 </dd> 672 </dl> 673 674 <dl id="compress_flate"><dt><a href="/pkg/compress/flate/">compress/flate</a></dt> 675 <dd> 676 677 <p> <!-- CL 31640, CL 31174, CL 32149 --> 678 There have been some minor fixes to the encoder to improve the 679 compression ratio in certain situations. As a result, the exact 680 encoded output of <code>DEFLATE</code> may be different from Go 1.7. Since 681 <code>DEFLATE</code> is the underlying compression of gzip, png, zlib, and zip, 682 those formats may have changed outputs. 683 </p> 684 685 <p> <!-- CL 31174 --> 686 The encoder, when operating in 687 <a href="/pkg/compress/flate/#NoCompression"><code>NoCompression</code></a> 688 mode, now produces a consistent output that is not dependent on 689 the size of the slices passed to the 690 <a href="/pkg/compress/flate/#Writer.Write"><code>Write</code></a> 691 method. 692 </p> 693 694 <p> <!-- CL 28216 --> 695 The decoder, upon encountering an error, now returns any 696 buffered data it had uncompressed along with the error. 697 </p> 698 699 </dd> 700 </dl> 701 702 703 <dl id="compress_gzip"><dt><a href="/pkg/compress/gzip/">compress/gzip</a></dt> 704 <dd> 705 706 <p> 707 The <a href="/pkg/compress/gzip/#Writer"><code>Writer</code></a> 708 now encodes a zero <code>MTIME</code> field when 709 the <a href="/pkg/compress/gzip/#Header"><code>Header.ModTime</code></a> 710 field is the zero value. 711 712 In previous releases of Go, the <code>Writer</code> would encode 713 a nonsensical value. 714 715 Similarly, 716 the <a href="/pkg/compress/gzip/#Reader"><code>Reader</code></a> 717 now reports a zero encoded <code>MTIME</code> field as a zero 718 <code>Header.ModTime</code>. 719 </p> 720 721 </dd> 722 </dl> 723 724 <dl id="context"><dt><a href="/pkg/context/">context</a></dt> 725 <dd> 726 <p> <!-- CL 30370 --> 727 The <a href="/pkg/context#DeadlineExceeded"><code>DeadlineExceeded</code></a> 728 error now implements 729 <a href="/pkg/net/#Error"><code>net.Error</code></a> 730 and reports true for both the <code>Timeout</code> and 731 <code>Temporary</code> methods. 732 </p> 733 </dd> 734 </dl> 735 736 <dl id="crypto_tls"><dt><a href="/pkg/crypto/tls/">crypto/tls</a></dt> 737 <dd> 738 <p> <!-- CL 25159, CL 31318 --> 739 The new method 740 <a href="/pkg/crypto/tls/#Conn.CloseWrite"><code>Conn.CloseWrite</code></a> 741 allows TLS connections to be half closed. 742 </p> 743 744 <p> <!-- CL 28075 --> 745 The new method 746 <a href="/pkg/crypto/tls/#Config.Clone"><code>Config.Clone</code></a> 747 clones a TLS configuration. 748 </p> 749 750 <p> 751 <!-- CL 30790 --> 752 The new <a href="/pkg/crypto/tls/#Config.GetConfigForClient"><code>Config.GetConfigForClient</code></a> 753 callback allows selecting a configuration for a client dynamically, based 754 on the client's 755 <a href="/pkg/crypto/tls/#ClientHelloInfo"><code>ClientHelloInfo</code></a>. 756 757 <!-- CL 31391, CL 32119 --> 758 The <a href="/pkg/crypto/tls/#ClientHelloInfo"><code>ClientHelloInfo</code></a> 759 struct now has new 760 fields <code>Conn</code>, <code>SignatureSchemes</code> (using 761 the new 762 type <a href="/kg/crypto/tls/#SignatureScheme"><code>SignatureScheme</code></a>), 763 <code>SupportedProtos</code>, and <code>SupportedVersions</code>. 764 </p> 765 766 <p> <!-- CL 32115 --> 767 The new <a href="/pkg/crypto/tls/#Config.GetClientCertificate"><code>Config.GetClientCertificate</code></a> 768 callback allows selecting a client certificate based on the server's 769 TLS <code>CertificateRequest</code> message, represented by the new 770 <a href="/pkg/crypto/tls/#CertificateRequestInfo"><code>CertificateRequestInfo</code></a>. 771 </p> 772 773 <p> <!-- CL 27434 --> 774 The new 775 <a href="/pkg/crypto/tls/#Config.KeyLogWriter"><code>Config.KeyLogWriter</code></a> 776 allows debugging TLS connections 777 in <a href="https://www.wireshark.org/">WireShark</a> and 778 similar tools. 779 </p> 780 781 <p> <!-- CL 32115 --> 782 The new 783 <a href="/pkg/crypto/tls/#Config.VerifyPeerCertificate"><code>Config.VerifyPeerCertificate</code></a> 784 callback allows additional validation of a peer's presented certificate. 785 </p> 786 787 <p> <!-- CL 18130 --> 788 The <code>crypto/tls</code> package now implements basic 789 countermeasures against CBC padding oracles. There should be 790 no explicit secret-dependent timings, but it does not attempt to 791 normalize memory accesses to prevent cache timing leaks. 792 </p> 793 794 <p> 795 The <code>crypto/tls</code> package now supports 796 X25519 and <!-- CL 30824, CL 30825 --> 797 ChaCha20-Poly1305. <!-- CL 30957, CL 30958 --> 798 ChaCha20-Poly1305 is now prioritized unless <!-- CL 32871 --> 799 hardware support for AES-GCM is present. 800 </p> 801 802 <p> <!-- CL 27315 --> 803 AES-128-CBC cipher suites with SHA-256 are also 804 now supported. 805 </p> 806 807 </dd> 808 </dl> 809 810 <dl id="crypto_x509"><dt><a href="/pkg/crypto/x509/">crypto/x509</a></dt> 811 <dd> 812 <p> <!-- CL 24743 --> 813 PSS signatures are now supported. 814 </p> 815 816 <p> <!-- CL 32644 --> 817 <a href="/pkg/crypto/x509/#UnknownAuthorityError"><code>UnknownAuthorityError</code></a> 818 now has a <code>Cert</code> field, reporting the untrusted 819 certificate. 820 </p> 821 822 <p> 823 Certificate validation is more permissive in a few cases and 824 stricter in a few other cases. 825 <!-- 826 crypto/x509: allow a leaf certificate to be specified directly as root (CL 27393) 827 crypto/x509: check that the issuer name matches the issuer's subject name (CL 23571) 828 crypto/x509: don't accept a root that already appears in a chain. (CL 32121) 829 crypto/x509: fix name constraints handling (CL 30155) 830 crypto/x509: parse all names in an RDN (CL 30810) 831 crypto/x509: recognise ISO OID for RSA+SHA1 (CL 27394) 832 crypto/x509: require a NULL parameters for RSA public keys (CL 16166, CL 27312) 833 crypto/x509: return error for missing SerialNumber (CL 27238) 834 --> 835 </p> 836 837 <p><!-- CL 30375 --> 838 Root certificates will now also be looked for 839 at <code>/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem</code> 840 on Linux, to support RHEL and CentOS. 841 </p> 842 843 </dd> 844 </dl> 845 846 <dl id="database_sql"><dt><a href="/pkg/database/sql/">database/sql</a></dt> 847 <dd> 848 <p> 849 The package now supports <code>context.Context</code>. There are new methods 850 ending in <code>Context</code> such as 851 <a href="/pkg/database/sql/#DB.QueryContext"><code>DB.QueryContext</code></a> and 852 <a href="/pkg/database/sql/#DB.PrepareContext"><code>DB.PrepareContext</code></a> 853 that take context arguments. Using the new <code>Context</code> methods ensures that 854 connections are closed and returned to the connection pool when the 855 request is done; enables canceling in-progress queries 856 should the driver support that; and allows the database 857 pool to cancel waiting for the next available connection. 858 </p> 859 <p> 860 The <a href="/pkg/database/sql#IsolationLevel"><code>IsolationLevel</code></a> 861 can now be set when starting a transaction by setting the isolation level 862 on the <code>Context</code> then passing that <code>Context</code> to 863 <a href="/pkg/database/sql#DB.BeginContext"><code>DB.BeginContext</code></a>. 864 An error will be returned if an isolation level is selected that the driver 865 does not support. A read-only attribute may also be set on the transaction 866 with <a href="/pkg/database/sql/#ReadOnlyContext"><code>ReadOnlyContext</code></a>. 867 </p> 868 <p> 869 Queries now expose the SQL column type information for drivers that support it. 870 Rows can return <a href="/pkg/database/sql#Rows.ColumnTypes"><code>ColumnTypes</code></a> 871 which can include SQL type information, column type lengths, and the Go type. 872 </p> 873 <p> 874 A <a href="/pkg/database/sql/#Rows"><code>Rows</code></a> 875 can now represent multiple result sets. After 876 <a href="/pkg/database/sql/#Rows.Next"><code>Rows.Next</code></a> returns false, 877 <a href="/pkg/database/sql/#Rows.NextResultSet"><code>Rows.NextResultSet</code></a> 878 may be called to advance to the next result set. The existing <code>Rows</code> 879 should continue to be used after it advances to the next result set. 880 </p> 881 <p> 882 <a href="/pkg/database/sql/#NamedArg"><code>NamedArg</code></a> may be used 883 as query arguments. The new function <a href="/pkg/database/sql/#Named"><code>Named</code></a> 884 helps create a <a href="/pkg/database/sql/#NamedArg"><code>NamedArg</code></a> 885 more succinctly. 886 <p> 887 If a driver supports the new 888 <a href="/pkg/database/sql/driver/#Pinger"><code>Pinger</code></a> 889 interface, the 890 <a href="/pkg/database/sql/#DB.Ping"><code>DB.Ping</code></a> 891 and 892 <a href="/pkg/database/sql/#DB.PingContext"><code>DB.PingContext</code></a> 893 methods will use that interface to check whether a 894 database connection is still valid. 895 </p> 896 <p> 897 The new <code>Context</code> query methods work for all drivers, but 898 <code>Context</code> cancelation is not responsive unless the driver has been 899 updated to use them. The other features require driver support in 900 <a href="/pkg/database/sql/driver"><code>database/sql/driver</code></a>. 901 Driver authors should review the new interfaces. Users of existing 902 driver should review the driver documentation to see what 903 it supports and any system specific documentation on each feature. 904 </p> 905 </dd> 906 </dl> 907 908 <dl id="debug_pe"><dt><a href="/pkg/debug/pe/">debug/pe</a></dt> 909 <dd> 910 <p> <!-- CL 22720, CL 27212, CL 22181, CL 22332, CL 22336, Issue 15345 --> 911 The package has been extended and is now used by 912 <a href="/cmd/link/">the Go linker</a> to read <code>gcc</code>-generated object files. 913 The new 914 <a href="/pkg/debug/pe/#File.StringTable"><code>File.StringTable</code></a> 915 and 916 <a href="/pkg/debug/pe/#Section.Relocs"><code>Section.Relocs</code></a> 917 fields provide access to the COFF string table and COFF relocations. 918 The new 919 <a href="/pkg/debug/pe/#File.COFFSymbols"><code>File.COFFSymbols</code></a> 920 allows low-level access to the COFF symbol table. 921 </p> 922 </dd> 923 </dl> 924 925 <dl id="encoding_base64"><dt><a href="/pkg/encoding/base64/">encoding/base64</a></dt> 926 <dd> 927 <p> <!-- CL 24964 --> 928 The new 929 <a href="/pkg/encoding/base64/#Encoding.Strict"><code>Encoding.Strict</code></a> 930 method returns an <code>Encoding</code> that causes the decoder 931 to return an error when the trailing padding bits are not zero. 932 </p> 933 </dd> 934 </dl> 935 936 <dl id="encoding_binary"><dt><a href="/pkg/encoding/binary/">encoding/binary</a></dt> 937 <dd> 938 <p> <!-- CL 28514 --> 939 <a href="/pkg/encoding/binary/#Read"><code>Read</code></a> 940 and 941 <a href="/pkg/encoding/binary/#Write"><code>Write</code></a> 942 now support booleans. 943 </p> 944 </dd> 945 </dl> 946 947 <dl id="encoding_json"><dt><a href="/pkg/encoding/json/">encoding/json</a></dt> 948 <dd> 949 950 <p> <!-- CL 18692 --> 951 <a href="/pkg/encoding/json/#UnmarshalTypeError"><code>UnmarshalTypeError</code></a> 952 now includes the struct and field name. 953 </p> 954 955 <p> <!-- CL 31932 --> 956 A nil <a href="/pkg/encoding/json/#Marshaler"><code>Marshaler</code></a> 957 now marshals as a JSON <code>null</code> value. 958 </p> 959 960 <p> <!-- CL 21811 --> 961 A <a href="/pkg/encoding/json/#RawMessage"><code>RawMessage</code></a> value now 962 marshals the same as its pointer type. 963 </p> 964 965 <p> <!-- CL 30371 --> 966 <a href="/pkg/encoding/json/#Marshal"><code>Marshal</code></a> 967 encodes floating-point numbers using the same format as in ES6, 968 preferring decimal (not exponential) notation for a wider range of values. 969 In particular, all floating-point integers up to 2<sup>64</sup> format the 970 same as the equivalent <code>int64</code> representation. 971 </p> 972 973 <p> <!-- CL 30944 --> 974 In previous versions of Go, unmarshaling a JSON <code>null</code> into an 975 <a href="/pkg/encoding/json/#Unmarshaler"><code>Unmarshaler</code></a> 976 was considered a no-op; now the <code>Unmarshaler</code>'s 977 <code>UnmarshalJSON</code> method is called with the JSON literal 978 <code>null</code> and can define the semantics of that case. 979 </p> 980 981 </dd> 982 </dl> 983 984 <dl id="encoding_pem"><dt><a href="/pkg/encoding/pem/">encoding/pem</a></dt> 985 <dd> 986 <p> <!-- CL 27391 --> 987 <a href="/pkg/encoding/pem/#Decode"><code>Decode</code></a> 988 is now strict about the format of the ending line. 989 </p> 990 </dd> 991 </dl> 992 993 <dl id="encoding_xml"><dt><a href="/pkg/encoding/xml/">encoding/xml</a></dt> 994 <dd> 995 <p> <!-- CL 30946 --> 996 <a href="/pkg/encoding/xml/#Unmarshal"><code>Unmarshal</code></a> 997 now has wildcard support for collecting all attributes using 998 the new <code>",any,attr"</code> struct tag. 999 </p> 1000 </dd> 1001 </dl> 1002 1003 <dl id="expvar"><dt><a href="/pkg/expvar/">expvar</a></dt> 1004 <dd> 1005 <p> <!-- CL 30917 --> 1006 The new methods 1007 <a href="/pkg/expvar/#Int.Value"><code>Int.Value</code></a>, 1008 <a href="/pkg/expvar/#String.Value"><code>String.Value</code></a>, 1009 <a href="/pkg/expvar/#Float.Value"><code>Float.Value</code></a>, and 1010 <a href="/pkg/expvar/#Func.Value"><code>Func.Value</code></a> 1011 report the current value of an exported variable. 1012 </p> 1013 1014 <p> <!-- CL 24722 --> 1015 The new 1016 function <a href="/pkg/expvar/#Handler"><code>Handler</code></a> 1017 returns the package's HTTP handler, to enable installing it in 1018 non-standard locations. 1019 </p> 1020 </dd> 1021 </dl> 1022 1023 <dl id="fmt"><dt><a href="/pkg/fmt/">fmt</a></dt> 1024 <dd> 1025 <p><!-- CL 30611 --> 1026 <a href="/pkg/fmt/#Scanf"><code>Scanf</code></a>, 1027 <a href="/pkg/fmt/#Fscanf"><code>Fscanf</code></a>, and 1028 <a href="/pkg/fmt/#Sscanf"><code>Sscanf</code></a> now 1029 handle spaces differently and more consistently than 1030 previous releases. See the 1031 <a href="/pkg/fmt/#hdr-Scanning">scanning documentation</a> 1032 for details. 1033 </p> 1034 </dd> 1035 </dl> 1036 1037 <dl id="go_doc"><dt><a href="/pkg/go/doc/">go/doc</a></dt> 1038 <dd> 1039 <p><!-- CL 29870 --> 1040 The new <a href="/pkg/go/doc/#IsPredeclared"><code>IsPredeclared</code></a> 1041 function reports whether a string is a predeclared identifier. 1042 </p> 1043 </dd> 1044 </dl> 1045 1046 <dl id="go_types"><dt><a href="/pkg/go/types/">go/types</a></dt> 1047 <dd> 1048 <p><!-- CL 30715 --> 1049 The new function 1050 <a href="/pkg/go/types/#Default"><code>Default</code></a> 1051 returns the default "typed" type for an "untyped" type. 1052 </p> 1053 1054 <p><!-- CL 31939 --> 1055 The alignment of <code>complex64</code> now matches 1056 the <a href="/cmd/compile/">Go compiler</a>. 1057 </p> 1058 </dd> 1059 </dl> 1060 1061 <dl id="html_template"><dt><a href="/pkg/html/template/">html/template</a></dt> 1062 <dd> 1063 <p><!-- CL 14336 --> 1064 The package now validates 1065 the <code>"type"</code> attribute on 1066 a <code><script></code> tag. 1067 </p> 1068 </dd> 1069 </dl> 1070 1071 <dl id="image_png"><dt><a href="/pkg/image/png/">image/png</a></dt> 1072 <dd> 1073 <p> <!-- CL 32143, CL 32140 --> 1074 <a href="/pkg/image/png/#Decode"><code>Decode</code></a> 1075 (and <code>DecodeConfig</code>) 1076 now supports True Color and grayscale transparency. 1077 </p> 1078 <p> <!-- CL 29872 --> 1079 <a href="/pkg/image/png/#Encoder"><code>Encoder</code></a> 1080 is now faster and creates smaller output 1081 when encoding paletted images. 1082 </p> 1083 </dd> 1084 </dl> 1085 1086 <dl id="math_big"><dt><a href="/pkg/math/big/">math/big</a></dt> 1087 <dd> 1088 <p><!-- CL 30706 --> 1089 The new method 1090 <a href="/pkg/math/big/#Int.Sqrt"><code>Int.Sqrt</code></a> 1091 calculates ⌊√x⌋. 1092 </p> 1093 1094 <p> 1095 The new method 1096 <a href="/pkg/math/big/#Float.Scan"><code>Float.Scan</code></a> 1097 is a support routine for 1098 <a href="/pkg/fmt/#Scanner"><code>fmt.Scanner</code></a>. 1099 </p> 1100 1101 <p> 1102 <a href="/pkg/math/big/#Int.ModInverse"><code>Int.ModInverse</code></a> 1103 now supports negative numbers. 1104 </p> 1105 1106 </dd> 1107 </dl> 1108 1109 <dl id="math_rand"><dt><a href="/pkg/math/rand/">math/rand</a></dt> 1110 <dd> 1111 1112 <p><!-- CL 27253, CL 33456 --> 1113 The new <a href="/pkg/math/rand/#Rand.Uint64"><code>Rand.Uint64</code></a> 1114 method returns <code>uint64</code> values. The 1115 new <a href="/pkg/math/rand/#Source64"><code>Source64</code></a> 1116 interface describes sources capable of generating such values 1117 directly; otherwise the <code>Rand.Uint64</code> method 1118 constructs a <code>uint64</code> from two calls 1119 to <a href="/pkg/math/rand/#Source"><code>Source</code></a>'s 1120 <code>Int63</code> method. 1121 </p> 1122 1123 </dd> 1124 </dl> 1125 1126 <dl id="mime"><dt><a href="/pkg/mime/">mime</a></dt> 1127 <dd> 1128 <p> <!-- CL 32175 --> 1129 <a href="/pkg/mime/#ParseMediaType"><code>ParseMediaType</code></a> 1130 now preserves unnecessary backslash escapes as literals, 1131 in order to support MSIE. 1132 When MSIE sends a full file path (in “intranet mode”), it does not 1133 escape backslashes: “<code>C:\dev\go\foo.txt</code>”, not 1134 “<code>C:\\dev\\go\\foo.txt</code>”. 1135 If we see an unnecessary backslash escape, we now assume it is from MSIE 1136 and intended as a literal backslash. 1137 No known MIME generators emit unnecessary backslash escapes 1138 for simple token characters like numbers and letters. 1139 </p> 1140 </dd> 1141 </dl> 1142 1143 <dl id="mime_quotedprintable"><dt><a href="/pkg/mime/quotedprintable/">mime/quotedprintable</a></dt> 1144 <dd> 1145 1146 <p> 1147 The 1148 <a href="/pkg/mime/quotedprintable/#Reader"><code>Reader</code></a>'s 1149 parsing has been relaxed in two ways to accept 1150 more input seen in the wild. 1151 1152 <!-- CL 32174 --> 1153 First, it accepts an equals sign (<code>=</code>) not followed 1154 by two hex digits as a literal equal sign. 1155 1156 <!-- CL 27530 --> 1157 Second, it silently ignores a trailing equals sign at the end of 1158 an encoded input. 1159 </p> 1160 1161 </dd> 1162 </dl> 1163 1164 <dl id="net"><dt><a href="/pkg/net/">net</a></dt> 1165 <dd> 1166 1167 <p><!-- CL 30164, CL 33473 --> 1168 The <a href="/pkg/net/#Conn"><code>Conn</code></a> documentation 1169 has been updated to clarify expectations of an interface 1170 implementation. Updates in the <code>net/http</code> packages 1171 depend on implementations obeying the documentation. 1172 </p> 1173 <p><i>Updating:</i> implementations of the <code>Conn</code> interface should verify 1174 they implement the documented semantics. The 1175 <a href="https://godoc.org/golang.org/x/net/nettest">golang.org/x/net/nettest</a> 1176 package will exercise a <code>Conn</code> and validate it behaves properly. 1177 </p> 1178 1179 <p><!-- CL 32099 --> 1180 The new method 1181 <a href="/pkg/net/#UnixListener.SetUnlinkOnClose"><code>UnixListener.SetUnlinkOnClose</code></a> 1182 sets whether the underlying socket file should be removed from the file system when 1183 the listener is closed. 1184 </p> 1185 1186 <p><!-- CL 29951 --> 1187 The new <a href="/pkg/net/#Buffers"><code>Buffers</code></a> type permits 1188 writing to the network more efficiently from multiple discontiguous buffers 1189 in memory. On certain machines, for certain types of connections, 1190 this is optimized into an OS-specific batch write operation (such as <code>writev</code>). 1191 </p> 1192 1193 <p><!-- CL 29440 --> 1194 The new <a href="/pkg/net/#Resolver"><code>Resolver</code></a> looks up names and numbers 1195 and supports <a href="/pkg/context/#Context"><code>context.Context</code></a>. 1196 The <a href="/pkg/net/#Dialer"><code>Dialer</code></a> now has an optional 1197 <a href="/pkg/net/#Dialer.Resolver"><code>Resolver</code> field</a>. 1198 </p> 1199 1200 <p><!-- CL 29892 --> 1201 <a href="/pkg/net/#Interfaces"><code>Interfaces</code></a> is now supported on Solaris. 1202 </p> 1203 1204 <p><!-- CL 29233, CL 24901 --> 1205 The Go DNS resolver now supports <code>resolv.conf</code>'s “<code>rotate</code>” 1206 and “<code>option</code> <code>ndots:0</code>” options. The “<code>ndots</code>” option is 1207 now respected in the same way as <code>libresolve</code>. 1208 </p> 1209 1210 </dd> 1211 </dl> 1212 1213 <dl id="net_http"><dt><a href="/pkg/net/http/">net/http</a></dt> 1214 <dd> 1215 1216 <p>Server changes:</p> 1217 <ul> 1218 <li>The server now supports graceful shutdown support, <a href="#http_shutdown">mentioned above</a>.</li> 1219 1220 <li> <!-- CL 32024 --> 1221 The <a href="/pkg/net/http/#Server"><code>Server</code></a> 1222 adds configuration options 1223 <code>ReadHeaderTimeout</code> and <code>IdleTimeout</code> 1224 and documents <code>WriteTimeout</code>. 1225 </li> 1226 1227 <li> <!-- CL 32014 --> 1228 <a href="/pkg/net/http/#FileServer"><code>FileServer</code></a> 1229 and 1230 <a href="/pkg/net/http/#ServeContent"><code>ServeContent</code></a> 1231 now support HTTP <code>If-Match</code> conditional requests, 1232 in addition to the previous <code>If-None-Match</code> 1233 support for ETags properly formatted according to RFC 7232, section 2.3. 1234 </li> 1235 </ul> 1236 1237 <p> 1238 There are several additions to what a server's <code>Handler</code> can do: 1239 </p> 1240 1241 <ul> 1242 <li><!-- CL 31173 --> 1243 The <a href="/pkg/context/#Context"><code>Context</code></a> 1244 returned 1245 by <a href="/pkg/net/http/#Request.Context"><code>Request.Context</code></a> 1246 is canceled if the underlying <code>net.Conn</code> 1247 closes. For instance, if the user closes their browser in the 1248 middle of a slow request, the <code>Handler</code> can now 1249 detect that the user is gone. This complements the 1250 existing <a href="/pkg/net/http/#CloseNotifier"><code>CloseNotifier</code></a> 1251 support. This functionality requires that the underlying 1252 <a href="/pkg/net/#Conn"><code>net.Conn</code></a> implements 1253 <a href="#net">recently clarified interface documentation</a>. 1254 </li> 1255 1256 <li><!-- CL 32479 --> 1257 To serve trailers produced after the header has already been written, 1258 see the new 1259 <a href="/pkg/net/http/#TrailerPrefix"><code>TrailerPrefix</code></a> 1260 mechanism. 1261 </li> 1262 1263 <li><!-- CL 33099 --> 1264 A <code>Handler</code> can now abort a response by panicking 1265 with the error 1266 <a href="/pkg/net/http/#ErrAbortHandler"><code>ErrAbortHandler</code></a>. 1267 </li> 1268 1269 <li><!-- CL 30812 --> 1270 A <code>Write</code> of zero bytes to a 1271 <a href="/pkg/net/http/#ResponseWriter"><code>ResponseWriter</code></a> 1272 is now defined as a 1273 way to test whether a <code>ResponseWriter</code> has been hijacked: 1274 if so, the <code>Write</code> returns 1275 <a href="/pkg/net/http/#ErrHijacked"><code>ErrHijacked</code></a> 1276 without printing an error 1277 to the server's error log. 1278 </li> 1279 1280 </ul> 1281 1282 <p>Client & Transport changes:</p> 1283 <ul> 1284 <li><!-- CL 28930, CL 31435 --> 1285 The <a href="/pkg/net/http/#Client"><code>Client</code></a> 1286 now copies most request headers on redirect. See 1287 <a href="/pkg/net/http/#Client">the documentation</a> 1288 on the <code>Client</code> type for details. 1289 </li> 1290 1291 <li><!-- CL 29072 --> 1292 The <a href="/pkg/net/http/#Transport"><code>Transport</code></a> 1293 now supports international domain names. Consequently, so do 1294 <a href="/pkg/net/http/#Get">Get</a> and other helpers. 1295 </li> 1296 1297 <li><!-- CL 31733, CL 29852 --> 1298 The <code>Client</code> now supports 301, 307, and 308 redirects. 1299 1300 For example, <code>Client.Post</code> now follows 301 1301 redirects, converting them to <code>GET</code> requests 1302 without bodies, like it did for 302 and 303 redirect responses 1303 previously. 1304 1305 The <code>Client</code> now also follows 307 and 308 1306 redirects, preserving the original request method and body, if 1307 any. If the redirect requires resending the request body, the 1308 request must have the new 1309 <a href="/pkg/net/http/#Request"><code>Request.GetBody</code></a> 1310 field defined. 1311 <a href="pkg/net/http/#NewRequest"><code>NewRequest</code></a> 1312 sets <code>Request.GetBody</code> automatically for common 1313 body types. 1314 </li> 1315 1316 <li><!-- CL 32482 --> 1317 The <code>Transport</code> now rejects requests for URLs with 1318 ports containing non-digit characters. 1319 </li> 1320 1321 <li><!-- CL 27117 --> 1322 The <code>Transport</code> will now retry non-idempotent 1323 requests if no bytes were written before a network failure 1324 and the request has no body. 1325 </li> 1326 1327 <li><!-- CL 32481 --> 1328 The 1329 new <a href="/pkg/net/http/#Transport"><code>Transport.ProxyConnectHeader</code></a> 1330 allows configuration of header values to send to a proxy 1331 during a <code>CONNECT</code> request. 1332 </li> 1333 1334 <li> <!-- CL 28077 --> 1335 The <a href="/pkg/net/http/#DefaultTransport"><code>DefaultTransport.Dialer</code></a> 1336 now enables <code>DualStack</code> ("<a href="https://tools.ietf.org/html/rfc6555">Happy Eyeballs</a>") support, 1337 allowing the use of IPv4 as a backup if it looks like IPv6 might be 1338 failing. 1339 </li> 1340 1341 <li> <!-- CL 31726 --> 1342 The <a href="/pkg/net/http/#Transport"><code>Transport</code></a> 1343 no longer reads a byte of a non-nil 1344 <a href="/pkg/net/http/#Request.Body"><code>Request.Body</code></a> 1345 when the 1346 <a href="/pkg/net/http/#Request.ContentLength"><code>Request.ContentLength</code></a> 1347 is zero to determine whether the <code>ContentLength</code> 1348 is actually zero or just undefined. 1349 To explicitly signal that a body has zero length, 1350 either set it to <code>nil</code>, or set it to the new value 1351 <a href="/pkg/net/http/#NoBody"><code>NoBody</code></a>. 1352 The new <code>NoBody</code> value is intended for use by <code>Request</code> 1353 constructor functions; it is used by 1354 <a href="/pkg/net/http/#NewRequest"><code>NewRequest</code></a>. 1355 </li> 1356 </ul> 1357 1358 </dd> 1359 </dl> 1360 1361 <dl id="net_http_httptrace"><dt><a href="/pkg/net/http/httptrace/">net/http/httptrace</a></dt> 1362 <dd> 1363 <p> <!-- CL 30359 --> 1364 There is now support for tracing a client request's TLS handshakes with 1365 the new 1366 <a href="/pkg/net/http/httptrace/#ClientTrace.TLSHandshakeStart"><code>ClientTrace.TLSHandshakeStart</code></a> 1367 and 1368 <a href="/pkg/net/http/httptrace/#ClientTrace.TLSHandshakeDone"><code>ClientTrace.TLSHandshakeDone</code></a>. 1369 </p> 1370 </dd> 1371 </dl> 1372 1373 <dl id="net_http_httputil"><dt><a href="/pkg/net/http/httputil/">net/http/httputil</a></dt> 1374 <dd> 1375 <p> <!-- CL 32356 --> 1376 The <a href="/pkg/net/http/httputil/#ReverseProxy"><code>ReverseProxy</code></a> 1377 has a new optional hook, 1378 <a href="/pkg/net/http/httputil/#ReverseProxy.ModifyResponse"><code>ModifyResponse</code></a>, 1379 for modifying the response from the back end before proxying it to the client. 1380 </p> 1381 1382 </dd> 1383 </dl> 1384 1385 <dl id="net_mail"><dt><a href="/pkg/net/mail/">net/mail</a></dt> 1386 <dd> 1387 1388 <p> <!-- CL 32176 --> 1389 Empty quoted strings are once again allowed in the name part of 1390 an address. That is, Go 1.4 and earlier accepted 1391 <code>""</code> <code><gopher@example.com></code>, 1392 but Go 1.5 introduced a bug that rejected this address. 1393 The address is recognized again. 1394 </p> 1395 1396 <p> <!-- CL 31581 --> 1397 The 1398 <a href="/pkg/net/mail/#Header.Date"><code>Header.Date</code></a> 1399 method has always provided a way to parse 1400 the <code>Date:</code> header. 1401 A new function 1402 <a href="/pkg/net/mail/#ParseDate"><code>ParseDate</code></a> 1403 allows parsing dates found in other 1404 header lines, such as the <code>Resent-Date:</code> header. 1405 </p> 1406 1407 </dd> 1408 </dl> 1409 1410 <dl id="net_smtp"><dt><a href="/pkg/net/smtp/">net/smtp</a></dt> 1411 <dd> 1412 1413 <p> <!-- CL 33143 --> 1414 If an implementation of the 1415 <a href="/pkg/net/smtp/#Auth"><code>Auth.Start</code></a> 1416 method returns an empty <code>toServer</code> value, 1417 the package no longer sends 1418 trailing whitespace in the SMTP <code>AUTH</code> command, 1419 which some servers rejected. 1420 </p> 1421 1422 </dd> 1423 </dl> 1424 1425 <dl id="net_url"><dt><a href="/pkg/net/url/">net/url</a></dt> 1426 <dd> 1427 1428 <p> <!-- CL 31322 --> 1429 The new functions 1430 <a href="/pkg/net/url/#PathEscape"><code>PathEscape</code></a> 1431 and 1432 <a href="/pkg/net/url/#PathUnescape"><code>PathUnescape</code></a> 1433 are similar to the query escaping and unescaping functions but 1434 for path elements. 1435 </p> 1436 1437 <p> <!-- CL 28933 --> 1438 The new methods 1439 <a href="/pkg/net/url/#URL.Hostname"><code>URL.Hostname</code></a> 1440 and 1441 <a href="/pkg/net/url/#URL.Port"><code>URL.Port</code></a> 1442 return the hostname and port fields of a URL, 1443 correctly handling the case where the port may not be present. 1444 </p> 1445 1446 <p> <!-- CL 28343 --> 1447 The existing method 1448 <a href="/pkg/net/url/#URL.ResolveReference"><code>URL.ResolveReference</code></a> 1449 now properly handles paths with escaped bytes without losing 1450 the escaping. 1451 </p> 1452 1453 <p> <!-- CL 31467 --> 1454 The <code>URL</code> type now implements 1455 <a href="/pkg/encoding/#BinaryMarshaler"><code>encoding.BinaryMarshaler</code></a> and 1456 <a href="/pkg/encoding/#BinaryUnmarshaler"><code>encoding.BinaryUnmarshaler</code></a>, 1457 making it possible to process URLs in <a href="/pkg/encoding/gob/">gob data</a>. 1458 </p> 1459 1460 <p> <!-- CL 29610, CL 31582 --> 1461 Following RFC 3986, 1462 <a href="/pkg/net/url/#Parse"><code>Parse</code></a> 1463 now rejects URLs like <code>this_that:other/thing</code> instead of 1464 interpreting them as relative paths (<code>this_that</code> is not a valid scheme). 1465 To force interpretation as a relative path, 1466 such URLs should be prefixed with “<code>./</code>”. 1467 The <code>URL.String</code> method now inserts this prefix as needed. 1468 </p> 1469 1470 </dd> 1471 </dl> 1472 1473 <dl id="os"><dt><a href="/pkg/os/">os</a></dt> 1474 <dd> 1475 <p> <!-- CL 16551 --> 1476 The new function 1477 <a href="/pkg/os/#Executable"><code>Executable</code></a> returns 1478 the path name of the running executable. 1479 </p> 1480 1481 <p> <!-- CL 30614 --> 1482 An attempt to call a method on 1483 an <a href="/pkg/os/#File"><code>os.File</code></a> that has 1484 already been closed will now return the new error 1485 value <a href="/pkg/os/#ErrClosed"><code>os.ErrClosed</code></a>. 1486 Previously it returned a system-specific error such 1487 as <code>syscall.EBADF</code>. 1488 </p> 1489 1490 <p> <!-- CL 31358 --> 1491 On Unix systems, <a href="/pkg/os/#Rename"><code>os.Rename</code></a> 1492 will now return an error when used to rename a directory to an 1493 existing empty directory. 1494 Previously it would fail when renaming to a non-empty directory 1495 but succeed when renaming to an empty directory. 1496 This makes the behavior on Unix correspond to that of other systems. 1497 </p> 1498 1499 <p> <!-- CL 32451 --> 1500 On Windows, long absolute paths are now transparently converted to 1501 extended-length paths (paths that start with “<code>\\?\</code>”). 1502 This permits the package to work with files whose path names are 1503 longer than 260 characters. 1504 </p> 1505 1506 <p> <!-- CL 29753 --> 1507 On Windows, <a href="/pkg/os/#IsExist"><code>os.IsExist</code></a> 1508 will now return <code>true</code> for the system 1509 error <code>ERROR_DIR_NOT_EMPTY</code>. 1510 This roughly corresponds to the existing handling of the Unix 1511 error <code>ENOTEMPTY</code>. 1512 </p> 1513 1514 <p> <!-- CL 32152 --> 1515 On Plan 9, files that are not served by <code>#M</code> will now 1516 have <a href="/pkg/os/#ModeDevice"><code>ModeDevice</code></a> set in 1517 the value returned 1518 by <a href="/pkg/os/#FileInfo"><code>FileInfo.Mode</code></a>. 1519 </p> 1520 </dd> 1521 </dl> 1522 1523 <dl id="path_filepath"><dt><a href="/pkg/path/filepath/">path/filepath</a></dt> 1524 <dd> 1525 <p> 1526 A number of bugs and corner cases on Windows were fixed: 1527 <a href="/pkg/path/filepath/#Abs"><code>Abs</code></a> now calls <code>Clean</code> as documented, 1528 <a href="/pkg/path/filepath/#Glob"><code>Glob</code></a> now matches 1529 “<code>\\?\c:\*</code>”, 1530 <a href="/pkg/path/filepath/#EvalSymlinks"><code>EvalSymlinks</code></a> now 1531 correctly handles “<code>C:.</code>”, and 1532 <a href="/pkg/path/filepath/#Clean"><code>Clean</code></a> now properly 1533 handles a leading “<code>..</code>” in the path. 1534 </p> 1535 </dd> 1536 </dl> 1537 1538 <dl id="reflect"><dt><a href="/pkg/reflect/">reflect</a></dt> 1539 <dd> 1540 <p> <!-- CL 30088 --> 1541 The new function 1542 <a href="/pkg/reflect/#Swapper"><code>Swapper</code></a> was 1543 added to support <a href="#sortslice"><code>sort.Slice</code></a>. 1544 </p> 1545 </dd> 1546 </dl> 1547 1548 <dl id="strconv"><dt><a href="/pkg/strconv/">strconv</a></dt> 1549 <dd> 1550 <p> <!-- CL 31210 --> 1551 The <a href="/pkg/strconv/#Unquote"><code>Unquote</code></a> 1552 function now strips carriage returns (<code>\r</code>) in 1553 backquoted raw strings, following the 1554 <a href="/ref/spec#String_literals">Go language semantics</a>. 1555 </p> 1556 </dd> 1557 </dl> 1558 1559 <dl id="syscall"><dt><a href="/pkg/syscall/">syscall</a></dt> 1560 <dd> 1561 <p> <!-- CL 25050, CL 25022 --> 1562 The <a href="/pkg/syscall/#Getpagesize"><code>Getpagesize</code></a> 1563 now returns the system's size, rather than a constant value. 1564 Previously it always returned 4KB. 1565 </p> 1566 1567 <p> <!-- CL 31446 --> 1568 The signature 1569 of <a href="/pkg/syscall/#Utimes"><code>Utimes</code></a> has 1570 changed on Solaris to match all the other Unix systems' 1571 signature. Portable code should continue to use 1572 <a href="/pkg/os/#Chtimes"><code>os.Chtimes</code></a> instead. 1573 </p> 1574 1575 <p> <!-- CL 32319 --> 1576 The <code>X__cmsg_data</code> field has been removed from 1577 <a href="/pkg/syscall/#Cmsghdr"><code>Cmsghdr</code></a>. 1578 </p> 1579 </dd> 1580 </dl> 1581 1582 <dl id="text_template"><dt><a href="/pkg/text/template/">text/template</a></dt> 1583 <dd> 1584 <p> <!-- CL 31462 --> 1585 <a href="/pkg/text/template/#Template.Execute"><code>Template.Execute</code></a> 1586 can now take a 1587 <a href="/pkg/reflect/#Value"><code>reflect.Value</code></a> as its data 1588 argument, and 1589 <a href="/pkg/text/template/#FuncMap"><code>FuncMap</code></a> 1590 functions can also accept and return <code>reflect.Value</code>. 1591 </p> 1592 1593 </dd> 1594 </dl> 1595 1596 <dl id="time"><dt><a href="/pkg/time/">time</a></dt> 1597 <dd> 1598 1599 <p> <!-- CL 20118 --> The new function 1600 <a href="/pkg/time/#Until"><code>Until</code></a> complements 1601 the analogous <code>Since</code> function. 1602 </p> 1603 1604 <p> <!-- CL 29338 --> 1605 <a href="/pkg/time/#ParseDuration"><code>ParseDuration</code></a> 1606 now accepts long fractional parts. 1607 </p> 1608 1609 <p> <!-- CL 33429 --> 1610 <a href="/pkg/time/#Parse"><code>Parse</code></a> 1611 now rejects dates before the start of a month, such as June 0; 1612 it already rejected dates beyond the end of the month, such as 1613 June 31 and July 32. 1614 </p> 1615 1616 <p> <!-- CL 33029 --> <!-- CL 34816 --> 1617 The <code>tzdata</code> database has been updated to version 1618 2016j for systems that don't already have a local time zone 1619 database. 1620 </p> 1621 1622 <p> 1623 </dd> 1624 </dl> 1625 1626 <dl id="testing"><dt><a href="/pkg/testing/">testing</a></dt> 1627 <dd> 1628 <p><!-- CL 29970 --> 1629 The new method 1630 <a href="/pkg/testing/#T.Name"><code>T.Name</code></a> 1631 (and <code>B.Name</code>) returns the name of the current 1632 test or benchmark. 1633 </p> 1634 1635 <p><!-- CL 32483 --> 1636 The new function 1637 <a href="/pkg/testing/#CoverMode"><code>CoverMode</code></a> 1638 reports the test coverage mode. 1639 </p> 1640 1641 <p><!-- CL 32615 --> 1642 Tests and benchmarks are now marked as failed if the race 1643 detector is enabled and a data race occurs during execution. 1644 Previously, individual test cases would appear to pass, 1645 and only the overall execution of the test binary would fail. 1646 </p> 1647 1648 <p><!-- CL 32455 --> 1649 The signature of the 1650 <a href="/pkg/testing/#MainStart"><code>MainStart</code></a> 1651 function has changed, as allowed by the documentation. It is an 1652 internal detail and not part of the Go 1 compatibility promise. 1653 If you're not calling <code>MainStart</code> directly but see 1654 errors, that likely means you set the 1655 normally-empty <code>GOROOT</code> environment variable and it 1656 doesn't match the version of your <code>go</code> command's binary. 1657 </p> 1658 1659 </dd> 1660 </dl> 1661 1662 <dl id="unicode"><dt><a href="/pkg/unicode/">unicode</a></dt> 1663 <dd> 1664 <p><!-- CL 30935 --> 1665 <a href="/pkg/unicode/#SimpleFold"><code>SimpleFold</code></a> 1666 now returns its argument unchanged if the provided input was an invalid rune. 1667 Previously, the implementation failed with an index bounds check panic. 1668 </p> 1669 </dd> 1670 </dl>