1 <!--{ 2 "Title": "Go 1.1 Release Notes", 3 "Path": "/doc/go1.1", 4 "Template": true 5 }--> 6 7 <h2 id="introduction">Introduction to Go 1.1</h2> 8 9 <p> 10 The release of <a href="/doc/go1.html">Go version 1</a> (Go 1 or Go 1.0 for short) 11 in March of 2012 introduced a new period 12 of stability in the Go language and libraries. 13 That stability has helped nourish a growing community of Go users 14 and systems around the world. 15 Several "point" releases since 16 then1.0.1, 1.0.2, and 1.0.3have been issued. 17 These point releases fixed known bugs but made 18 no non-critical changes to the implementation. 19 </p> 20 21 <p> 22 This new release, Go 1.1, keeps the <a href="/doc/go1compat.html">promise 23 of compatibility</a> but adds a couple of significant 24 (backwards-compatible, of course) language changes, has a long list 25 of (again, compatible) library changes, and 26 includes major work on the implementation of the compilers, 27 libraries, and run-time. 28 The focus is on performance. 29 Benchmarking is an inexact science at best, but we see significant, 30 sometimes dramatic speedups for many of our test programs. 31 We trust that many of our users' programs will also see improvements 32 just by updating their Go installation and recompiling. 33 </p> 34 35 <p> 36 This document summarizes the changes between Go 1 and Go 1.1. 37 Very little if any code will need modification to run with Go 1.1, 38 although a couple of rare error cases surface with this release 39 and need to be addressed if they arise. 40 Details appear below; see the discussion of 41 <a href="#int">64-bit ints</a> and <a href="#unicode_literals">Unicode literals</a> 42 in particular. 43 </p> 44 45 <h2 id="language">Changes to the language</h2> 46 47 <p> 48 <a href="/doc/go1compat.html">The Go compatibility document</a> promises 49 that programs written to the Go 1 language specification will continue to operate, 50 and those promises are maintained. 51 In the interest of firming up the specification, though, there are 52 details about some error cases that have been clarified. 53 There are also some new language features. 54 </p> 55 56 <h3 id="divzero">Integer division by zero</h3> 57 58 <p> 59 In Go 1, integer division by a constant zero produced a run-time panic: 60 </p> 61 62 <pre> 63 func f(x int) int { 64 return x/0 65 } 66 </pre> 67 68 <p> 69 In Go 1.1, an integer division by constant zero is not a legal program, so it is a compile-time error. 70 </p> 71 72 <h3 id="unicode_literals">Surrogates in Unicode literals</h3> 73 74 <p> 75 The definition of string and rune literals has been refined to exclude surrogate halves from the 76 set of valid Unicode code points. 77 See the <a href="#unicode">Unicode</a> section for more information. 78 </p> 79 80 <h3 id="method_values">Method values</h3> 81 82 <p> 83 Go 1.1 now implements 84 <a href="/ref/spec#Method_values">method values</a>, 85 which are functions that have been bound to a specific receiver value. 86 For instance, given a 87 <a href="/pkg/bufio/#Writer"><code>Writer</code></a> 88 value <code>w</code>, 89 the expression 90 <code>w.Write</code>, 91 a method value, is a function that will always write to <code>w</code>; it is equivalent to 92 a function literal closing over <code>w</code>: 93 </p> 94 95 <pre> 96 func (p []byte) (n int, err error) { 97 return w.Write(p) 98 } 99 </pre> 100 101 <p> 102 Method values are distinct from method expressions, which generate functions 103 from methods of a given type; the method expression <code>(*bufio.Writer).Write</code> 104 is equivalent to a function with an extra first argument, a receiver of type 105 <code>(*bufio.Writer)</code>: 106 </p> 107 108 <pre> 109 func (w *bufio.Writer, p []byte) (n int, err error) { 110 return w.Write(p) 111 } 112 </pre> 113 114 <p> 115 <em>Updating</em>: No existing code is affected; the change is strictly backward-compatible. 116 </p> 117 118 <h3 id="return">Return requirements</h3> 119 120 <p> 121 Before Go 1.1, a function that returned a value needed an explicit "return" 122 or call to <code>panic</code> at 123 the end of the function; this was a simple way to make the programmer 124 be explicit about the meaning of the function. But there are many cases 125 where a final "return" is clearly unnecessary, such as a function with 126 only an infinite "for" loop. 127 </p> 128 129 <p> 130 In Go 1.1, the rule about final "return" statements is more permissive. 131 It introduces the concept of a 132 <a href="/ref/spec#Terminating_statements"><em>terminating statement</em></a>, 133 a statement that is guaranteed to be the last one a function executes. 134 Examples include 135 "for" loops with no condition and "if-else" 136 statements in which each half ends in a "return". 137 If the final statement of a function can be shown <em>syntactically</em> to 138 be a terminating statement, no final "return" statement is needed. 139 </p> 140 141 <p> 142 Note that the rule is purely syntactic: it pays no attention to the values in the 143 code and therefore requires no complex analysis. 144 </p> 145 146 <p> 147 <em>Updating</em>: The change is backward-compatible, but existing code 148 with superfluous "return" statements and calls to <code>panic</code> may 149 be simplified manually. 150 Such code can be identified by <code>go vet</code>. 151 </p> 152 153 <h2 id="impl">Changes to the implementations and tools</h2> 154 155 <h3 id="gccgo">Status of gccgo</h3> 156 157 <p> 158 The GCC release schedule does not coincide with the Go release schedule, so some skew is inevitable in 159 <code>gccgo</code>'s releases. 160 The 4.8.0 version of GCC shipped in March, 2013 and includes a nearly-Go 1.1 version of <code>gccgo</code>. 161 Its library is a little behind the release, but the biggest difference is that method values are not implemented. 162 Sometime around July 2013, we expect 4.8.2 of GCC to ship with a <code>gccgo</code> 163 providing a complete Go 1.1 implementation. 164 </p> 165 166 <h3 id="gc_flag">Command-line flag parsing</h3> 167 168 <p> 169 In the gc tool chain, the compilers and linkers now use the 170 same command-line flag parsing rules as the Go flag package, a departure 171 from the traditional Unix flag parsing. This may affect scripts that invoke 172 the tool directly. 173 For example, 174 <code>go tool 6c -Fw -Dfoo</code> must now be written 175 <code>go tool 6c -F -w -D foo</code>. 176 </p> 177 178 <h3 id="int">Size of int on 64-bit platforms</h3> 179 180 <p> 181 The language allows the implementation to choose whether the <code>int</code> type and 182 <code>uint</code> types are 32 or 64 bits. Previous Go implementations made <code>int</code> 183 and <code>uint</code> 32 bits on all systems. Both the gc and gccgo implementations 184 now make 185 <code>int</code> and <code>uint</code> 64 bits on 64-bit platforms such as AMD64/x86-64. 186 Among other things, this enables the allocation of slices with 187 more than 2 billion elements on 64-bit platforms. 188 </p> 189 190 <p> 191 <em>Updating</em>: 192 Most programs will be unaffected by this change. 193 Because Go does not allow implicit conversions between distinct 194 <a href="/ref/spec#Numeric_types">numeric types</a>, 195 no programs will stop compiling due to this change. 196 However, programs that contain implicit assumptions 197 that <code>int</code> is only 32 bits may change behavior. 198 For example, this code prints a positive number on 64-bit systems and 199 a negative one on 32-bit systems: 200 </p> 201 202 <pre> 203 x := ^uint32(0) // x is 0xffffffff 204 i := int(x) // i is -1 on 32-bit systems, 0xffffffff on 64-bit 205 fmt.Println(i) 206 </pre> 207 208 <p>Portable code intending 32-bit sign extension (yielding <code>-1</code> on all systems) 209 would instead say: 210 </p> 211 212 <pre> 213 i := int(int32(x)) 214 </pre> 215 216 <h3 id="heap">Heap size on 64-bit architectures</h3> 217 218 <p> 219 On 64-bit architectures, the maximum heap size has been enlarged substantially, 220 from a few gigabytes to several tens of gigabytes. 221 (The exact details depend on the system and may change.) 222 </p> 223 224 <p> 225 On 32-bit architectures, the heap size has not changed. 226 </p> 227 228 <p> 229 <em>Updating</em>: 230 This change should have no effect on existing programs beyond allowing them 231 to run with larger heaps. 232 </p> 233 234 <h3 id="unicode">Unicode</h3> 235 236 <p> 237 To make it possible to represent code points greater than 65535 in UTF-16, 238 Unicode defines <em>surrogate halves</em>, 239 a range of code points to be used only in the assembly of large values, and only in UTF-16. 240 The code points in that surrogate range are illegal for any other purpose. 241 In Go 1.1, this constraint is honored by the compiler, libraries, and run-time: 242 a surrogate half is illegal as a rune value, when encoded as UTF-8, or when 243 encoded in isolation as UTF-16. 244 When encountered, for example in converting from a rune to UTF-8, it is 245 treated as an encoding error and will yield the replacement rune, 246 <a href="/pkg/unicode/utf8/#RuneError"><code>utf8.RuneError</code></a>, 247 U+FFFD. 248 </p> 249 250 <p> 251 This program, 252 </p> 253 254 <pre> 255 import "fmt" 256 257 func main() { 258 fmt.Printf("%+q\n", string(0xD800)) 259 } 260 </pre> 261 262 <p> 263 printed <code>"\ud800"</code> in Go 1.0, but prints <code>"\ufffd"</code> in Go 1.1. 264 </p> 265 266 <p> 267 Surrogate-half Unicode values are now illegal in rune and string constants, so constants such as 268 <code>'\ud800'</code> and <code>"\ud800"</code> are now rejected by the compilers. 269 When written explicitly as UTF-8 encoded bytes, 270 such strings can still be created, as in <code>"\xed\xa0\x80"</code>. 271 However, when such a string is decoded as a sequence of runes, as in a range loop, it will yield only <code>utf8.RuneError</code> 272 values. 273 </p> 274 275 <p> 276 The Unicode byte order mark U+FEFF, encoded in UTF-8, is now permitted as the first 277 character of a Go source file. 278 Even though its appearance in the byte-order-free UTF-8 encoding is clearly unnecessary, 279 some editors add the mark as a kind of "magic number" identifying a UTF-8 encoded file. 280 </p> 281 282 <p> 283 <em>Updating</em>: 284 Most programs will be unaffected by the surrogate change. 285 Programs that depend on the old behavior should be modified to avoid the issue. 286 The byte-order-mark change is strictly backward-compatible. 287 </p> 288 289 <h3 id="race">Race detector</h3> 290 291 <p> 292 A major addition to the tools is a <em>race detector</em>, a way to 293 find bugs in programs caused by concurrent access of the same 294 variable, where at least one of the accesses is a write. 295 This new facility is built into the <code>go</code> tool. 296 For now, it is only available on Linux, Mac OS X, and Windows systems with 297 64-bit x86 processors. 298 To enable it, set the <code>-race</code> flag when building or testing your program 299 (for instance, <code>go test -race</code>). 300 The race detector is documented in <a href="/doc/articles/race_detector.html">a separate article</a>. 301 </p> 302 303 <h3 id="gc_asm">The gc assemblers</h3> 304 305 <p> 306 Due to the change of the <a href="#int"><code>int</code></a> to 64 bits and 307 a new internal <a href="//golang.org/s/go11func">representation of functions</a>, 308 the arrangement of function arguments on the stack has changed in the gc tool chain. 309 Functions written in assembly will need to be revised at least 310 to adjust frame pointer offsets. 311 </p> 312 313 <p> 314 <em>Updating</em>: 315 The <code>go vet</code> command now checks that functions implemented in assembly 316 match the Go function prototypes they implement. 317 </p> 318 319 <h3 id="gocmd">Changes to the go command</h3> 320 321 <p> 322 The <a href="/cmd/go/"><code>go</code></a> command has acquired several 323 changes intended to improve the experience for new Go users. 324 </p> 325 326 <p> 327 First, when compiling, testing, or running Go code, the <code>go</code> command will now give more detailed error messages, 328 including a list of paths searched, when a package cannot be located. 329 </p> 330 331 <pre> 332 $ go build foo/quxx 333 can't load package: package foo/quxx: cannot find package "foo/quxx" in any of: 334 /home/you/go/src/pkg/foo/quxx (from $GOROOT) 335 /home/you/src/foo/quxx (from $GOPATH) 336 </pre> 337 338 <p> 339 Second, the <code>go get</code> command no longer allows <code>$GOROOT</code> 340 as the default destination when downloading package source. 341 To use the <code>go get</code> 342 command, a <a href="/doc/code.html#GOPATH">valid <code>$GOPATH</code></a> is now required. 343 </p> 344 345 <pre> 346 $ GOPATH= go get code.google.com/p/foo/quxx 347 package code.google.com/p/foo/quxx: cannot download, $GOPATH not set. For more details see: go help gopath 348 </pre> 349 350 <p> 351 Finally, as a result of the previous change, the <code>go get</code> command will also fail 352 when <code>$GOPATH</code> and <code>$GOROOT</code> are set to the same value. 353 </p> 354 355 <pre> 356 $ GOPATH=$GOROOT go get code.google.com/p/foo/quxx 357 warning: GOPATH set to GOROOT (/home/you/go) has no effect 358 package code.google.com/p/foo/quxx: cannot download, $GOPATH must not be set to $GOROOT. For more details see: go help gopath 359 </pre> 360 361 <h3 id="gotest">Changes to the go test command</h3> 362 363 <p> 364 The <a href="/cmd/go/#hdr-Test_packages"><code>go test</code></a> 365 command no longer deletes the binary when run with profiling enabled, 366 to make it easier to analyze the profile. 367 The implementation sets the <code>-c</code> flag automatically, so after running, 368 </p> 369 370 <pre> 371 $ go test -cpuprofile cpuprof.out mypackage 372 </pre> 373 374 <p> 375 the file <code>mypackage.test</code> will be left in the directory where <code>go test</code> was run. 376 </p> 377 378 <p> 379 The <a href="/cmd/go/#hdr-Test_packages"><code>go test</code></a> 380 command can now generate profiling information 381 that reports where goroutines are blocked, that is, 382 where they tend to stall waiting for an event such as a channel communication. 383 The information is presented as a 384 <em>blocking profile</em> 385 enabled with the 386 <code>-blockprofile</code> 387 option of 388 <code>go test</code>. 389 Run <code>go help test</code> for more information. 390 </p> 391 392 <h3 id="gofix">Changes to the go fix command</h3> 393 394 <p> 395 The <a href="/cmd/fix/"><code>fix</code></a> command, usually run as 396 <code>go fix</code>, no longer applies fixes to update code from 397 before Go 1 to use Go 1 APIs. 398 To update pre-Go 1 code to Go 1.1, use a Go 1.0 tool chain 399 to convert the code to Go 1.0 first. 400 </p> 401 402 <h3 id="tags">Build constraints</h3> 403 404 <p> 405 The "<code>go1.1</code>" tag has been added to the list of default 406 <a href="/pkg/go/build/#hdr-Build_Constraints">build constraints</a>. 407 This permits packages to take advantage of the new features in Go 1.1 while 408 remaining compatible with earlier versions of Go. 409 </p> 410 411 <p> 412 To build a file only with Go 1.1 and above, add this build constraint: 413 </p> 414 415 <pre> 416 // +build go1.1 417 </pre> 418 419 <p> 420 To build a file only with Go 1.0.x, use the converse constraint: 421 </p> 422 423 <pre> 424 // +build !go1.1 425 </pre> 426 427 <h3 id="platforms">Additional platforms</h3> 428 429 <p> 430 The Go 1.1 tool chain adds experimental support for <code>freebsd/arm</code>, 431 <code>netbsd/386</code>, <code>netbsd/amd64</code>, <code>netbsd/arm</code>, 432 <code>openbsd/386</code> and <code>openbsd/amd64</code> platforms. 433 </p> 434 435 <p> 436 An ARMv6 or later processor is required for <code>freebsd/arm</code> or 437 <code>netbsd/arm</code>. 438 </p> 439 440 <p> 441 Go 1.1 adds experimental support for <code>cgo</code> on <code>linux/arm</code>. 442 </p> 443 444 <h3 id="crosscompile">Cross compilation</h3> 445 446 <p> 447 When cross-compiling, the <code>go</code> tool will disable <code>cgo</code> 448 support by default. 449 </p> 450 451 <p> 452 To explicitly enable <code>cgo</code>, set <code>CGO_ENABLED=1</code>. 453 </p> 454 455 <h2 id="performance">Performance</h2> 456 457 <p> 458 The performance of code compiled with the Go 1.1 gc tool suite should be noticeably 459 better for most Go programs. 460 Typical improvements relative to Go 1.0 seem to be about 30%-40%, sometimes 461 much more, but occasionally less or even non-existent. 462 There are too many small performance-driven tweaks through the tools and libraries 463 to list them all here, but the following major changes are worth noting: 464 </p> 465 466 <ul> 467 <li>The gc compilers generate better code in many cases, most noticeably for 468 floating point on the 32-bit Intel architecture.</li> 469 <li>The gc compilers do more in-lining, including for some operations 470 in the run-time such as <a href="/pkg/builtin/#append"><code>append</code></a> 471 and interface conversions.</li> 472 <li>There is a new implementation of Go maps with significant reduction in 473 memory footprint and CPU time.</li> 474 <li>The garbage collector has been made more parallel, which can reduce 475 latencies for programs running on multiple CPUs.</li> 476 <li>The garbage collector is also more precise, which costs a small amount of 477 CPU time but can reduce the size of the heap significantly, especially 478 on 32-bit architectures.</li> 479 <li>Due to tighter coupling of the run-time and network libraries, fewer 480 context switches are required on network operations.</li> 481 </ul> 482 483 <h2 id="library">Changes to the standard library</h2> 484 485 <h3 id="bufio_scanner">bufio.Scanner</h3> 486 487 <p> 488 The various routines to scan textual input in the 489 <a href="/pkg/bufio/"><code>bufio</code></a> 490 package, 491 <a href="/pkg/bufio/#Reader.ReadBytes"><code>ReadBytes</code></a>, 492 <a href="/pkg/bufio/#Reader.ReadString"><code>ReadString</code></a> 493 and particularly 494 <a href="/pkg/bufio/#Reader.ReadLine"><code>ReadLine</code></a>, 495 are needlessly complex to use for simple purposes. 496 In Go 1.1, a new type, 497 <a href="/pkg/bufio/#Scanner"><code>Scanner</code></a>, 498 has been added to make it easier to do simple tasks such as 499 read the input as a sequence of lines or space-delimited words. 500 It simplifies the problem by terminating the scan on problematic 501 input such as pathologically long lines, and having a simple 502 default: line-oriented input, with each line stripped of its terminator. 503 Here is code to reproduce the input a line at a time: 504 </p> 505 506 <pre> 507 scanner := bufio.NewScanner(os.Stdin) 508 for scanner.Scan() { 509 fmt.Println(scanner.Text()) // Println will add back the final '\n' 510 } 511 if err := scanner.Err(); err != nil { 512 fmt.Fprintln(os.Stderr, "reading standard input:", err) 513 } 514 </pre> 515 516 <p> 517 Scanning behavior can be adjusted through a function to control subdividing the input 518 (see the documentation for <a href="/pkg/bufio/#SplitFunc"><code>SplitFunc</code></a>), 519 but for tough problems or the need to continue past errors, the older interface 520 may still be required. 521 </p> 522 523 <h3 id="net">net</h3> 524 525 <p> 526 The protocol-specific resolvers in the <a href="/pkg/net/"><code>net</code></a> package were formerly 527 lax about the network name passed in. 528 Although the documentation was clear 529 that the only valid networks for 530 <a href="/pkg/net/#ResolveTCPAddr"><code>ResolveTCPAddr</code></a> 531 are <code>"tcp"</code>, 532 <code>"tcp4"</code>, and <code>"tcp6"</code>, the Go 1.0 implementation silently accepted any string. 533 The Go 1.1 implementation returns an error if the network is not one of those strings. 534 The same is true of the other protocol-specific resolvers <a href="/pkg/net/#ResolveIPAddr"><code>ResolveIPAddr</code></a>, 535 <a href="/pkg/net/#ResolveUDPAddr"><code>ResolveUDPAddr</code></a>, and 536 <a href="/pkg/net/#ResolveUnixAddr"><code>ResolveUnixAddr</code></a>. 537 </p> 538 539 <p> 540 The previous implementation of 541 <a href="/pkg/net/#ListenUnixgram"><code>ListenUnixgram</code></a> 542 returned a 543 <a href="/pkg/net/#UDPConn"><code>UDPConn</code></a> as 544 a representation of the connection endpoint. 545 The Go 1.1 implementation instead returns a 546 <a href="/pkg/net/#UnixConn"><code>UnixConn</code></a> 547 to allow reading and writing 548 with its 549 <a href="/pkg/net/#UnixConn.ReadFrom"><code>ReadFrom</code></a> 550 and 551 <a href="/pkg/net/#UnixConn.WriteTo"><code>WriteTo</code></a> 552 methods. 553 </p> 554 555 <p> 556 The data structures 557 <a href="/pkg/net/#IPAddr"><code>IPAddr</code></a>, 558 <a href="/pkg/net/#TCPAddr"><code>TCPAddr</code></a>, and 559 <a href="/pkg/net/#UDPAddr"><code>UDPAddr</code></a> 560 add a new string field called <code>Zone</code>. 561 Code using untagged composite literals (e.g. <code>net.TCPAddr{ip, port}</code>) 562 instead of tagged literals (<code>net.TCPAddr{IP: ip, Port: port}</code>) 563 will break due to the new field. 564 The Go 1 compatibility rules allow this change: client code must use tagged literals to avoid such breakages. 565 </p> 566 567 <p> 568 <em>Updating</em>: 569 To correct breakage caused by the new struct field, 570 <code>go fix</code> will rewrite code to add tags for these types. 571 More generally, <code>go vet</code> will identify composite literals that 572 should be revised to use field tags. 573 </p> 574 575 <h3 id="reflect">reflect</h3> 576 577 <p> 578 The <a href="/pkg/reflect/"><code>reflect</code></a> package has several significant additions. 579 </p> 580 581 <p> 582 It is now possible to run a "select" statement using 583 the <code>reflect</code> package; see the description of 584 <a href="/pkg/reflect/#Select"><code>Select</code></a> 585 and 586 <a href="/pkg/reflect/#SelectCase"><code>SelectCase</code></a> 587 for details. 588 </p> 589 590 <p> 591 The new method 592 <a href="/pkg/reflect/#Value.Convert"><code>Value.Convert</code></a> 593 (or 594 <a href="/pkg/reflect/#Type"><code>Type.ConvertibleTo</code></a>) 595 provides functionality to execute a Go conversion or type assertion operation 596 on a 597 <a href="/pkg/reflect/#Value"><code>Value</code></a> 598 (or test for its possibility). 599 </p> 600 601 <p> 602 The new function 603 <a href="/pkg/reflect/#MakeFunc"><code>MakeFunc</code></a> 604 creates a wrapper function to make it easier to call a function with existing 605 <a href="/pkg/reflect/#Value"><code>Values</code></a>, 606 doing the standard Go conversions among the arguments, for instance 607 to pass an actual <code>int</code> to a formal <code>interface{}</code>. 608 </p> 609 610 <p> 611 Finally, the new functions 612 <a href="/pkg/reflect/#ChanOf"><code>ChanOf</code></a>, 613 <a href="/pkg/reflect/#MapOf"><code>MapOf</code></a> 614 and 615 <a href="/pkg/reflect/#SliceOf"><code>SliceOf</code></a> 616 construct new 617 <a href="/pkg/reflect/#Type"><code>Types</code></a> 618 from existing types, for example to construct the type <code>[]T</code> given 619 only <code>T</code>. 620 </p> 621 622 623 <h3 id="time">time</h3> 624 <p> 625 On FreeBSD, Linux, NetBSD, OS X and OpenBSD, previous versions of the 626 <a href="/pkg/time/"><code>time</code></a> package 627 returned times with microsecond precision. 628 The Go 1.1 implementation on these 629 systems now returns times with nanosecond precision. 630 Programs that write to an external format with microsecond precision 631 and read it back, expecting to recover the original value, will be affected 632 by the loss of precision. 633 There are two new methods of <a href="/pkg/time/#Time"><code>Time</code></a>, 634 <a href="/pkg/time/#Time.Round"><code>Round</code></a> 635 and 636 <a href="/pkg/time/#Time.Truncate"><code>Truncate</code></a>, 637 that can be used to remove precision from a time before passing it to 638 external storage. 639 </p> 640 641 <p> 642 The new method 643 <a href="/pkg/time/#Time.YearDay"><code>YearDay</code></a> 644 returns the one-indexed integral day number of the year specified by the time value. 645 </p> 646 647 <p> 648 The 649 <a href="/pkg/time/#Timer"><code>Timer</code></a> 650 type has a new method 651 <a href="/pkg/time/#Timer.Reset"><code>Reset</code></a> 652 that modifies the timer to expire after a specified duration. 653 </p> 654 655 <p> 656 Finally, the new function 657 <a href="/pkg/time/#ParseInLocation"><code>ParseInLocation</code></a> 658 is like the existing 659 <a href="/pkg/time/#Parse"><code>Parse</code></a> 660 but parses the time in the context of a location (time zone), ignoring 661 time zone information in the parsed string. 662 This function addresses a common source of confusion in the time API. 663 </p> 664 665 <p> 666 <em>Updating</em>: 667 Code that needs to read and write times using an external format with 668 lower precision should be modified to use the new methods. 669 </p> 670 671 <h3 id="exp_old">Exp and old subtrees moved to go.exp and go.text subrepositories</h3> 672 673 <p> 674 To make it easier for binary distributions to access them if desired, the <code>exp</code> 675 and <code>old</code> source subtrees, which are not included in binary distributions, 676 have been moved to the new <code>go.exp</code> subrepository at 677 <code>code.google.com/p/go.exp</code>. To access the <code>ssa</code> package, 678 for example, run 679 </p> 680 681 <pre> 682 $ go get code.google.com/p/go.exp/ssa 683 </pre> 684 685 <p> 686 and then in Go source, 687 </p> 688 689 <pre> 690 import "code.google.com/p/go.exp/ssa" 691 </pre> 692 693 <p> 694 The old package <code>exp/norm</code> has also been moved, but to a new repository 695 <code>go.text</code>, where the Unicode APIs and other text-related packages will 696 be developed. 697 </p> 698 699 <h3 id="new_packages">New packages</h3> 700 701 <p> 702 There are three new packages. 703 </p> 704 705 <ul> 706 <li> 707 The <a href="/pkg/go/format/"><code>go/format</code></a> package provides 708 a convenient way for a program to access the formatting capabilities of the 709 <a href="/cmd/go/#hdr-Run_gofmt_on_package_sources"><code>go fmt</code></a> command. 710 It has two functions, 711 <a href="/pkg/go/format/#Node"><code>Node</code></a> to format a Go parser 712 <a href="/pkg/go/ast/#Node"><code>Node</code></a>, 713 and 714 <a href="/pkg/go/format/#Source"><code>Source</code></a> 715 to reformat arbitrary Go source code into the standard format as provided by the 716 <a href="/cmd/go/#hdr-Run_gofmt_on_package_sources"><code>go fmt</code></a> command. 717 </li> 718 719 <li> 720 The <a href="/pkg/net/http/cookiejar/"><code>net/http/cookiejar</code></a> package provides the basics for managing HTTP cookies. 721 </li> 722 723 <li> 724 The <a href="/pkg/runtime/race/"><code>runtime/race</code></a> package provides low-level facilities for data race detection. 725 It is internal to the race detector and does not otherwise export any user-visible functionality. 726 </li> 727 </ul> 728 729 <h3 id="minor_library_changes">Minor changes to the library</h3> 730 731 <p> 732 The following list summarizes a number of minor changes to the library, mostly additions. 733 See the relevant package documentation for more information about each change. 734 </p> 735 736 <ul> 737 <li> 738 The <a href="/pkg/bytes/"><code>bytes</code></a> package has two new functions, 739 <a href="/pkg/bytes/#TrimPrefix"><code>TrimPrefix</code></a> 740 and 741 <a href="/pkg/bytes/#TrimSuffix"><code>TrimSuffix</code></a>, 742 with self-evident properties. 743 Also, the <a href="/pkg/bytes/#Buffer"><code>Buffer</code></a> type 744 has a new method 745 <a href="/pkg/bytes/#Buffer.Grow"><code>Grow</code></a> that 746 provides some control over memory allocation inside the buffer. 747 Finally, the 748 <a href="/pkg/bytes/#Reader"><code>Reader</code></a> type now has a 749 <a href="/pkg/strings/#Reader.WriteTo"><code>WriteTo</code></a> method 750 so it implements the 751 <a href="/pkg/io/#WriterTo"><code>io.WriterTo</code></a> interface. 752 </li> 753 754 <li> 755 The <a href="/pkg/compress/gzip/"><code>compress/gzip</code></a> package has 756 a new <a href="/pkg/compress/gzip/#Writer.Flush"><code>Flush</code></a> 757 method for its 758 <a href="/pkg/compress/gzip/#Writer"><code>Writer</code></a> 759 type that flushes its underlying <code>flate.Writer</code>. 760 </li> 761 762 <li> 763 The <a href="/pkg/crypto/hmac/"><code>crypto/hmac</code></a> package has a new function, 764 <a href="/pkg/crypto/hmac/#Equal"><code>Equal</code></a>, to compare two MACs. 765 </li> 766 767 <li> 768 The <a href="/pkg/crypto/x509/"><code>crypto/x509</code></a> package 769 now supports PEM blocks (see 770 <a href="/pkg/crypto/x509/#DecryptPEMBlock"><code>DecryptPEMBlock</code></a> for instance), 771 and a new function 772 <a href="/pkg/crypto/x509/#ParseECPrivateKey"><code>ParseECPrivateKey</code></a> to parse elliptic curve private keys. 773 </li> 774 775 <li> 776 The <a href="/pkg/database/sql/"><code>database/sql</code></a> package 777 has a new 778 <a href="/pkg/database/sql/#DB.Ping"><code>Ping</code></a> 779 method for its 780 <a href="/pkg/database/sql/#DB"><code>DB</code></a> 781 type that tests the health of the connection. 782 </li> 783 784 <li> 785 The <a href="/pkg/database/sql/driver/"><code>database/sql/driver</code></a> package 786 has a new 787 <a href="/pkg/database/sql/driver/#Queryer"><code>Queryer</code></a> 788 interface that a 789 <a href="/pkg/database/sql/driver/#Conn"><code>Conn</code></a> 790 may implement to improve performance. 791 </li> 792 793 <li> 794 The <a href="/pkg/encoding/json/"><code>encoding/json</code></a> package's 795 <a href="/pkg/encoding/json/#Decoder"><code>Decoder</code></a> 796 has a new method 797 <a href="/pkg/encoding/json/#Decoder.Buffered"><code>Buffered</code></a> 798 to provide access to the remaining data in its buffer, 799 as well as a new method 800 <a href="/pkg/encoding/json/#Decoder.UseNumber"><code>UseNumber</code></a> 801 to unmarshal a value into the new type 802 <a href="/pkg/encoding/json/#Number"><code>Number</code></a>, 803 a string, rather than a float64. 804 </li> 805 806 <li> 807 The <a href="/pkg/encoding/xml/"><code>encoding/xml</code></a> package 808 has a new function, 809 <a href="/pkg/encoding/xml/#EscapeText"><code>EscapeText</code></a>, 810 which writes escaped XML output, 811 and a method on 812 <a href="/pkg/encoding/xml/#Encoder"><code>Encoder</code></a>, 813 <a href="/pkg/encoding/xml/#Encoder.Indent"><code>Indent</code></a>, 814 to specify indented output. 815 </li> 816 817 <li> 818 In the <a href="/pkg/go/ast/"><code>go/ast</code></a> package, a 819 new type <a href="/pkg/go/ast/#CommentMap"><code>CommentMap</code></a> 820 and associated methods makes it easier to extract and process comments in Go programs. 821 </li> 822 823 <li> 824 In the <a href="/pkg/go/doc/"><code>go/doc</code></a> package, 825 the parser now keeps better track of stylized annotations such as <code>TODO(joe)</code> 826 throughout the code, 827 information that the <a href="/cmd/godoc/"><code>godoc</code></a> 828 command can filter or present according to the value of the <code>-notes</code> flag. 829 </li> 830 831 <li> 832 The undocumented and only partially implemented "noescape" feature of the 833 <a href="/pkg/html/template/"><code>html/template</code></a> 834 package has been removed; programs that depend on it will break. 835 </li> 836 837 <li> 838 The <a href="/pkg/image/jpeg/"><code>image/jpeg</code></a> package now 839 reads progressive JPEG files and handles a few more subsampling configurations. 840 </li> 841 842 <li> 843 The <a href="/pkg/io/"><code>io</code></a> package now exports the 844 <a href="/pkg/io/#ByteWriter"><code>io.ByteWriter</code></a> interface to capture the common 845 functionality of writing a byte at a time. 846 It also exports a new error, <a href="/pkg/io/#ErrNoProgress"><code>ErrNoProgress</code></a>, 847 used to indicate a <code>Read</code> implementation is looping without delivering data. 848 </li> 849 850 <li> 851 The <a href="/pkg/log/syslog/"><code>log/syslog</code></a> package now provides better support 852 for OS-specific logging features. 853 </li> 854 855 <li> 856 The <a href="/pkg/math/big/"><code>math/big</code></a> package's 857 <a href="/pkg/math/big/#Int"><code>Int</code></a> type 858 now has methods 859 <a href="/pkg/math/big/#Int.MarshalJSON"><code>MarshalJSON</code></a> 860 and 861 <a href="/pkg/math/big/#Int.UnmarshalJSON"><code>UnmarshalJSON</code></a> 862 to convert to and from a JSON representation. 863 Also, 864 <a href="/pkg/math/big/#Int"><code>Int</code></a> 865 can now convert directly to and from a <code>uint64</code> using 866 <a href="/pkg/math/big/#Int.Uint64"><code>Uint64</code></a> 867 and 868 <a href="/pkg/math/big/#Int.SetUint64"><code>SetUint64</code></a>, 869 while 870 <a href="/pkg/math/big/#Rat"><code>Rat</code></a> 871 can do the same with <code>float64</code> using 872 <a href="/pkg/math/big/#Rat.Float64"><code>Float64</code></a> 873 and 874 <a href="/pkg/math/big/#Rat.SetFloat64"><code>SetFloat64</code></a>. 875 </li> 876 877 <li> 878 The <a href="/pkg/mime/multipart/"><code>mime/multipart</code></a> package 879 has a new method for its 880 <a href="/pkg/mime/multipart/#Writer"><code>Writer</code></a>, 881 <a href="/pkg/mime/multipart/#Writer.SetBoundary"><code>SetBoundary</code></a>, 882 to define the boundary separator used to package the output. 883 The <a href="/pkg/mime/multipart/#Reader"><code>Reader</code></a> also now 884 transparently decodes any <code>quoted-printable</code> parts and removes 885 the <code>Content-Transfer-Encoding</code> header when doing so. 886 </li> 887 888 <li> 889 The 890 <a href="/pkg/net/"><code>net</code></a> package's 891 <a href="/pkg/net/#ListenUnixgram"><code>ListenUnixgram</code></a> 892 function has changed return types: it now returns a 893 <a href="/pkg/net/#UnixConn"><code>UnixConn</code></a> 894 rather than a 895 <a href="/pkg/net/#UDPConn"><code>UDPConn</code></a>, which was 896 clearly a mistake in Go 1.0. 897 Since this API change fixes a bug, it is permitted by the Go 1 compatibility rules. 898 </li> 899 900 <li> 901 The <a href="/pkg/net/"><code>net</code></a> package includes a new type, 902 <a href="/pkg/net/#Dialer"><code>Dialer</code></a>, to supply options to 903 <a href="/pkg/net/#Dialer.Dial"><code>Dial</code></a>. 904 </li> 905 906 <li> 907 The <a href="/pkg/net/"><code>net</code></a> package adds support for 908 link-local IPv6 addresses with zone qualifiers, such as <code>fe80::1%lo0</code>. 909 The address structures <a href="/pkg/net/#IPAddr"><code>IPAddr</code></a>, 910 <a href="/pkg/net/#UDPAddr"><code>UDPAddr</code></a>, and 911 <a href="/pkg/net/#TCPAddr"><code>TCPAddr</code></a> 912 record the zone in a new field, and functions that expect string forms of these addresses, such as 913 <a href="/pkg/net/#Dial"><code>Dial</code></a>, 914 <a href="/pkg/net/#ResolveIPAddr"><code>ResolveIPAddr</code></a>, 915 <a href="/pkg/net/#ResolveUDPAddr"><code>ResolveUDPAddr</code></a>, and 916 <a href="/pkg/net/#ResolveTCPAddr"><code>ResolveTCPAddr</code></a>, 917 now accept the zone-qualified form. 918 </li> 919 920 <li> 921 The <a href="/pkg/net/"><code>net</code></a> package adds 922 <a href="/pkg/net/#LookupNS"><code>LookupNS</code></a> to its suite of resolving functions. 923 <code>LookupNS</code> returns the <a href="/pkg/net/#NS">NS records</a> for a host name. 924 </li> 925 926 <li> 927 The <a href="/pkg/net/"><code>net</code></a> package adds protocol-specific 928 packet reading and writing methods to 929 <a href="/pkg/net/#IPConn"><code>IPConn</code></a> 930 (<a href="/pkg/net/#IPConn.ReadMsgIP"><code>ReadMsgIP</code></a> 931 and <a href="/pkg/net/#IPConn.WriteMsgIP"><code>WriteMsgIP</code></a>) and 932 <a href="/pkg/net/#UDPConn"><code>UDPConn</code></a> 933 (<a href="/pkg/net/#UDPConn.ReadMsgUDP"><code>ReadMsgUDP</code></a> and 934 <a href="/pkg/net/#UDPConn.WriteMsgUDP"><code>WriteMsgUDP</code></a>). 935 These are specialized versions of <a href="/pkg/net/#PacketConn"><code>PacketConn</code></a>'s 936 <code>ReadFrom</code> and <code>WriteTo</code> methods that provide access to out-of-band data associated 937 with the packets. 938 </li> 939 940 <li> 941 The <a href="/pkg/net/"><code>net</code></a> package adds methods to 942 <a href="/pkg/net/#UnixConn"><code>UnixConn</code></a> to allow closing half of the connection 943 (<a href="/pkg/net/#UnixConn.CloseRead"><code>CloseRead</code></a> and 944 <a href="/pkg/net/#UnixConn.CloseWrite"><code>CloseWrite</code></a>), 945 matching the existing methods of <a href="/pkg/net/#TCPConn"><code>TCPConn</code></a>. 946 </li> 947 948 <li> 949 The <a href="/pkg/net/http/"><code>net/http</code></a> package includes several new additions. 950 <a href="/pkg/net/http/#ParseTime"><code>ParseTime</code></a> parses a time string, trying 951 several common HTTP time formats. 952 The <a href="/pkg/net/http/#Request.PostFormValue"><code>PostFormValue</code></a> method of 953 <a href="/pkg/net/http/#Request"><code>Request</code></a> is like 954 <a href="/pkg/net/http/#Request.FormValue"><code>FormValue</code></a> but ignores URL parameters. 955 The <a href="/pkg/net/http/#CloseNotifier"><code>CloseNotifier</code></a> interface provides a mechanism 956 for a server handler to discover when a client has disconnected. 957 The <code>ServeMux</code> type now has a 958 <a href="/pkg/net/http/#ServeMux.Handler"><code>Handler</code></a> method to access a path's 959 <code>Handler</code> without executing it. 960 The <code>Transport</code> can now cancel an in-flight request with 961 <a href="/pkg/net/http/#Transport.CancelRequest"><code>CancelRequest</code></a>. 962 Finally, the Transport is now more aggressive at closing TCP connections when 963 a <a href="/pkg/net/http/#Response"><code>Response.Body</code></a> is closed before 964 being fully consumed. 965 </li> 966 967 <li> 968 The <a href="/pkg/net/mail/"><code>net/mail</code></a> package has two new functions, 969 <a href="/pkg/net/mail/#ParseAddress"><code>ParseAddress</code></a> and 970 <a href="/pkg/net/mail/#ParseAddressList"><code>ParseAddressList</code></a>, 971 to parse RFC 5322-formatted mail addresses into 972 <a href="/pkg/net/mail/#Address"><code>Address</code></a> structures. 973 </li> 974 975 <li> 976 The <a href="/pkg/net/smtp/"><code>net/smtp</code></a> package's 977 <a href="/pkg/net/smtp/#Client"><code>Client</code></a> type has a new method, 978 <a href="/pkg/net/smtp/#Client.Hello"><code>Hello</code></a>, 979 which transmits a <code>HELO</code> or <code>EHLO</code> message to the server. 980 </li> 981 982 <li> 983 The <a href="/pkg/net/textproto/"><code>net/textproto</code></a> package 984 has two new functions, 985 <a href="/pkg/net/textproto/#TrimBytes"><code>TrimBytes</code></a> and 986 <a href="/pkg/net/textproto/#TrimString"><code>TrimString</code></a>, 987 which do ASCII-only trimming of leading and trailing spaces. 988 </li> 989 990 <li> 991 The new method <a href="/pkg/os/#FileMode.IsRegular"><code>os.FileMode.IsRegular</code></a> makes it easy to ask if a file is a plain file. 992 </li> 993 994 <li> 995 The <a href="/pkg/os/signal/"><code>os/signal</code></a> package has a new function, 996 <a href="/pkg/os/signal/#Stop"><code>Stop</code></a>, which stops the package delivering 997 any further signals to the channel. 998 </li> 999 1000 <li> 1001 The <a href="/pkg/regexp/"><code>regexp</code></a> package 1002 now supports Unix-original leftmost-longest matches through the 1003 <a href="/pkg/regexp/#Regexp.Longest"><code>Regexp.Longest</code></a> 1004 method, while 1005 <a href="/pkg/regexp/#Regexp.Split"><code>Regexp.Split</code></a> slices 1006 strings into pieces based on separators defined by the regular expression. 1007 </li> 1008 1009 <li> 1010 The <a href="/pkg/runtime/debug/"><code>runtime/debug</code></a> package 1011 has three new functions regarding memory usage. 1012 The <a href="/pkg/runtime/debug/#FreeOSMemory"><code>FreeOSMemory</code></a> 1013 function triggers a run of the garbage collector and then attempts to return unused 1014 memory to the operating system; 1015 the <a href="/pkg/runtime/debug/#ReadGCStats"><code>ReadGCStats</code></a> 1016 function retrieves statistics about the collector; and 1017 <a href="/pkg/runtime/debug/#SetGCPercent"><code>SetGCPercent</code></a> 1018 provides a programmatic way to control how often the collector runs, 1019 including disabling it altogether. 1020 </li> 1021 1022 <li> 1023 The <a href="/pkg/sort/"><code>sort</code></a> package has a new function, 1024 <a href="/pkg/sort/#Reverse"><code>Reverse</code></a>. 1025 Wrapping the argument of a call to 1026 <a href="/pkg/sort/#Sort"><code>sort.Sort</code></a> 1027 with a call to <code>Reverse</code> causes the sort order to be reversed. 1028 </li> 1029 1030 <li> 1031 The <a href="/pkg/strings/"><code>strings</code></a> package has two new functions, 1032 <a href="/pkg/strings/#TrimPrefix"><code>TrimPrefix</code></a> 1033 and 1034 <a href="/pkg/strings/#TrimSuffix"><code>TrimSuffix</code></a> 1035 with self-evident properties, and the new method 1036 <a href="/pkg/strings/#Reader.WriteTo"><code>Reader.WriteTo</code></a> so the 1037 <a href="/pkg/strings/#Reader"><code>Reader</code></a> 1038 type now implements the 1039 <a href="/pkg/io/#WriterTo"><code>io.WriterTo</code></a> interface. 1040 </li> 1041 1042 <li> 1043 The <a href="/pkg/syscall/"><code>syscall</code></a> package's 1044 <a href="/pkg/syscall/#Fchflags"><code>Fchflags</code></a> function on various BSDs 1045 (including Darwin) has changed signature. 1046 It now takes an int as the first parameter instead of a string. 1047 Since this API change fixes a bug, it is permitted by the Go 1 compatibility rules. 1048 </li> 1049 <li> 1050 The <a href="/pkg/syscall/"><code>syscall</code></a> package also has received many updates 1051 to make it more inclusive of constants and system calls for each supported operating system. 1052 </li> 1053 1054 <li> 1055 The <a href="/pkg/testing/"><code>testing</code></a> package now automates the generation of allocation 1056 statistics in tests and benchmarks using the new 1057 <a href="/pkg/testing/#AllocsPerRun"><code>AllocsPerRun</code></a> function. And the 1058 <a href="/pkg/testing/#B.ReportAllocs"><code>ReportAllocs</code></a> 1059 method on <a href="/pkg/testing/#B"><code>testing.B</code></a> will enable printing of 1060 memory allocation statistics for the calling benchmark. It also introduces the 1061 <a href="/pkg/testing/#BenchmarkResult.AllocsPerOp"><code>AllocsPerOp</code></a> method of 1062 <a href="/pkg/testing/#BenchmarkResult"><code>BenchmarkResult</code></a>. 1063 There is also a new 1064 <a href="/pkg/testing/#Verbose"><code>Verbose</code></a> function to test the state of the <code>-v</code> 1065 command-line flag, 1066 and a new 1067 <a href="/pkg/testing/#B.Skip"><code>Skip</code></a> method of 1068 <a href="/pkg/testing/#B"><code>testing.B</code></a> and 1069 <a href="/pkg/testing/#T"><code>testing.T</code></a> 1070 to simplify skipping an inappropriate test. 1071 </li> 1072 1073 <li> 1074 In the <a href="/pkg/text/template/"><code>text/template</code></a> 1075 and 1076 <a href="/pkg/html/template/"><code>html/template</code></a> packages, 1077 templates can now use parentheses to group the elements of pipelines, simplifying the construction of complex pipelines. 1078 Also, as part of the new parser, the 1079 <a href="/pkg/text/template/parse/#Node"><code>Node</code></a> interface got two new methods to provide 1080 better error reporting. 1081 Although this violates the Go 1 compatibility rules, 1082 no existing code should be affected because this interface is explicitly intended only to be used 1083 by the 1084 <a href="/pkg/text/template/"><code>text/template</code></a> 1085 and 1086 <a href="/pkg/html/template/"><code>html/template</code></a> 1087 packages and there are safeguards to guarantee that. 1088 </li> 1089 1090 <li> 1091 The implementation of the <a href="/pkg/unicode/"><code>unicode</code></a> package has been updated to Unicode version 6.2.0. 1092 </li> 1093 1094 <li> 1095 In the <a href="/pkg/unicode/utf8/"><code>unicode/utf8</code></a> package, 1096 the new function <a href="/pkg/unicode/utf8/#ValidRune"><code>ValidRune</code></a> reports whether the rune is a valid Unicode code point. 1097 To be valid, a rune must be in range and not be a surrogate half. 1098 </li> 1099 </ul> 1100