github.com/gocuntian/go@v0.0.0-20160610041250-fee02d270bf8/doc/go1.7.html (about) 1 <!--{ 2 "Title": "Go 1.7 Release Notes DRAFT", 3 "Path": "/doc/go1.7", 4 "Template": true 5 }--> 6 7 <!-- 8 for acme: 9 Edit .,s;^PKG:([a-z][A-Za-z0-9_/]+);<a href="/pkg/\1/"><code>\1</code></a>;g 10 Edit .,s;^([a-z][A-Za-z0-9_/]+)\.([A-Z][A-Za-z0-9_]+\.)?([A-Z][A-Za-z0-9_]+)([ .',)]|$);<a href="/pkg/\1/#\2\3"><code>\3</code></a>\4;g 11 Edit .,s;^FULL:([a-z][A-Za-z0-9_/]+)\.([A-Z][A-Za-z0-9_]+\.)?([A-Z][A-Za-z0-9_]+)([ .',)]|$);<a href="/pkg/\1/#\2\3"><code>\1.\2\3</code></a>\4;g 12 Edit .,s;^DPKG:([a-z][A-Za-z0-9_/]+);<dl id="\1"><a href="/pkg/\1/">\1</a></dl>;g 13 14 rsc last updated through 6729576 15 --> 16 17 <!-- 18 NOTE: In this document and others in this directory, the convention is to 19 set fixed-width phrases with non-fixed-width spaces, as in 20 <code>hello</code> <code>world</code>. 21 Do not send CLs removing the interior tags from such phrases. 22 --> 23 24 <style> 25 ul li { margin: 0.5em 0; } 26 </style> 27 28 <p> 29 <!-- TODO: REMOVE THIS COMMENT --> 30 <!-- TODO: Also remove "DRAFT" in the "Title" at the top of this file. --> 31 <i>NOTE: This is a DRAFT of the Go 1.7 release notes, prepared for the Go 1.7 beta. 32 Go 1.7 has NOT yet been released. 33 By our regular schedule, it is expected some time in August 2016. 34 </i> 35 </p> 36 37 <h2 id="introduction">Introduction to Go 1.7</h2> 38 39 <p> 40 The latest Go release, version 1.7, arrives six months after 1.6. 41 Most of its changes are in the implementation of the toolchain, runtime, and libraries. 42 There is one minor change to the language specification. 43 As always, the release maintains the Go 1 <a href="/doc/go1compat.html">promise of compatibility</a>. 44 We expect almost all Go programs to continue to compile and run as before. 45 </p> 46 47 <p> 48 The release <a href="#ports">adds a port to IBM LinuxOne</a>; 49 <a href="#compiler">updates the x86-64 compiler back end</a> to generate more efficient code; 50 includes the <a href="#context">context package</a>, promoted from the 51 <a href="https://golang.org/x/net/context">x/net subrepository</a> 52 and now used in the standard library; 53 and <a href="#testing">adds support in the testing package</a> for 54 creating hierarchies of tests and benchmarks. 55 The release also <a href="#cmd/go">finalizes the vendoring support</a> 56 started in Go 1.5, making it a standard feature. 57 </p> 58 59 <h2 id="language">Changes to the language</h2> 60 61 <p> 62 There is one tiny language change in this release. 63 The section on <a href="/ref/spec#Terminating_statements">terminating statements</a> 64 clarifies that to determine whether a statement list ends in a terminating statement, 65 the “final non-empty statement” is considered the end, 66 matching the existing behavior of the gc and gccgo compiler toolchains. 67 In earlier releases the definition referred only to the “final statement,” 68 leaving the effect of trailing empty statements at the least unclear. 69 The <a href="/pkg/go/types/"><code>go/types</code></a> 70 package has been updated to match the gc and gccgo compiler toolchains 71 in this respect. 72 This change has no effect on the correctness of existing programs. 73 </p> 74 75 <h2 id="ports">Ports</h2> 76 77 <p> 78 Go 1.7 adds an experimental port to <a href="https://en.wikipedia.org/wiki/Linux_on_z_Systems">Linux on z Systems</a> (<code>linux/s390x</code>) 79 and the beginning of a port to Plan 9 on ARM (<code>plan9/arm</code>). 80 </p> 81 82 <p> 83 The experimental ports to Linux on 64-bit MIPS (<code>linux/mips64</code> and <code>linux/mips64le</code>) 84 added in Go 1.6 now have full support for cgo and external linking. 85 </p> 86 87 <p> 88 The experimental port to Linux on big-endian 64-bit PowerPC (<code>linux/ppc64</code>) 89 now requires the POWER8 architecture or later. 90 </p> 91 92 <p> 93 The OpenBSD port now requires OpenBSD 5.6 or later, for access to the <a href="http://man.openbsd.org/getentropy.2"><i>getentropy</i>(2)</a> system call. 94 </p> 95 96 <h2 id="tools">Tools</h2> 97 98 <h3 id="cmd_asm">Assembler</h3> 99 100 <p> 101 For 64-bit ARM systems, the vector register names have been 102 corrected to <code>V0</code> through <code>V31</code>; 103 previous releases incorrectly referred to them as <code>V32</code> through <code>V63</code>. 104 </p> 105 106 <p> 107 For 64-bit x86 systems, the following instructions have been added: 108 <code>PCMPESTRI</code>, 109 <code>RORXL</code>, 110 <code>RORXQ</code>, 111 <code>VINSERTI128</code>, 112 <code>VPADDD</code>, 113 <code>VPADDQ</code>, 114 <code>VPALIGNR</code>, 115 <code>VPBLENDD</code>, 116 <code>VPERM2F128</code>, 117 <code>VPERM2I128</code>, 118 <code>VPOR</code>, 119 <code>VPSHUFB</code>, 120 <code>VPSHUFD</code>, 121 <code>VPSLLD</code>, 122 <code>VPSLLDQ</code>, 123 <code>VPSLLQ</code>, 124 <code>VPSRLD</code>, 125 <code>VPSRLDQ</code>, 126 and 127 <code>VPSRLQ</code>. 128 </p> 129 130 <h3 id="compiler">Compiler Toolchain</h3> 131 132 <p> 133 This release includes a new code generation back end for 64-bit x86 systems, 134 following a <a href="https://golang.org/s/go17ssa">proposal from 2015</a> 135 that has been under development since then. 136 The new back end, based on 137 <a href="https://en.wikipedia.org/wiki/Static_single_assignment_form">SSA</a>, 138 generates more compact, more efficient code 139 and provides a better platform for optimizations 140 such as bounds check elimination. 141 The new back end reduces the CPU time required by 142 <a href="https://golang.org/test/bench/go1/">our benchmark programs</a> by 5-35%. 143 </p> 144 145 <p> 146 For this release, the new back end can be disabled by passing 147 <code>-ssa=0</code> to the compiler. 148 If you find that your program compiles or runs successfully 149 only with the new back end disabled, please 150 <a href="https://golang.org/issue/new">file a bug report</a>. 151 </p> 152 153 <p> 154 The format of exported metadata written by the compiler in package archives has changed: 155 the old textual format has been replaced by a more compact binary format. 156 This results in somewhat smaller package archives and fixes a few 157 long-standing corner case bugs. 158 </p> 159 160 <p> 161 For this release, the new export format can be disabled by passing 162 <code>-newexport=0</code> to the compiler. 163 If you find that your program compiles or runs successfully 164 only with the new export format disabled, please 165 <a href="https://golang.org/issue/new">file a bug report</a>. 166 </p> 167 168 <p> 169 The linker's <code>-X</code> option no longer supports the unusual two-argument form 170 <code>-X</code> <code>name</code> <code>value</code>, 171 as <a href="/doc/go1.6#compiler">announced</a> in the Go 1.6 release 172 and in warnings printed by the linker. 173 Use <code>-X</code> <code>name=value</code> instead. 174 </p> 175 176 <p> 177 The compiler and linker have been optimized and run significantly faster in this release than in Go 1.6, 178 although they are still slower than we would like and will continue to be optimized in future releases. 179 </p> 180 181 <p> 182 Due to changes across the compiler toolchain and standard library, 183 binaries built with this release should typically be smaller than binaries 184 built with Go 1.6, 185 sometimes by as much as 20-30%. 186 </p> 187 188 <p> 189 On x86-64 systems, Go programs now maintain stack frame pointers 190 as expected by profiling tools like Linux's perf and Intel's VTune, 191 making it easier to analyze and optimize Go programs using these tools. 192 The frame pointer maintenance has a small run-time overhead that varies 193 but averages around 2%. We hope to reduce this cost in future releases. 194 To build a toolchain that does not use frame pointers, set 195 <code>GOEXPERIMENT=noframepointer</code> when running 196 <code>make.bash</code>, <code>make.bat</code>, or <code>make.rc</code>. 197 </p> 198 199 <h3 id="cmd_cgo">Cgo</h3> 200 201 <p> 202 Packages using <a href="/cmd/cgo/">cgo</a> may now include 203 Fortran source files (in addition to C, C++, Objective C, and SWIG), 204 although the Go bindings must still use C language APIs. 205 </p> 206 207 <p> 208 Go bindings may now use a new helper function <code>C.CBytes</code>. 209 In contrast to <code>C.CString</code>, which takes a Go <code>string</code> 210 and returns a <code>*C.byte</code> (a C <code>char*</code>), 211 <code>C.CBytes</code> takes a Go <code>[]byte</code> 212 and returns an <code>unsafe.Pointer</code> (a C <code>void*</code>). 213 </p> 214 215 <p> 216 Packages and binaries built using <code>cgo</code> have in past releases 217 produced different output on each build, 218 due to the embedding of temporary directory names. 219 When using this release with 220 new enough versions of GCC or Clang 221 (those that support the <code>-fdebug-prefix-map</code> option), 222 those builds should finally be deterministic. 223 </p> 224 225 <h3 id="gccgo">Gccgo</h3> 226 227 <p> 228 Due to the alignment of Go's semiannual release schedule with GCC's annual release schedule, 229 GCC release 6 contains the Go 1.6.1 version of gccgo. 230 The next release, GCC 7, will likely have the Go 1.8 version of gccgo. 231 </p> 232 233 <h3 id="cmd_go">Go command</h3> 234 235 <p> 236 The <a href="/cmd/go/"><code>go</code></a> command's basic operation 237 is unchanged, but there are a number of changes worth noting. 238 </p> 239 240 <p> 241 This release removes support for the <code>GO15VENDOREXPERIMENT</code> environment variable, 242 as <a href="/doc/go1.6#go_command">announced</a> in the Go 1.6 release. 243 <a href="https://golang.org/s/go15vendor">Vendoring support</a> 244 is now a standard feature of the <code>go</code> command and toolchain. 245 </p> 246 247 <p> 248 The <code>Package</code> data structure made available to 249 “<code>go</code> <code>list</code>” now includes a 250 <code>StaleReason</code> field explaining why a particular package 251 is or is not considered stale (in need of rebuilding). 252 This field is available to the <code>-f</code> or <code>-json</code> 253 options and is useful for understanding why a target is being rebuilt. 254 </p> 255 256 <p> 257 The “<code>go</code> <code>get</code>” command now supports 258 import paths referring to <code>git.openstack.org</code>. 259 </p> 260 261 <p> 262 This release adds experimental, minimal support for building programs using 263 <a href="/pkg/go/build#hdr-Binary_Only_Packages">binary-only packages</a>, 264 packages distributed in binary form 265 without the corresponding source code. 266 This feature is needed in some commercial settings 267 but is not intended to be fully integrated into the rest of the toolchain. 268 For example, tools that assume access to complete source code 269 will not work with such packages, and there are no plans to support 270 such packages in the “<code>go</code> <code>get</code>” command. 271 </p> 272 273 <h3 id="cmd_doc">Go doc</h3> 274 275 <p> 276 The “<code>go</code> <code>doc</code>” command 277 now groups constructors with the type they construct, 278 following <a href="/cmd/godoc/"><code>godoc</code></a>. 279 </p> 280 281 <h3 id="cmd_vet">Go vet</h3> 282 283 <p> 284 The “<code>go</code> <code>vet</code>” command 285 has more accurate analysis in its <code>-copylock</code> and <code>-printf</code> checks, 286 and a new <code>-tests</code> check that checks the name and signature of likely test functions. 287 To avoid confusion with the new <code>-tests</code> check, the old, unadvertised 288 <code>-test</code> option has been removed; it was equivalent to <code>-all</code> <code>-shadow</code>. 289 </p> 290 291 <h3 id="cmd_dist">Go tool dist</h3> 292 293 <p> 294 The new subcommand “<code>go</code> <code>tool</code> <code>dist</code> <code>list</code>” 295 prints all supported operating system/architecture pairs. 296 </p> 297 298 <h3 id="cmd_trace">Go tool trace</h3> 299 300 <p> 301 The “<code>go</code> <code>tool</code> <code>trace</code>” command, 302 <a href="/doc/go1.5#trace_command">introduced in Go 1.5</a>, 303 has been refined in various ways. 304 </p> 305 306 <p> 307 First, collecting traces is significantly more efficient than in past releases. 308 In this release, the typical execution-time overhead of collecting a trace is about 25%; 309 in past releases it was at least 400%. 310 Second, trace files now include file and line number information, 311 making them more self-contained and making the 312 original executable optional when running the trace tool. 313 Third, the trace tool now breaks up large traces to avoid limits 314 in the browser-based viewer. 315 </p> 316 317 <p> 318 Although the trace file format has changed in this release, 319 the Go 1.7 tools can still read traces from earlier releases. 320 </p> 321 322 <h2 id="performance">Performance</h2> 323 324 <p> 325 As always, the changes are so general and varied that precise statements 326 about performance are difficult to make. 327 Most programs should run a bit faster, 328 due to speedups in the garbage collector and 329 optimizations in the core library. 330 On x86-64 systems, many programs will run significantly faster, 331 due to improvements in generated code brought by the 332 new compiler back end. 333 As noted above, in our own benchmarks, 334 the code generation changes alone typically reduce program CPU time by 5-35%. 335 </p> 336 337 <p> 338 <!-- git log --grep '-[0-9][0-9]\.[0-9][0-9]%' go1.6.. --> 339 There have been significant optimizations bringing more than 10% improvements 340 to implementations in the 341 <a href="/pkg/crypto/sha1/"><code>crypto/sha1</code></a>, 342 <a href="/pkg/crypto/sha256/"><code>crypto/sha256</code></a>, 343 <a href="/pkg/encoding/binary/"><code>encoding/binary</code></a>, 344 <a href="/pkg/fmt/"><code>fmt</code></a>, 345 <a href="/pkg/hash/adler32/"><code>hash/adler32</code></a>, 346 <a href="/pkg/hash/crc32/"><code>hash/crc32</code></a>, 347 <a href="/pkg/hash/crc64/"><code>hash/crc64</code></a>, 348 <a href="/pkg/image/color/"><code>image/color</code></a>, 349 <a href="/pkg/math/big/"><code>math/big</code></a>, 350 <a href="/pkg/strconv/"><code>strconv</code></a>, 351 <a href="/pkg/strings/"><code>strings</code></a>, 352 <a href="/pkg/unicode/"><code>unicode</code></a>, 353 and 354 <a href="/pkg/unicode/utf16/"><code>unicode/utf16</code></a> 355 packages. 356 </p> 357 358 <h2 id="library">Core library</h2> 359 360 <h3 id="context">Context</h3> 361 362 <p> 363 Go 1.7 moves the <code>golang.org/x/net/context</code> package 364 into the standard library as <a href="/pkg/context/"><code>context</code></a>. 365 This allows the use of contexts for cancelation, timeouts, and passing 366 request-scoped data in other standard library packages, 367 including 368 <a href="#net">net</a>, 369 <a href="#net/http">net/http</a>, 370 and 371 <a href="#os/exec">os/exec</a>, 372 as noted below. 373 </p> 374 375 <p> 376 For more information about contexts, see the 377 <a href="/pkg/context/">package documentation</a> 378 and the Go blog post 379 “<a href="https://blog.golang.org/context">Go Concurrent Patterns: Context</a>.” 380 </p> 381 382 <h3 id="httptrace">HTTP Tracing</h3> 383 384 <p> 385 Go 1.7 introduces <a href="/pkg/net/http/httptrace/"><code>net/http/httptrace</code></a>, 386 a package that provides mechanisms for tracing events within HTTP requests. 387 </p> 388 389 <h3 id="testing">Testing</h3> 390 391 <p> 392 The <code>testing</code> package now supports the definition 393 of tests with subtests and benchmarks with sub-benchmarks. 394 This support makes it easy to write table-driven benchmarks 395 and to create hierarchical tests. 396 It also provides a way to share common setup and tear-down code. 397 See the <a href="/pkg/testing/#hdr-Subtests_and_Sub_benchmarks">package documentation</a> for details. 398 </p> 399 400 <h3 id="runtime">Runtime</h3> 401 402 <p> 403 All panics started by the runtime now use panic values 404 that implement both the 405 builtin <a href="/ref/spec#Errors"><code>error</code></a>, 406 and 407 <a href="/pkg/runtime/#Error"><code>runtime.Error</code></a>, 408 as 409 <a href="/ref/spec#Run_time_panics">required by the language specification</a>. 410 </p> 411 412 <p> 413 During panics, if a signal's name is known, it will be printed in the stack trace. 414 Otherwise, the signal's number will be used, as it was before Go1.7. 415 </p> 416 417 <p> 418 The new function 419 <a href="/pkg/runtime/#KeepAlive"><code>KeepAlive</code></a> 420 provides an explicit mechanism for declaring 421 that an allocated object must be considered reachable 422 at a particular point in a program, 423 typically to delay the execution of an associated finalizer. 424 </p> 425 426 <p> 427 The new function 428 <a href="/pkg/runtime/#CallersFrames"><code>CallersFrames</code></a> 429 translates a PC slice obtained from 430 <a href="/pkg/runtime/#Callers"><code>Callers</code></a> 431 into a sequence of frames corresponding to the call stack. 432 This new API should be preferred instead of direct use of 433 <a href="/pkg/runtime/#FuncForPC"><code>FuncForPC</code></a>, 434 because the frame sequence can more accurately describe 435 call stacks with inlined function calls. 436 </p> 437 438 <p> 439 The new function 440 <a href="/pkg/runtime/#SetCgoTraceback"><code>SetCgoTraceback</code></a> 441 facilitates tighter integration between Go and C code executing 442 in the same process called using cgo. 443 </p> 444 445 <p> 446 On 32-bit systems, the runtime can now use memory allocated 447 by the operating system anywhere in the address space, 448 eliminating the 449 “memory allocated by OS not in usable range” failure 450 common in some environments. 451 </p> 452 453 <p> 454 On Windows, Go programs in Go 1.5 and earlier forced 455 the global Windows timer resolution to 1ms at startup 456 by calling <code>timeBeginPeriod(1)</code>. 457 Changing the global timer resolution caused problems on some systems, 458 and testing suggested that the call was not needed for good scheduler performance, 459 so Go 1.6 removed the call. 460 Go 1.7 brings the call back: under some workloads the call 461 is still needed for good scheduler performance. 462 </p> 463 464 465 <h3 id="minor_library_changes">Minor changes to the library</h3> 466 467 <p> 468 As always, there are various minor changes and updates to the library, 469 made with the Go 1 <a href="/doc/go1compat">promise of compatibility</a> 470 in mind. 471 </p> 472 473 <dl id="bufio"><dt><a href="/pkg/bufio/">bufio</a></dt> 474 475 <dd> 476 <p> 477 In previous releases of Go, if 478 <a href="/pkg/bufio/#Reader"><code>Reader</code></a>'s 479 <a href="/pkg/bufio/#Reader.Peek"><code>Peek</code></a> method 480 were asked for more bytes than fit in the underlying buffer, 481 it would return an empty slice and the error <code>ErrBufferFull</code>. 482 Now it returns the entire underlying buffer, still accompanied by the error <code>ErrBufferFull</code>. 483 </p> 484 </dd> 485 </dl> 486 487 <dl id="bytes"><dt><a href="/pkg/bytes/">bytes</a></dt> 488 489 <dd> 490 <p> 491 The new functions 492 <a href="/pkg/bytes/#ContainsAny"><code>ContainsAny</code></a> and 493 <a href="/pkg/bytes/#ContainsRune"><code>ContainsRune</code></a> 494 have been added for symmetry with 495 the <a href="/pkg/strings/"><code>strings</code></a> package. 496 </p> 497 498 <p> 499 In previous releases of Go, if 500 <a href="/pkg/bytes/#Reader"><code>Reader</code></a>'s 501 <a href="/pkg/bytes/#Reader.Read"><code>Read</code></a> method 502 were asked for zero bytes with no data remaining, it would 503 return a count of 0 and no error. 504 Now it returns a count of 0 and the error 505 <a href="/pkg/io/#EOF"><code>io.EOF</code></a>. 506 </p> 507 508 <p> 509 The 510 <a href="/pkg/bytes/#Reader"><code>Reader</code></a> type has a new method 511 <a href="/pkg/bytes/#Reader.Reset"><code>Reset</code></a> to allow reuse of a <code>Reader</code>. 512 </p> 513 </dd> 514 </dl> 515 516 <dl id="compress_flate"><dt><a href="/pkg/compress/flate/">compress/flate</a></dt> 517 518 <dd> 519 <p> 520 As noted above, 521 there are significant performance optimizations throughout the package. 522 Decompression speed is improved by about 10%, 523 while compression speed for <code>DefaultCompression</code> is roughly doubled. 524 </p> 525 526 <p> 527 In addition to those general improvements, 528 the 529 <code>BestSpeed</code> 530 compressor has been replaced entirely and uses an 531 algorithm similar to <a href="https://github.com/google/snappy">Snappy</a>, 532 resulting in about a 2.5X speed increase, 533 although the output can be 5-10% larger than with the previous algorithm. 534 </p> 535 536 <p> 537 There is also a new compression level 538 <code>HuffmanOnly</code> 539 that applies Huffman but not Lempel-Ziv encoding. 540 <a href="https://blog.klauspost.com/constant-time-gzipzip-compression/">Forgoing Lempel-Ziv encoding</a> means that 541 <code>HuffmanOnly</code> runs about 3X faster than the new <code>BestSpeed</code> 542 but at the cost of producing compressed outputs that are 20-40% larger than those 543 generated by the new <code>BestSpeed</code>. 544 </p> 545 546 <p> 547 It is important to note that both 548 <code>BestSpeed</code> and <code>HuffmanOnly</code> produce a compressed output that is 549 <a href="https://tools.ietf.org/html/rfc1951">RFC 1951</a> compliant. 550 In other words, any valid DEFLATE decompressor will continue to be able to decompress these outputs. 551 </p> 552 553 <p> 554 Lastly, there is a minor change to the decompressor's implementation of 555 <a href="/pkg/io/#Reader"><code>io.Reader</code></a>. In previous versions, 556 the decompressor deferred reporting 557 <a href="/pkg/io/#EOF"><code>io.EOF</code></a> until exactly no more bytes could be read. 558 Now, it reports 559 <a href="/pkg/io/#EOF"><code>io.EOF</code></a> more eagerly when reading the last set of bytes. 560 </p> 561 </dd> 562 </dl> 563 564 <dl id="crypto_tls"><dt><a href="/pkg/crypto/tls/">crypto/tls</a></dt> 565 566 <dd> 567 <p> 568 The TLS implementation sends the first few data packets on each connection 569 using small record sizes, gradually increasing to the TLS maximum record size. 570 This heuristic reduces the amount of data that must be received before 571 the first packet can be decrypted, improving communication latency over 572 low-bandwidth networks. 573 Setting 574 <a href="/pkg/crypto/tls/#Config"><code>Config</code></a>'s 575 <code>DynamicRecordSizingDisabled</code> field to true 576 forces the behavior of Go 1.6 and earlier, where packets are 577 as large as possible from the start of the connection. 578 </p> 579 580 <p> 581 The TLS client now has optional, limited support for server-initiated renegotiation, 582 enabled by setting the 583 <a href="/pkg/crypto/tls/#Config"><code>Config</code></a>'s 584 <code>Renegotiation</code> field. 585 This is needed for connecting to many Microsoft Azure servers. 586 </p> 587 588 <p> 589 The errors returned by the package now consistently begin with a 590 <code>tls:</code> prefix. 591 In past releases, some errors used a <code>crypto/tls:</code> prefix, 592 some used a <code>tls:</code> prefix, and some had no prefix at all. 593 </p> 594 595 <p> 596 When generating self-signed certificates, the package no longer sets the 597 “Authority Key Identifier” field by default. 598 </p> 599 </dd> 600 </dl> 601 602 <dl id="crypto_x509"><dt><a href="/pkg/crypto/x509/">crypto/x509</a></dt> 603 604 <dd> 605 <p> 606 The new function 607 <a href="/pkg/crypto/x509/#SystemCertPool"><code>SystemCertPool</code></a> 608 provides access to the entire system certificate pool if available. 609 There is also a new associated error type 610 <a href="/pkg/crypto/x509/#SystemRootsError"><code>SystemRootsError</code></a>. 611 </p> 612 </dd> 613 </dl> 614 615 <dl id="debug_dwarf"><dt><a href="/pkg/debug/dwarf/">debug/dwarf</a></dt> 616 617 <dd> 618 <p> 619 The 620 <a href="/pkg/debug/dwarf/#Reader"><code>Reader</code></a> type's new 621 <a href="/pkg/debug/dwarf/#Reader.SeekPC"><code>SeekPC</code></a> method and the 622 <a href="/pkg/debug/dwarf/#Data"><code>Data</code></a> type's new 623 <a href="/pkg/debug/dwarf/#Ranges"><code>Ranges</code></a> method 624 help to find the compilation unit to pass to a 625 <a href="/pkg/debug/dwarf/#LineReader"><code>LineReader</code></a> 626 and to identify the specific function for a given program counter. 627 </p> 628 </dd> 629 </dl> 630 631 <dl id="debug_elf"><dt><a href="/pkg/debug/elf/">debug/elf</a></dt> 632 633 <dd> 634 <p> 635 The new 636 <a href="/pkg/debug/elf/#R_390"><code>R_390</code></a> relocation type 637 and its many predefined constants 638 support the S390 port. 639 </p> 640 </dd> 641 </dl> 642 643 <dl id="encoding_asn1"><dt><a href="/pkg/encoding/asn1/">encoding/asn1</a></dt> 644 645 <dd> 646 <p> 647 The ASN.1 decoder now rejects non-minimal integer encodings. 648 This may cause the package to reject some invalid but formerly accepted ASN.1 data. 649 </p> 650 </dd> 651 </dl> 652 653 <dl id="encoding_json"><dt><a href="/pkg/encoding/json/">encoding/json</a></dt> 654 655 <dd> 656 <p> 657 The 658 <a href="/pkg/encoding/json/#Encoder"><code>Encoder</code></a>'s new 659 <a href="/pkg/encoding/json/#Encoder.SetIndent"><code>SetIndent</code></a> method 660 sets the indentation parameters for JSON encoding, 661 like in the top-level 662 <a href="/pkg/encoding/json/#Indent"><code>Indent</code></a> function. 663 </p> 664 665 <p> 666 The 667 <a href="/pkg/encoding/json/#Encoder"><code>Encoder</code></a>'s new 668 <a href="/pkg/encoding/json/#Encoder.SetEscapeHTML"><code>SetEscapeHTML</code></a> method 669 controls whether the 670 <code>&</code>, <code><</code>, and <code>></code> 671 characters in quoted strings should be escaped as 672 <code>\u0026</code>, <code>\u003c</code>, and <code>\u003e</code>, 673 respectively. 674 As in previous releases, the encoder defaults to applying this escaping, 675 to avoid certain problems that can arise when embedding JSON in HTML. 676 </p> 677 678 <p> 679 In earlier versions of Go, this package only supported encoding and decoding 680 maps using keys with string types. 681 Go 1.7 adds support for maps using keys with integer types: 682 the encoding uses a quoted decimal representation as the JSON key. 683 Go 1.7 also adds support for encoding maps using non-string keys that implement 684 the <code>MarshalText</code> 685 (see 686 <a href="/pkg/encoding/#TextMarshaler"><code>encoding.TextMarshaler</code></a>) 687 method, 688 as well as support for decoding maps using non-string keys that implement 689 the <code>UnmarshalText</code> 690 (see 691 <a href="/pkg/encoding/#TextUnmarshaler"><code>encoding.TextUnmarshaler</code></a>) 692 method. 693 These methods are ignored for keys with string types in order to preserve 694 the encoding and decoding used in earlier versions of Go. 695 </p> 696 697 <p> 698 When encoding a slice of typed bytes, 699 <a href="/pkg/encoding/json/#Marshal"><code>Marshal</code></a> 700 now generates an array of elements encoded using 701 that byte type's 702 <code>MarshalJSON</code> 703 or 704 <code>MarshalText</code> 705 method if present, 706 only falling back to the default base64-encoded string data if neither method is available. 707 Earlier versions of Go accept both the original base64-encoded string encoding 708 and the array encoding (assuming the byte type also implements 709 <code>UnmarshalJSON</code> 710 or 711 <code>UnmarshalText</code> 712 as appropriate), 713 so this change should be semantically backwards compatible with earlier versions of Go, 714 even though it does change the chosen encoding. 715 </p> 716 </dd> 717 </dl> 718 719 <dl id="go_build"><dt><a href="/pkg/go/build/">go/build</a></dt> 720 721 <dd> 722 <p> 723 To implement the go command's new support for binary-only packages 724 and for Fortran code in cgo-based packages, 725 the 726 <a href="/pkg/go/build/#Package"><code>Package</code></a> type 727 adds new fields <code>BinaryOnly</code>, <code>CgoFFLAGS</code>, and <code>FFiles</code>. 728 </p> 729 </dd> 730 </dl> 731 732 <dl id="go_doc"><dt><a href="/pkg/go/doc/">go/doc</a></dt> 733 734 <dd> 735 <p> 736 To support the corresponding change in <code>go</code> <code>test</code> described above, 737 <a href="/pkg/go/doc/#Example"><code>Example</code></a> struct adds a Unordered field 738 indicating whether the example may generate its output lines in any order. 739 </p> 740 </dd> 741 </dl> 742 743 <dl id="io"><dt><a href="/pkg/io/">io</a></dt> 744 745 <dd> 746 <p> 747 The package adds new constants 748 <code>SeekStart</code>, <code>SeekCurrent</code>, and <code>SeekEnd</code>, 749 for use with 750 <a href="/pkg/io/#Seeker"><code>Seeker</code></a> 751 implementations. 752 These constants are preferred over <code>os.SEEK_SET</code>, <code>os.SEEK_CUR</code>, and <code>os.SEEK_END</code>, 753 but the latter will be preserved for compatibility. 754 </p> 755 </dd> 756 </dl> 757 758 <dl id="math_big"><dt><a href="/pkg/math/big/">math/big</a></dt> 759 760 <dd> 761 <p> 762 The 763 <a href="/pkg/math/big/#Float"><code>Float</code></a> type adds 764 <a href="/pkg/math/big/#Float.GobEncode"><code>GobEncode</code></a> and 765 <a href="/pkg/math/big/#Float.GobDecode"><code>GobDecode</code></a> methods, 766 so that values of type <code>Float</code> can now be encoded and decoded using the 767 <a href="/pkg/encoding/gob/"><code>encoding/gob</code></a> 768 package. 769 </p> 770 </dd> 771 </dl> 772 773 <dl id="mime_multipart"><dt><a href="/pkg/mime/multipart/">mime/multipart</a></dt> 774 775 <dd> 776 <p> 777 The 778 <a href="/pkg/mime/multipart/#Writer"><code>Writer</code></a> 779 implementation now emits each multipart section's header sorted by key. 780 Previously, iteration over a map caused the section header to use a 781 non-deterministic order. 782 </p> 783 </dd> 784 </dl> 785 786 <dl id="net"><dt><a href="/pkg/net/">net</a></dt> 787 788 <dd> 789 <p> 790 As part of the introduction of <a href="#context">context</a>, the 791 <a href="/pkg/net/#Dialer"><code>Dialer</code></a> type has a new method 792 <a href="/pkg/net/#Dialer.DialContext"><code>DialContext</code></a>, like 793 <a href="/pkg/net/#Dialer.Dial"><code>Dial</code></a> but adding the 794 <a href="/pkg/context/#Context"><code>context.Context</code></a> 795 for the dial operation. 796 The context is intended to obsolete the <code>Dialer</code>'s 797 <code>Cancel</code> and <code>Deadline</code> fields, 798 but the implementation continues to respect them, 799 for backwards compatibility. 800 </p> 801 802 <p> 803 The 804 <a href="/pkg/net/#IP"><code>IP</code></a> type's 805 <a href="/pkg/net/#IP.String"><code>String</code></a> method has changed its result for invalid <code>IP</code> addresses. 806 In past releases, if an <code>IP</code> byte slice had length other than 0, 4, or 16, <code>String</code> 807 returned <code>"?"</code>. 808 Go 1.7 adds the hexadecimal encoding of the bytes, as in <code>"?12ab"</code>. 809 </p> 810 811 <p> 812 The pure Go <a href="/pkg/net/#hdr-Name_Resolution">name resolution</a> 813 implementation now respects <code>nsswitch.conf</code>'s 814 stated preference for the priority of DNS lookups compared to 815 local file (that is, <code>/etc/hosts</code>) lookups. 816 </p> 817 </dd> 818 </dl> 819 820 <dl id="net_http"><dt><a href="/pkg/net/http/">net/http</a></dt> 821 822 <dd> 823 <p> 824 <a href="/pkg/net/http/#ResponseWriter"><code>ResponseWriter</code></a>'s 825 documentation now makes clear that beginning to write the response 826 may prevent future reads on the request body. 827 For maximal compatibility, implementations are encouraged to 828 read the request body completely before writing any part of the response. 829 </p> 830 831 <p> 832 As part of the introduction of <a href="#context">context</a>, the 833 <a href="/pkg/net/http/#Request"><code>Request</code></a> has a new methods 834 <a href="/pkg/net/http/#Request.Context"><code>Context</code></a>, to retrieve the associated context, and 835 <a href="/pkg/net/http/#Request.WithContext"><code>WithContext</code></a>, to construct a copy of <code>Request</code> 836 with a modified context. 837 </p> 838 839 <p> 840 In the 841 <a href="/pkg/net/http/#Server"><code>Server</code></a> implementation, 842 <a href="/pkg/net/http/#Server.Serve"><code>Serve</code></a> records in the request context 843 both the underlying <code>*Server</code> using the key <code>ServerContextKey</code> 844 and the local address on which the request was received (a 845 <a href="/pkg/net/#Addr"><code>Addr</code></a>) using the key <code>LocalAddrContextKey</code>. 846 For example, the address on which a request received is 847 <code>req.Context().Value(http.LocalAddrContextKey).(net.Addr)</code>. 848 </p> 849 850 <p> 851 The server implementation now 852 pads response codes less than 100 to three digits 853 as required by the protocol, 854 so that <code>w.WriteHeader(5)</code> uses the HTTP response 855 status <code>005</code>, not just <code>5</code>. 856 </p> 857 858 <p> 859 In the client, the 860 <a href="/pkg/net/http/#Transport"><code>Transport</code></a> implementation passes the request context 861 to any dial operation connecting to the remote server. 862 If a custom dialer is needed, the new <code>Transport</code> field 863 <code>DialContext</code> is preferred over the existing <code>Dial</code> field, 864 to allow the transport to supply a context. 865 </p> 866 867 <p> 868 The 869 <a href="/pkg/net/http/#Transport"><code>Transport</code></a> also adds fields 870 <code>IdleConnTimeout</code>, 871 <code>MaxIdleConns</code>, 872 and 873 <code>MaxResponseHeaderBytes</code> 874 to help control client resources consumed 875 by idle or chatty servers. 876 </p> 877 878 <p> 879 A 880 <a href="/pkg/net/http/#Client"><code>Client</code></a>'s configured <code>CheckRedirect</code> function can now 881 return <code>ErrUseLastResponse</code> to indicate that the 882 most recent redirect response should be returned as the 883 result of the HTTP request. 884 That response is now available to the <code>CheckRedirect</code> function 885 as <code>req.Response</code>. 886 </p> 887 888 <p> 889 Since Go 1, the default behavior of the HTTP client is 890 to request server-side compression 891 using the <code>Accept-Encoding</code> request header 892 and then to decompress the response body transparently, 893 and this behavior is adjustable using the 894 <a href="/pkg/net/http/#Transport"><code>Transport</code></a>'s <code>DisableCompression</code> field. 895 In Go 1.7, to aid the implementation of HTTP proxies, the 896 <a href="/pkg/net/http/#Response"><code>Response</code></a>'s new 897 <code>Uncompressed</code> field reports whether 898 this transparent decompression took place. 899 </p> 900 901 <p> 902 <a href="/pkg/net/http/#DetectContentType"><code>DetectContentType</code></a> 903 adds support for a few new audio and video content types. 904 </p> 905 </dd> 906 </dl> 907 908 <dl id="net_http_cgi"><dt><a href="/pkg/net/http/cgi/">net/http/cgi</a></dt> 909 910 <dd> 911 <p> 912 The 913 <a href="/pkg/net/http/cgi/#Handler"><code>Handler</code></a> 914 adds a new field 915 <code>Stderr</code> 916 that allows redirection of the child process's 917 standard error away from the host process's 918 standard error. 919 </p> 920 </dd> 921 </dl> 922 923 <dl id="net_http_httptest"><dt><a href="/pkg/net/http/httptest/">net/http/httptest</a></dt> 924 925 <dd> 926 <p> 927 The new function 928 <a href="/pkg/net/http/httptest/#NewRequest"><code>NewRequest</code></a> 929 prepares a new 930 <a href="/pkg/net/http/#Request"><code>http.Request</code></a> 931 suitable for passing to an 932 <a href="/pkg/net/http/#Handler"><code>http.Handler</code></a> during a test. 933 </p> 934 935 <p> 936 The 937 <a href="/pkg/net/http/httptest/#ResponseRecorder"><code>ResponseRecorder</code></a>'s new 938 <a href="/pkg/net/http/httptest/#ResponseRecorder.Result"><code>Result</code></a> method 939 returns the recorded 940 <a href="/pkg/net/http/#Response"><code>http.Response</code></a>. 941 Tests that need to check the response's headers or trailers 942 should call <code>Result</code> and inspect the response fields 943 instead of accessing 944 <code>ResponseRecorder</code>'s <code>HeaderMap</code> directly. 945 </p> 946 </dd> 947 </dl> 948 949 <dl id="net_http_httputil"><dt><a href="/pkg/net/http/httputil/">net/http/httputil</a></dt> 950 951 <dd> 952 <p> 953 The 954 <a href="/pkg/net/http/httputil/#ReverseProxy"><code>ReverseProxy</code></a> implementation now responds with “502 Bad Gateway” 955 when it cannot reach a back end; in earlier releases it responded with “500 Internal Server Error.” 956 </p> 957 958 <p> 959 Both 960 <a href="/pkg/net/http/httputil/#ClientConn"><code>ClientConn</code></a> and 961 <a href="/pkg/net/http/httputil/#ServerConn"><code>ServerConn</code></a> have been documented as deprecated. 962 They are low-level, old, and unused by Go's current HTTP stack 963 and will no longer be updated. 964 Programs should use 965 <a href="/pkg/net/http/#Client"><code>http.Client</code></a>, 966 <a href="/pkg/net/http/#Transport"><code>http.Transport</code></a>, 967 and 968 <a href="/pkg/net/http/#Server"><code>http.Server</code></a> 969 instead. 970 </p> 971 </dd> 972 </dl> 973 974 <dl id="net_http_pprof"><dt><a href="/pkg/net/http/pprof/">net/http/pprof</a></dt> 975 976 <dd> 977 <p> 978 The runtime trace HTTP handler, installed to handle the path <code>/debug/pprof/trace</code>, 979 now accepts a fractional number in its <code>seconds</code> query parameter, 980 allowing collection of traces for intervals smaller than one second. 981 This is especially useful on busy servers. 982 </p> 983 </dd> 984 </dl> 985 986 <dl><dt><a href="/pkg/net/mail/">net/mail</a></dt> 987 988 <dd> 989 <p> 990 The address parser now allows unescaped UTF-8 text in addresses 991 following <a href="https://tools.ietf.org/html/rfc6532">RFC 6532</a>, 992 but it does not apply any normalization to the result. 993 For compatibility with older mail parsers, 994 the address encoder, namely 995 <a href="/pkg/net/mail/#Address"><code>Address</code></a>'s 996 <a href="/pkg/net/mail/#Address.String"><code>String</code></a> method, 997 continues to escape all UTF-8 text following <a href="https://tools.ietf.org/html/rfc5322">RFC 5322</a>. 998 </p> 999 1000 <p> 1001 The <a href="/pkg/net/mail/#ParseAddress"><code>ParseAddress</code></a> 1002 function and 1003 the <a href="/pkg/net/mail/#AddressParser.Parse"><code>AddressParser.Parse</code></a> 1004 method are stricter. 1005 They used to ignore any characters following an e-mail address, but 1006 will now return an error for anything other than whitespace. 1007 </p> 1008 </dd> 1009 </dl> 1010 1011 <dl id="net_url"><dt><a href="/pkg/net/url/">net/url</a></dt> 1012 1013 <dd> 1014 <p> 1015 The 1016 <a href="/pkg/net/url/#URL"><code>URL</code></a>'s 1017 new <code>ForceQuery</code> field 1018 records whether the URL must have a query string, 1019 in order to distinguish URLs without query strings (like <code>/search</code>) 1020 from URLs with empty query strings (like <code>/search?</code>). 1021 </p> 1022 </dd> 1023 </dl> 1024 1025 <dl id="os"><dt><a href="/pkg/os/">os</a></dt> 1026 1027 <dd> 1028 <p> 1029 <a href="/pkg/os/#IsExists"><code>IsExists</code></a> now returns true for <code>syscall.ENOTEMPTY</code>, 1030 on systems where that error exists. 1031 </p> 1032 1033 <p> 1034 On Windows, 1035 <a href="/pkg/os/#Remove"><code>Remove</code></a> now removes read-only files when possible, 1036 making the implementation behave as on 1037 non-Windows systems. 1038 </p> 1039 </dd> 1040 </dl> 1041 1042 <dl id="os_exec"><dt><a href="/pkg/os/exec/">os/exec</a></dt> 1043 1044 <dd> 1045 <p> 1046 As part of the introduction of <a href="#context">context</a>, 1047 the new constructor 1048 <a href="/pkg/os/exec/#CommandContext"><code>CommandContext</code></a> 1049 is like 1050 <a href="/pkg/os/exec/#Command"><code>Command</code></a> but includes a context that can be used to cancel the command execution. 1051 </p> 1052 </dd> 1053 </dl> 1054 1055 <dl id="os_user"><dt><a href="/pkg/os/user/">os/user</a></dt> 1056 1057 <dd> 1058 <p> 1059 The 1060 <a href="/pkg/os/user/#Current"><code>Current</code></a> 1061 function is now implemented even when cgo is not available. 1062 </p> 1063 1064 <p> 1065 The new 1066 <a href="/pkg/os/user/#Group"><code>Group</code></a> type, 1067 along with the lookup functions 1068 <a href="/pkg/os/user/#LookupGroup"><code>LookupGroup</code></a> and 1069 <a href="/pkg/os/user/#LookupGroupId"><code>LookupGroupId</code></a> 1070 and the new field <code>GroupIds</code> in the <code>User</code> struct, 1071 provides access to system-specific user group information. 1072 </p> 1073 </dd> 1074 </dl> 1075 1076 <dl id="reflect"><dt><a href="/pkg/reflect/">reflect</a></dt> 1077 1078 <dd> 1079 <p> 1080 Although 1081 <a href="/pkg/reflect/#Value"><code>Value</code></a>'s 1082 <a href="/pkg/reflect/#Value.Field"><code>Field</code></a> method has always been documented to panic 1083 if the given field number <code>i</code> is out of range, it has instead 1084 silently returned a zero 1085 <a href="/pkg/reflect/#Value"><code>Value</code></a>. 1086 Go 1.7 changes the method to behave as documented. 1087 </p> 1088 1089 <p> 1090 The new 1091 <a href="/pkg/reflect/#StructOf"><code>StructOf</code></a> 1092 function constructs a struct type at run time. 1093 It completes the set of type constructors, joining 1094 <a href="/pkg/reflect/#ArrayOf"><code>ArrayOf</code></a>, 1095 <a href="/pkg/reflect/#ChanOf"><code>ChanOf</code></a>, 1096 <a href="/pkg/reflect/#FuncOf"><code>FuncOf</code></a>, 1097 <a href="/pkg/reflect/#MapOf"><code>MapOf</code></a>, 1098 <a href="/pkg/reflect/#PtrTo"><code>PtrTo</code></a>, 1099 and 1100 <a href="/pkg/reflect/#SliceOf"><code>SliceOf</code></a>. 1101 </p> 1102 1103 <p> 1104 <a href="/pkg/reflect/#StructTag"><code>StructTag</code></a>'s 1105 new method 1106 <a href="/pkg/reflect/#StructTag.Lookup"><code>Lookup</code></a> 1107 is like 1108 <a href="/pkg/reflect/#StructTag.Get"><code>Get</code></a> 1109 but distinguishes the tag not containing the given key 1110 from the tag associating an empty string with the given key. 1111 </p> 1112 1113 <p> 1114 The 1115 <a href="/pkg/reflect/#Type.Method"><code>Method</code></a> and 1116 <a href="/pkg/reflect/#Type.NumMethod"><code>NumMethod</code></a> 1117 methods of 1118 <a href="/pkg/reflect/#Type"><code>Type</code></a> and 1119 <a href="/pkg/reflect/#Value"><code>Value</code></a> 1120 no longer return or count unexported methods. 1121 </p> 1122 </dd> 1123 </dl> 1124 1125 <dl id="strings"><dt><a href="/pkg/strings/">strings</a></dt> 1126 1127 <dd> 1128 <p> 1129 In previous releases of Go, if 1130 <a href="/pkg/strings/#Reader"><code>Reader</code></a>'s 1131 <a href="/pkg/strings/#Reader.Read"><code>Read</code></a> method 1132 were asked for zero bytes with no data remaining, it would 1133 return a count of 0 and no error. 1134 Now it returns a count of 0 and the error 1135 <a href="/pkg/io/#EOF"><code>io.EOF</code></a>. 1136 </p> 1137 1138 <p> 1139 The 1140 <a href="/pkg/strings/#Reader"><code>Reader</code></a> type has a new method 1141 <a href="/pkg/strings/#Reader.Reset"><code>Reset</code></a> to allow reuse of a <code>Reader</code>. 1142 </p> 1143 </dd> 1144 </dl> 1145 1146 <dl id="time"><dt><a href="/pkg/time/">time</a></dt> 1147 1148 <dd> 1149 <p> 1150 <a href="/pkg/time/#Duration"><code>Duration</code></a>'s 1151 time.Duration.String method now reports the zero duration as <code>"0s"</code>, not <code>"0"</code>. 1152 <a href="/pkg/time/#ParseDuration"><code>ParseDuration</code></a> continues to accept both forms. 1153 </p> 1154 1155 <p> 1156 The method call <code>time.Local.String()</code> now returns <code>"Local"</code> on all systems; 1157 in earlier releases, it returned an empty string on Windows. 1158 </p> 1159 1160 <p> 1161 The time zone database in 1162 <code>$GOROOT/lib/time</code> has been updated 1163 to IANA release 2016d. 1164 This fallback database is only used when the system time zone database 1165 cannot be found, for example on Windows. 1166 The Windows time zone abbreviation list has also been updated. 1167 </p> 1168 </dd> 1169 </dl> 1170 1171 <dl id="syscall"><dt><a href="/pkg/syscall/">syscall</a></dt> 1172 1173 <dd> 1174 <p> 1175 On Linux, the 1176 <a href="/pkg/syscall/#SysProcAttr"><code>SysProcAttr</code></a> struct 1177 (as used in 1178 <a href="/pkg/os/exec/#Cmd"><code>os/exec.Cmd</code></a>'s <code>SysProcAttr</code> field) 1179 has a new <code>Unshareflags</code> field. 1180 If the field is nonzero, the child process created by 1181 <a href="/pkg/syscall/#ForkExec"><code>ForkExec</code></a> 1182 (as used in <code>exec.Cmd</code>'s <code>Run</code> method) 1183 will call the 1184 <a href="http://man7.org/linux/man-pages/man2/unshare.2.html"><i>unshare</i>(2)</a> 1185 system call before executing the new program. 1186 </p> 1187 </dd> 1188 </dl>