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