github.com/riscv/riscv-go@v0.0.0-20200123204226-124ebd6fcc8e/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, CL 35290 --> 803 AES-128-CBC cipher suites with SHA-256 are also 804 now supported, but disabled by default. 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 <a href="/pkg/database/sql#TxOptions.Isolation"><code>TxOptions.Isolation</code></a> and passing 863 it to <a href="/pkg/database/sql#DB.BeginTx"><code>DB.BeginTx</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 by setting <a href="/pkg/database/sql/#TxOptions.ReadOnly"><code>TxOptions.ReadOnly</code></a> 867 to true. 868 </p> 869 <p> 870 Queries now expose the SQL column type information for drivers that support it. 871 Rows can return <a href="/pkg/database/sql#Rows.ColumnTypes"><code>ColumnTypes</code></a> 872 which can include SQL type information, column type lengths, and the Go type. 873 </p> 874 <p> 875 A <a href="/pkg/database/sql/#Rows"><code>Rows</code></a> 876 can now represent multiple result sets. After 877 <a href="/pkg/database/sql/#Rows.Next"><code>Rows.Next</code></a> returns false, 878 <a href="/pkg/database/sql/#Rows.NextResultSet"><code>Rows.NextResultSet</code></a> 879 may be called to advance to the next result set. The existing <code>Rows</code> 880 should continue to be used after it advances to the next result set. 881 </p> 882 <p> 883 <a href="/pkg/database/sql/#NamedArg"><code>NamedArg</code></a> may be used 884 as query arguments. The new function <a href="/pkg/database/sql/#Named"><code>Named</code></a> 885 helps create a <a href="/pkg/database/sql/#NamedArg"><code>NamedArg</code></a> 886 more succinctly. 887 <p> 888 If a driver supports the new 889 <a href="/pkg/database/sql/driver/#Pinger"><code>Pinger</code></a> 890 interface, the 891 <a href="/pkg/database/sql/#DB.Ping"><code>DB.Ping</code></a> 892 and 893 <a href="/pkg/database/sql/#DB.PingContext"><code>DB.PingContext</code></a> 894 methods will use that interface to check whether a 895 database connection is still valid. 896 </p> 897 <p> 898 The new <code>Context</code> query methods work for all drivers, but 899 <code>Context</code> cancelation is not responsive unless the driver has been 900 updated to use them. The other features require driver support in 901 <a href="/pkg/database/sql/driver"><code>database/sql/driver</code></a>. 902 Driver authors should review the new interfaces. Users of existing 903 driver should review the driver documentation to see what 904 it supports and any system specific documentation on each feature. 905 </p> 906 </dd> 907 </dl> 908 909 <dl id="debug_pe"><dt><a href="/pkg/debug/pe/">debug/pe</a></dt> 910 <dd> 911 <p> <!-- CL 22720, CL 27212, CL 22181, CL 22332, CL 22336, Issue 15345 --> 912 The package has been extended and is now used by 913 <a href="/cmd/link/">the Go linker</a> to read <code>gcc</code>-generated object files. 914 The new 915 <a href="/pkg/debug/pe/#File.StringTable"><code>File.StringTable</code></a> 916 and 917 <a href="/pkg/debug/pe/#Section.Relocs"><code>Section.Relocs</code></a> 918 fields provide access to the COFF string table and COFF relocations. 919 The new 920 <a href="/pkg/debug/pe/#File.COFFSymbols"><code>File.COFFSymbols</code></a> 921 allows low-level access to the COFF symbol table. 922 </p> 923 </dd> 924 </dl> 925 926 <dl id="encoding_base64"><dt><a href="/pkg/encoding/base64/">encoding/base64</a></dt> 927 <dd> 928 <p> <!-- CL 24964 --> 929 The new 930 <a href="/pkg/encoding/base64/#Encoding.Strict"><code>Encoding.Strict</code></a> 931 method returns an <code>Encoding</code> that causes the decoder 932 to return an error when the trailing padding bits are not zero. 933 </p> 934 </dd> 935 </dl> 936 937 <dl id="encoding_binary"><dt><a href="/pkg/encoding/binary/">encoding/binary</a></dt> 938 <dd> 939 <p> <!-- CL 28514 --> 940 <a href="/pkg/encoding/binary/#Read"><code>Read</code></a> 941 and 942 <a href="/pkg/encoding/binary/#Write"><code>Write</code></a> 943 now support booleans. 944 </p> 945 </dd> 946 </dl> 947 948 <dl id="encoding_json"><dt><a href="/pkg/encoding/json/">encoding/json</a></dt> 949 <dd> 950 951 <p> <!-- CL 18692 --> 952 <a href="/pkg/encoding/json/#UnmarshalTypeError"><code>UnmarshalTypeError</code></a> 953 now includes the struct and field name. 954 </p> 955 956 <p> <!-- CL 31932 --> 957 A nil <a href="/pkg/encoding/json/#Marshaler"><code>Marshaler</code></a> 958 now marshals as a JSON <code>null</code> value. 959 </p> 960 961 <p> <!-- CL 21811 --> 962 A <a href="/pkg/encoding/json/#RawMessage"><code>RawMessage</code></a> value now 963 marshals the same as its pointer type. 964 </p> 965 966 <p> <!-- CL 30371 --> 967 <a href="/pkg/encoding/json/#Marshal"><code>Marshal</code></a> 968 encodes floating-point numbers using the same format as in ES6, 969 preferring decimal (not exponential) notation for a wider range of values. 970 In particular, all floating-point integers up to 2<sup>64</sup> format the 971 same as the equivalent <code>int64</code> representation. 972 </p> 973 974 <p> <!-- CL 30944 --> 975 In previous versions of Go, unmarshaling a JSON <code>null</code> into an 976 <a href="/pkg/encoding/json/#Unmarshaler"><code>Unmarshaler</code></a> 977 was considered a no-op; now the <code>Unmarshaler</code>'s 978 <code>UnmarshalJSON</code> method is called with the JSON literal 979 <code>null</code> and can define the semantics of that case. 980 </p> 981 982 </dd> 983 </dl> 984 985 <dl id="encoding_pem"><dt><a href="/pkg/encoding/pem/">encoding/pem</a></dt> 986 <dd> 987 <p> <!-- CL 27391 --> 988 <a href="/pkg/encoding/pem/#Decode"><code>Decode</code></a> 989 is now strict about the format of the ending line. 990 </p> 991 </dd> 992 </dl> 993 994 <dl id="encoding_xml"><dt><a href="/pkg/encoding/xml/">encoding/xml</a></dt> 995 <dd> 996 <p> <!-- CL 30946 --> 997 <a href="/pkg/encoding/xml/#Unmarshal"><code>Unmarshal</code></a> 998 now has wildcard support for collecting all attributes using 999 the new <code>",any,attr"</code> struct tag. 1000 </p> 1001 </dd> 1002 </dl> 1003 1004 <dl id="expvar"><dt><a href="/pkg/expvar/">expvar</a></dt> 1005 <dd> 1006 <p> <!-- CL 30917 --> 1007 The new methods 1008 <a href="/pkg/expvar/#Int.Value"><code>Int.Value</code></a>, 1009 <a href="/pkg/expvar/#String.Value"><code>String.Value</code></a>, 1010 <a href="/pkg/expvar/#Float.Value"><code>Float.Value</code></a>, and 1011 <a href="/pkg/expvar/#Func.Value"><code>Func.Value</code></a> 1012 report the current value of an exported variable. 1013 </p> 1014 1015 <p> <!-- CL 24722 --> 1016 The new 1017 function <a href="/pkg/expvar/#Handler"><code>Handler</code></a> 1018 returns the package's HTTP handler, to enable installing it in 1019 non-standard locations. 1020 </p> 1021 </dd> 1022 </dl> 1023 1024 <dl id="fmt"><dt><a href="/pkg/fmt/">fmt</a></dt> 1025 <dd> 1026 <p><!-- CL 30611 --> 1027 <a href="/pkg/fmt/#Scanf"><code>Scanf</code></a>, 1028 <a href="/pkg/fmt/#Fscanf"><code>Fscanf</code></a>, and 1029 <a href="/pkg/fmt/#Sscanf"><code>Sscanf</code></a> now 1030 handle spaces differently and more consistently than 1031 previous releases. See the 1032 <a href="/pkg/fmt/#hdr-Scanning">scanning documentation</a> 1033 for details. 1034 </p> 1035 </dd> 1036 </dl> 1037 1038 <dl id="go_doc"><dt><a href="/pkg/go/doc/">go/doc</a></dt> 1039 <dd> 1040 <p><!-- CL 29870 --> 1041 The new <a href="/pkg/go/doc/#IsPredeclared"><code>IsPredeclared</code></a> 1042 function reports whether a string is a predeclared identifier. 1043 </p> 1044 </dd> 1045 </dl> 1046 1047 <dl id="go_types"><dt><a href="/pkg/go/types/">go/types</a></dt> 1048 <dd> 1049 <p><!-- CL 30715 --> 1050 The new function 1051 <a href="/pkg/go/types/#Default"><code>Default</code></a> 1052 returns the default "typed" type for an "untyped" type. 1053 </p> 1054 1055 <p><!-- CL 31939 --> 1056 The alignment of <code>complex64</code> now matches 1057 the <a href="/cmd/compile/">Go compiler</a>. 1058 </p> 1059 </dd> 1060 </dl> 1061 1062 <dl id="html_template"><dt><a href="/pkg/html/template/">html/template</a></dt> 1063 <dd> 1064 <p><!-- CL 14336 --> 1065 The package now validates 1066 the <code>"type"</code> attribute on 1067 a <code><script></code> tag. 1068 </p> 1069 </dd> 1070 </dl> 1071 1072 <dl id="image_png"><dt><a href="/pkg/image/png/">image/png</a></dt> 1073 <dd> 1074 <p> <!-- CL 32143, CL 32140 --> 1075 <a href="/pkg/image/png/#Decode"><code>Decode</code></a> 1076 (and <code>DecodeConfig</code>) 1077 now supports True Color and grayscale transparency. 1078 </p> 1079 <p> <!-- CL 29872 --> 1080 <a href="/pkg/image/png/#Encoder"><code>Encoder</code></a> 1081 is now faster and creates smaller output 1082 when encoding paletted images. 1083 </p> 1084 </dd> 1085 </dl> 1086 1087 <dl id="math_big"><dt><a href="/pkg/math/big/">math/big</a></dt> 1088 <dd> 1089 <p><!-- CL 30706 --> 1090 The new method 1091 <a href="/pkg/math/big/#Int.Sqrt"><code>Int.Sqrt</code></a> 1092 calculates ⌊√x⌋. 1093 </p> 1094 1095 <p> 1096 The new method 1097 <a href="/pkg/math/big/#Float.Scan"><code>Float.Scan</code></a> 1098 is a support routine for 1099 <a href="/pkg/fmt/#Scanner"><code>fmt.Scanner</code></a>. 1100 </p> 1101 1102 <p> 1103 <a href="/pkg/math/big/#Int.ModInverse"><code>Int.ModInverse</code></a> 1104 now supports negative numbers. 1105 </p> 1106 1107 </dd> 1108 </dl> 1109 1110 <dl id="math_rand"><dt><a href="/pkg/math/rand/">math/rand</a></dt> 1111 <dd> 1112 1113 <p><!-- CL 27253, CL 33456 --> 1114 The new <a href="/pkg/math/rand/#Rand.Uint64"><code>Rand.Uint64</code></a> 1115 method returns <code>uint64</code> values. The 1116 new <a href="/pkg/math/rand/#Source64"><code>Source64</code></a> 1117 interface describes sources capable of generating such values 1118 directly; otherwise the <code>Rand.Uint64</code> method 1119 constructs a <code>uint64</code> from two calls 1120 to <a href="/pkg/math/rand/#Source"><code>Source</code></a>'s 1121 <code>Int63</code> method. 1122 </p> 1123 1124 </dd> 1125 </dl> 1126 1127 <dl id="mime"><dt><a href="/pkg/mime/">mime</a></dt> 1128 <dd> 1129 <p> <!-- CL 32175 --> 1130 <a href="/pkg/mime/#ParseMediaType"><code>ParseMediaType</code></a> 1131 now preserves unnecessary backslash escapes as literals, 1132 in order to support MSIE. 1133 When MSIE sends a full file path (in “intranet mode”), it does not 1134 escape backslashes: “<code>C:\dev\go\foo.txt</code>”, not 1135 “<code>C:\\dev\\go\\foo.txt</code>”. 1136 If we see an unnecessary backslash escape, we now assume it is from MSIE 1137 and intended as a literal backslash. 1138 No known MIME generators emit unnecessary backslash escapes 1139 for simple token characters like numbers and letters. 1140 </p> 1141 </dd> 1142 </dl> 1143 1144 <dl id="mime_quotedprintable"><dt><a href="/pkg/mime/quotedprintable/">mime/quotedprintable</a></dt> 1145 <dd> 1146 1147 <p> 1148 The 1149 <a href="/pkg/mime/quotedprintable/#Reader"><code>Reader</code></a>'s 1150 parsing has been relaxed in two ways to accept 1151 more input seen in the wild. 1152 1153 <!-- CL 32174 --> 1154 First, it accepts an equals sign (<code>=</code>) not followed 1155 by two hex digits as a literal equal sign. 1156 1157 <!-- CL 27530 --> 1158 Second, it silently ignores a trailing equals sign at the end of 1159 an encoded input. 1160 </p> 1161 1162 </dd> 1163 </dl> 1164 1165 <dl id="net"><dt><a href="/pkg/net/">net</a></dt> 1166 <dd> 1167 1168 <p><!-- CL 30164, CL 33473 --> 1169 The <a href="/pkg/net/#Conn"><code>Conn</code></a> documentation 1170 has been updated to clarify expectations of an interface 1171 implementation. Updates in the <code>net/http</code> packages 1172 depend on implementations obeying the documentation. 1173 </p> 1174 <p><i>Updating:</i> implementations of the <code>Conn</code> interface should verify 1175 they implement the documented semantics. The 1176 <a href="https://godoc.org/golang.org/x/net/nettest">golang.org/x/net/nettest</a> 1177 package will exercise a <code>Conn</code> and validate it behaves properly. 1178 </p> 1179 1180 <p><!-- CL 32099 --> 1181 The new method 1182 <a href="/pkg/net/#UnixListener.SetUnlinkOnClose"><code>UnixListener.SetUnlinkOnClose</code></a> 1183 sets whether the underlying socket file should be removed from the file system when 1184 the listener is closed. 1185 </p> 1186 1187 <p><!-- CL 29951 --> 1188 The new <a href="/pkg/net/#Buffers"><code>Buffers</code></a> type permits 1189 writing to the network more efficiently from multiple discontiguous buffers 1190 in memory. On certain machines, for certain types of connections, 1191 this is optimized into an OS-specific batch write operation (such as <code>writev</code>). 1192 </p> 1193 1194 <p><!-- CL 29440 --> 1195 The new <a href="/pkg/net/#Resolver"><code>Resolver</code></a> looks up names and numbers 1196 and supports <a href="/pkg/context/#Context"><code>context.Context</code></a>. 1197 The <a href="/pkg/net/#Dialer"><code>Dialer</code></a> now has an optional 1198 <a href="/pkg/net/#Dialer.Resolver"><code>Resolver</code> field</a>. 1199 </p> 1200 1201 <p><!-- CL 29892 --> 1202 <a href="/pkg/net/#Interfaces"><code>Interfaces</code></a> is now supported on Solaris. 1203 </p> 1204 1205 <p><!-- CL 29233, CL 24901 --> 1206 The Go DNS resolver now supports <code>resolv.conf</code>'s “<code>rotate</code>” 1207 and “<code>option</code> <code>ndots:0</code>” options. The “<code>ndots</code>” option is 1208 now respected in the same way as <code>libresolve</code>. 1209 </p> 1210 1211 </dd> 1212 </dl> 1213 1214 <dl id="net_http"><dt><a href="/pkg/net/http/">net/http</a></dt> 1215 <dd> 1216 1217 <p>Server changes:</p> 1218 <ul> 1219 <li>The server now supports graceful shutdown support, <a href="#http_shutdown">mentioned above</a>.</li> 1220 1221 <li> <!-- CL 32024 --> 1222 The <a href="/pkg/net/http/#Server"><code>Server</code></a> 1223 adds configuration options 1224 <code>ReadHeaderTimeout</code> and <code>IdleTimeout</code> 1225 and documents <code>WriteTimeout</code>. 1226 </li> 1227 1228 <li> <!-- CL 32014 --> 1229 <a href="/pkg/net/http/#FileServer"><code>FileServer</code></a> 1230 and 1231 <a href="/pkg/net/http/#ServeContent"><code>ServeContent</code></a> 1232 now support HTTP <code>If-Match</code> conditional requests, 1233 in addition to the previous <code>If-None-Match</code> 1234 support for ETags properly formatted according to RFC 7232, section 2.3. 1235 </li> 1236 </ul> 1237 1238 <p> 1239 There are several additions to what a server's <code>Handler</code> can do: 1240 </p> 1241 1242 <ul> 1243 <li><!-- CL 31173 --> 1244 The <a href="/pkg/context/#Context"><code>Context</code></a> 1245 returned 1246 by <a href="/pkg/net/http/#Request.Context"><code>Request.Context</code></a> 1247 is canceled if the underlying <code>net.Conn</code> 1248 closes. For instance, if the user closes their browser in the 1249 middle of a slow request, the <code>Handler</code> can now 1250 detect that the user is gone. This complements the 1251 existing <a href="/pkg/net/http/#CloseNotifier"><code>CloseNotifier</code></a> 1252 support. This functionality requires that the underlying 1253 <a href="/pkg/net/#Conn"><code>net.Conn</code></a> implements 1254 <a href="#net">recently clarified interface documentation</a>. 1255 </li> 1256 1257 <li><!-- CL 32479 --> 1258 To serve trailers produced after the header has already been written, 1259 see the new 1260 <a href="/pkg/net/http/#TrailerPrefix"><code>TrailerPrefix</code></a> 1261 mechanism. 1262 </li> 1263 1264 <li><!-- CL 33099 --> 1265 A <code>Handler</code> can now abort a response by panicking 1266 with the error 1267 <a href="/pkg/net/http/#ErrAbortHandler"><code>ErrAbortHandler</code></a>. 1268 </li> 1269 1270 <li><!-- CL 30812 --> 1271 A <code>Write</code> of zero bytes to a 1272 <a href="/pkg/net/http/#ResponseWriter"><code>ResponseWriter</code></a> 1273 is now defined as a 1274 way to test whether a <code>ResponseWriter</code> has been hijacked: 1275 if so, the <code>Write</code> returns 1276 <a href="/pkg/net/http/#ErrHijacked"><code>ErrHijacked</code></a> 1277 without printing an error 1278 to the server's error log. 1279 </li> 1280 1281 </ul> 1282 1283 <p>Client & Transport changes:</p> 1284 <ul> 1285 <li><!-- CL 28930, CL 31435 --> 1286 The <a href="/pkg/net/http/#Client"><code>Client</code></a> 1287 now copies most request headers on redirect. See 1288 <a href="/pkg/net/http/#Client">the documentation</a> 1289 on the <code>Client</code> type for details. 1290 </li> 1291 1292 <li><!-- CL 29072 --> 1293 The <a href="/pkg/net/http/#Transport"><code>Transport</code></a> 1294 now supports international domain names. Consequently, so do 1295 <a href="/pkg/net/http/#Get">Get</a> and other helpers. 1296 </li> 1297 1298 <li><!-- CL 31733, CL 29852 --> 1299 The <code>Client</code> now supports 301, 307, and 308 redirects. 1300 1301 For example, <code>Client.Post</code> now follows 301 1302 redirects, converting them to <code>GET</code> requests 1303 without bodies, like it did for 302 and 303 redirect responses 1304 previously. 1305 1306 The <code>Client</code> now also follows 307 and 308 1307 redirects, preserving the original request method and body, if 1308 any. If the redirect requires resending the request body, the 1309 request must have the new 1310 <a href="/pkg/net/http/#Request"><code>Request.GetBody</code></a> 1311 field defined. 1312 <a href="pkg/net/http/#NewRequest"><code>NewRequest</code></a> 1313 sets <code>Request.GetBody</code> automatically for common 1314 body types. 1315 </li> 1316 1317 <li><!-- CL 32482 --> 1318 The <code>Transport</code> now rejects requests for URLs with 1319 ports containing non-digit characters. 1320 </li> 1321 1322 <li><!-- CL 27117 --> 1323 The <code>Transport</code> will now retry non-idempotent 1324 requests if no bytes were written before a network failure 1325 and the request has no body. 1326 </li> 1327 1328 <li><!-- CL 32481 --> 1329 The 1330 new <a href="/pkg/net/http/#Transport"><code>Transport.ProxyConnectHeader</code></a> 1331 allows configuration of header values to send to a proxy 1332 during a <code>CONNECT</code> request. 1333 </li> 1334 1335 <li> <!-- CL 28077 --> 1336 The <a href="/pkg/net/http/#DefaultTransport"><code>DefaultTransport.Dialer</code></a> 1337 now enables <code>DualStack</code> ("<a href="https://tools.ietf.org/html/rfc6555">Happy Eyeballs</a>") support, 1338 allowing the use of IPv4 as a backup if it looks like IPv6 might be 1339 failing. 1340 </li> 1341 1342 <li> <!-- CL 31726 --> 1343 The <a href="/pkg/net/http/#Transport"><code>Transport</code></a> 1344 no longer reads a byte of a non-nil 1345 <a href="/pkg/net/http/#Request.Body"><code>Request.Body</code></a> 1346 when the 1347 <a href="/pkg/net/http/#Request.ContentLength"><code>Request.ContentLength</code></a> 1348 is zero to determine whether the <code>ContentLength</code> 1349 is actually zero or just undefined. 1350 To explicitly signal that a body has zero length, 1351 either set it to <code>nil</code>, or set it to the new value 1352 <a href="/pkg/net/http/#NoBody"><code>NoBody</code></a>. 1353 The new <code>NoBody</code> value is intended for use by <code>Request</code> 1354 constructor functions; it is used by 1355 <a href="/pkg/net/http/#NewRequest"><code>NewRequest</code></a>. 1356 </li> 1357 </ul> 1358 1359 </dd> 1360 </dl> 1361 1362 <dl id="net_http_httptrace"><dt><a href="/pkg/net/http/httptrace/">net/http/httptrace</a></dt> 1363 <dd> 1364 <p> <!-- CL 30359 --> 1365 There is now support for tracing a client request's TLS handshakes with 1366 the new 1367 <a href="/pkg/net/http/httptrace/#ClientTrace.TLSHandshakeStart"><code>ClientTrace.TLSHandshakeStart</code></a> 1368 and 1369 <a href="/pkg/net/http/httptrace/#ClientTrace.TLSHandshakeDone"><code>ClientTrace.TLSHandshakeDone</code></a>. 1370 </p> 1371 </dd> 1372 </dl> 1373 1374 <dl id="net_http_httputil"><dt><a href="/pkg/net/http/httputil/">net/http/httputil</a></dt> 1375 <dd> 1376 <p> <!-- CL 32356 --> 1377 The <a href="/pkg/net/http/httputil/#ReverseProxy"><code>ReverseProxy</code></a> 1378 has a new optional hook, 1379 <a href="/pkg/net/http/httputil/#ReverseProxy.ModifyResponse"><code>ModifyResponse</code></a>, 1380 for modifying the response from the back end before proxying it to the client. 1381 </p> 1382 1383 </dd> 1384 </dl> 1385 1386 <dl id="net_mail"><dt><a href="/pkg/net/mail/">net/mail</a></dt> 1387 <dd> 1388 1389 <p> <!-- CL 32176 --> 1390 Empty quoted strings are once again allowed in the name part of 1391 an address. That is, Go 1.4 and earlier accepted 1392 <code>""</code> <code><gopher@example.com></code>, 1393 but Go 1.5 introduced a bug that rejected this address. 1394 The address is recognized again. 1395 </p> 1396 1397 <p> <!-- CL 31581 --> 1398 The 1399 <a href="/pkg/net/mail/#Header.Date"><code>Header.Date</code></a> 1400 method has always provided a way to parse 1401 the <code>Date:</code> header. 1402 A new function 1403 <a href="/pkg/net/mail/#ParseDate"><code>ParseDate</code></a> 1404 allows parsing dates found in other 1405 header lines, such as the <code>Resent-Date:</code> header. 1406 </p> 1407 1408 </dd> 1409 </dl> 1410 1411 <dl id="net_smtp"><dt><a href="/pkg/net/smtp/">net/smtp</a></dt> 1412 <dd> 1413 1414 <p> <!-- CL 33143 --> 1415 If an implementation of the 1416 <a href="/pkg/net/smtp/#Auth"><code>Auth.Start</code></a> 1417 method returns an empty <code>toServer</code> value, 1418 the package no longer sends 1419 trailing whitespace in the SMTP <code>AUTH</code> command, 1420 which some servers rejected. 1421 </p> 1422 1423 </dd> 1424 </dl> 1425 1426 <dl id="net_url"><dt><a href="/pkg/net/url/">net/url</a></dt> 1427 <dd> 1428 1429 <p> <!-- CL 31322 --> 1430 The new functions 1431 <a href="/pkg/net/url/#PathEscape"><code>PathEscape</code></a> 1432 and 1433 <a href="/pkg/net/url/#PathUnescape"><code>PathUnescape</code></a> 1434 are similar to the query escaping and unescaping functions but 1435 for path elements. 1436 </p> 1437 1438 <p> <!-- CL 28933 --> 1439 The new methods 1440 <a href="/pkg/net/url/#URL.Hostname"><code>URL.Hostname</code></a> 1441 and 1442 <a href="/pkg/net/url/#URL.Port"><code>URL.Port</code></a> 1443 return the hostname and port fields of a URL, 1444 correctly handling the case where the port may not be present. 1445 </p> 1446 1447 <p> <!-- CL 28343 --> 1448 The existing method 1449 <a href="/pkg/net/url/#URL.ResolveReference"><code>URL.ResolveReference</code></a> 1450 now properly handles paths with escaped bytes without losing 1451 the escaping. 1452 </p> 1453 1454 <p> <!-- CL 31467 --> 1455 The <code>URL</code> type now implements 1456 <a href="/pkg/encoding/#BinaryMarshaler"><code>encoding.BinaryMarshaler</code></a> and 1457 <a href="/pkg/encoding/#BinaryUnmarshaler"><code>encoding.BinaryUnmarshaler</code></a>, 1458 making it possible to process URLs in <a href="/pkg/encoding/gob/">gob data</a>. 1459 </p> 1460 1461 <p> <!-- CL 29610, CL 31582 --> 1462 Following RFC 3986, 1463 <a href="/pkg/net/url/#Parse"><code>Parse</code></a> 1464 now rejects URLs like <code>this_that:other/thing</code> instead of 1465 interpreting them as relative paths (<code>this_that</code> is not a valid scheme). 1466 To force interpretation as a relative path, 1467 such URLs should be prefixed with “<code>./</code>”. 1468 The <code>URL.String</code> method now inserts this prefix as needed. 1469 </p> 1470 1471 </dd> 1472 </dl> 1473 1474 <dl id="os"><dt><a href="/pkg/os/">os</a></dt> 1475 <dd> 1476 <p> <!-- CL 16551 --> 1477 The new function 1478 <a href="/pkg/os/#Executable"><code>Executable</code></a> returns 1479 the path name of the running executable. 1480 </p> 1481 1482 <p> <!-- CL 30614 --> 1483 An attempt to call a method on 1484 an <a href="/pkg/os/#File"><code>os.File</code></a> that has 1485 already been closed will now return the new error 1486 value <a href="/pkg/os/#ErrClosed"><code>os.ErrClosed</code></a>. 1487 Previously it returned a system-specific error such 1488 as <code>syscall.EBADF</code>. 1489 </p> 1490 1491 <p> <!-- CL 31358 --> 1492 On Unix systems, <a href="/pkg/os/#Rename"><code>os.Rename</code></a> 1493 will now return an error when used to rename a directory to an 1494 existing empty directory. 1495 Previously it would fail when renaming to a non-empty directory 1496 but succeed when renaming to an empty directory. 1497 This makes the behavior on Unix correspond to that of other systems. 1498 </p> 1499 1500 <p> <!-- CL 32451 --> 1501 On Windows, long absolute paths are now transparently converted to 1502 extended-length paths (paths that start with “<code>\\?\</code>”). 1503 This permits the package to work with files whose path names are 1504 longer than 260 characters. 1505 </p> 1506 1507 <p> <!-- CL 29753 --> 1508 On Windows, <a href="/pkg/os/#IsExist"><code>os.IsExist</code></a> 1509 will now return <code>true</code> for the system 1510 error <code>ERROR_DIR_NOT_EMPTY</code>. 1511 This roughly corresponds to the existing handling of the Unix 1512 error <code>ENOTEMPTY</code>. 1513 </p> 1514 1515 <p> <!-- CL 32152 --> 1516 On Plan 9, files that are not served by <code>#M</code> will now 1517 have <a href="/pkg/os/#ModeDevice"><code>ModeDevice</code></a> set in 1518 the value returned 1519 by <a href="/pkg/os/#FileInfo"><code>FileInfo.Mode</code></a>. 1520 </p> 1521 </dd> 1522 </dl> 1523 1524 <dl id="path_filepath"><dt><a href="/pkg/path/filepath/">path/filepath</a></dt> 1525 <dd> 1526 <p> 1527 A number of bugs and corner cases on Windows were fixed: 1528 <a href="/pkg/path/filepath/#Abs"><code>Abs</code></a> now calls <code>Clean</code> as documented, 1529 <a href="/pkg/path/filepath/#Glob"><code>Glob</code></a> now matches 1530 “<code>\\?\c:\*</code>”, 1531 <a href="/pkg/path/filepath/#EvalSymlinks"><code>EvalSymlinks</code></a> now 1532 correctly handles “<code>C:.</code>”, and 1533 <a href="/pkg/path/filepath/#Clean"><code>Clean</code></a> now properly 1534 handles a leading “<code>..</code>” in the path. 1535 </p> 1536 </dd> 1537 </dl> 1538 1539 <dl id="reflect"><dt><a href="/pkg/reflect/">reflect</a></dt> 1540 <dd> 1541 <p> <!-- CL 30088 --> 1542 The new function 1543 <a href="/pkg/reflect/#Swapper"><code>Swapper</code></a> was 1544 added to support <a href="#sortslice"><code>sort.Slice</code></a>. 1545 </p> 1546 </dd> 1547 </dl> 1548 1549 <dl id="strconv"><dt><a href="/pkg/strconv/">strconv</a></dt> 1550 <dd> 1551 <p> <!-- CL 31210 --> 1552 The <a href="/pkg/strconv/#Unquote"><code>Unquote</code></a> 1553 function now strips carriage returns (<code>\r</code>) in 1554 backquoted raw strings, following the 1555 <a href="/ref/spec#String_literals">Go language semantics</a>. 1556 </p> 1557 </dd> 1558 </dl> 1559 1560 <dl id="syscall"><dt><a href="/pkg/syscall/">syscall</a></dt> 1561 <dd> 1562 <p> <!-- CL 25050, CL 25022 --> 1563 The <a href="/pkg/syscall/#Getpagesize"><code>Getpagesize</code></a> 1564 now returns the system's size, rather than a constant value. 1565 Previously it always returned 4KB. 1566 </p> 1567 1568 <p> <!-- CL 31446 --> 1569 The signature 1570 of <a href="/pkg/syscall/#Utimes"><code>Utimes</code></a> has 1571 changed on Solaris to match all the other Unix systems' 1572 signature. Portable code should continue to use 1573 <a href="/pkg/os/#Chtimes"><code>os.Chtimes</code></a> instead. 1574 </p> 1575 1576 <p> <!-- CL 32319 --> 1577 The <code>X__cmsg_data</code> field has been removed from 1578 <a href="/pkg/syscall/#Cmsghdr"><code>Cmsghdr</code></a>. 1579 </p> 1580 </dd> 1581 </dl> 1582 1583 <dl id="text_template"><dt><a href="/pkg/text/template/">text/template</a></dt> 1584 <dd> 1585 <p> <!-- CL 31462 --> 1586 <a href="/pkg/text/template/#Template.Execute"><code>Template.Execute</code></a> 1587 can now take a 1588 <a href="/pkg/reflect/#Value"><code>reflect.Value</code></a> as its data 1589 argument, and 1590 <a href="/pkg/text/template/#FuncMap"><code>FuncMap</code></a> 1591 functions can also accept and return <code>reflect.Value</code>. 1592 </p> 1593 1594 </dd> 1595 </dl> 1596 1597 <dl id="time"><dt><a href="/pkg/time/">time</a></dt> 1598 <dd> 1599 1600 <p> <!-- CL 20118 --> The new function 1601 <a href="/pkg/time/#Until"><code>Until</code></a> complements 1602 the analogous <code>Since</code> function. 1603 </p> 1604 1605 <p> <!-- CL 29338 --> 1606 <a href="/pkg/time/#ParseDuration"><code>ParseDuration</code></a> 1607 now accepts long fractional parts. 1608 </p> 1609 1610 <p> <!-- CL 33429 --> 1611 <a href="/pkg/time/#Parse"><code>Parse</code></a> 1612 now rejects dates before the start of a month, such as June 0; 1613 it already rejected dates beyond the end of the month, such as 1614 June 31 and July 32. 1615 </p> 1616 1617 <p> <!-- CL 33029 --> <!-- CL 34816 --> 1618 The <code>tzdata</code> database has been updated to version 1619 2016j for systems that don't already have a local time zone 1620 database. 1621 </p> 1622 1623 <p> 1624 </dd> 1625 </dl> 1626 1627 <dl id="testing"><dt><a href="/pkg/testing/">testing</a></dt> 1628 <dd> 1629 <p><!-- CL 29970 --> 1630 The new method 1631 <a href="/pkg/testing/#T.Name"><code>T.Name</code></a> 1632 (and <code>B.Name</code>) returns the name of the current 1633 test or benchmark. 1634 </p> 1635 1636 <p><!-- CL 32483 --> 1637 The new function 1638 <a href="/pkg/testing/#CoverMode"><code>CoverMode</code></a> 1639 reports the test coverage mode. 1640 </p> 1641 1642 <p><!-- CL 32615 --> 1643 Tests and benchmarks are now marked as failed if the race 1644 detector is enabled and a data race occurs during execution. 1645 Previously, individual test cases would appear to pass, 1646 and only the overall execution of the test binary would fail. 1647 </p> 1648 1649 <p><!-- CL 32455 --> 1650 The signature of the 1651 <a href="/pkg/testing/#MainStart"><code>MainStart</code></a> 1652 function has changed, as allowed by the documentation. It is an 1653 internal detail and not part of the Go 1 compatibility promise. 1654 If you're not calling <code>MainStart</code> directly but see 1655 errors, that likely means you set the 1656 normally-empty <code>GOROOT</code> environment variable and it 1657 doesn't match the version of your <code>go</code> command's binary. 1658 </p> 1659 1660 </dd> 1661 </dl> 1662 1663 <dl id="unicode"><dt><a href="/pkg/unicode/">unicode</a></dt> 1664 <dd> 1665 <p><!-- CL 30935 --> 1666 <a href="/pkg/unicode/#SimpleFold"><code>SimpleFold</code></a> 1667 now returns its argument unchanged if the provided input was an invalid rune. 1668 Previously, the implementation failed with an index bounds check panic. 1669 </p> 1670 </dd> 1671 </dl>