blob: 6d8f148eda32bc051387dd2846d8d8af94467f77 [file] [log] [blame]
Andrew Gerrand7cb21a72012-01-19 11:24:54 +11001<!--{
2 "Title": "Go 1 Release Notes"
3}-->
Rob Pike9d59c402011-12-08 11:35:28 -08004<!--
5 DO NOT EDIT: created by
6 tmpltohtml go1.tmpl
7-->
8
Rob Pikebab4dec2011-12-07 14:33:37 -08009
10<h2 id="introduction">Introduction to Go 1</h2>
11
12<p>
13For a full explanation of the motivation and design of Go 1, see XXX.
14Here follows a summary.
15</p>
16
17<p>
Rob Pike2fa987b2011-12-07 16:11:17 -080018Go 1 is intended to be a stable language and core library set that
19will form a reliable foundation for people and organizations that
20want to make a long-term commitment to developing in the Go programming
21language. Go will continue to develop, but in a way that guarantees
22code written to the Go 1 specification will continue to work. For
23instance, Go 1 will be a supported platform on Google App Engine
24for the next few years. Incompatible changes to the environment,
25should they arise, will be done in a distinct version.
Rob Pikebab4dec2011-12-07 14:33:37 -080026</p>
27
28<p>
Rob Pike2fa987b2011-12-07 16:11:17 -080029This document describes the changes in the language and libraries
30in Go 1, relative to the previous release, r60 (at the time of
31writing, tagged as r60.3). It also explains how to update code at
32r60 to compile and run under Go 1. Finally, it outlines the new
33<code>go</code> command for building Go programs and the new binary
34release process being introduced. Most of these topics have more
35thorough presentations elsewhere; such documents are linked below.
Rob Pike136c04f2011-12-08 16:39:05 -080036</p>
Rob Pikebab4dec2011-12-07 14:33:37 -080037
38<h2 id="language">Changes to the language</h2>
39
40<h3 id="append">Append</h3>
41
Rob Pike136c04f2011-12-08 16:39:05 -080042<p>
43The <code>append</code> built-in function is variadic, so one can
44append to a byte slice using the <code>...</code> syntax in the
45call.
46</p>
47
48<pre><!--{{code "progs/go1.go" `/greeting := ..byte/` `/append.*hello/`}}
Andrew Gerrand468e6922012-01-09 20:05:34 +110049--> greeting := []byte{}
Andrew Gerrand5353e1e2012-01-06 09:20:31 +110050 greeting = append(greeting, []byte(&#34;hello &#34;)...)</pre>
Rob Pike136c04f2011-12-08 16:39:05 -080051
52<p>
53By analogy with the similar property of <code>copy</code>, Go 1
54permits a string to be appended (byte-wise) directly to a byte
55slice; the conversion is no longer necessary:
56</p>
57
58<pre><!--{{code "progs/go1.go" `/append.*world/`}}
Andrew Gerrand468e6922012-01-09 20:05:34 +110059--> greeting = append(greeting, &#34;world&#34;...)</pre>
Rob Pike136c04f2011-12-08 16:39:05 -080060
61<p>
62<em>Updating</em>:
63This is a new feature, so existing code needs no changes.
64</p>
65
Rob Pikebab4dec2011-12-07 14:33:37 -080066<h3 id="close">Close</h3>
67
Rob Pike136c04f2011-12-08 16:39:05 -080068<p>
69The <code>close</code> built-in function lets a sender tell a receiver
70that no more data will be transmitted on the channel. In Go 1 the
71type system enforces the directionality when possible: it is illegal
72to call <code>close</code> on a receive-only channel:
73</p>
74
75<pre>
76 var c chan int
Robert Hencke7c9ee5f2012-01-25 21:09:46 -080077 var csend chan&lt;- int = c
78 var crecv &lt;-chan int = c
Rob Pike136c04f2011-12-08 16:39:05 -080079 close(c) // legal
80 close(csend) // legal
81 close(crecv) // illegal
82</pre>
83
84<p>
85<em>Updating</em>:
86Existing code that attempts to close a receive-only channel was
87erroneous even before Go 1 and should be fixed. The compiler will
88now reject such code.
89</p>
90
Rob Pike9d59c402011-12-08 11:35:28 -080091<h3 id="literals">Composite literals</h3>
Rob Pikebab4dec2011-12-07 14:33:37 -080092
Rob Pike2e338fa2011-12-09 08:31:57 -080093<p>
94In Go 1, a composite literal of array, slice, or map type can elide the
95type specification for the elements' initializers if they are of pointer type.
96All four of the initializations in this example are legal; the last one was illegal before Go 1.
97</p>
98
99<pre><!--{{code "progs/go1.go" `/type Date struct/` `/STOP/`}}
Andrew Gerrand468e6922012-01-09 20:05:34 +1100100--> type Date struct {
Rob Pike2e338fa2011-12-09 08:31:57 -0800101 month string
102 day int
103 }
104 // Struct values, fully qualified; always legal.
105 holiday1 := []Date{
106 Date{&#34;Feb&#34;, 14},
107 Date{&#34;Nov&#34;, 11},
108 Date{&#34;Dec&#34;, 25},
109 }
110 // Struct values, type name elided; always legal.
111 holiday2 := []Date{
112 {&#34;Feb&#34;, 14},
113 {&#34;Nov&#34;, 11},
114 {&#34;Dec&#34;, 25},
115 }
116 // Pointers, fully qualified, always legal.
117 holiday3 := []*Date{
118 &amp;Date{&#34;Feb&#34;, 14},
119 &amp;Date{&#34;Nov&#34;, 11},
120 &amp;Date{&#34;Dec&#34;, 25},
121 }
122 // Pointers, type name elided; legal in Go 1.
123 holiday4 := []*Date{
124 {&#34;Feb&#34;, 14},
125 {&#34;Nov&#34;, 11},
126 {&#34;Dec&#34;, 25},
Andrew Gerrand5353e1e2012-01-06 09:20:31 +1100127 }</pre>
Rob Pike2e338fa2011-12-09 08:31:57 -0800128
129<p>
130<em>Updating</em>:
131This change has no effect on existing code, but the command
132<code>gofmt</code> <code>-s</code> applied to existing source
133will, among other things, elide explicit element types wherever permitted.
134</p>
135
136
Rob Pike9d59c402011-12-08 11:35:28 -0800137<h3 id="init">Goroutines during init</h3>
Rob Pikebab4dec2011-12-07 14:33:37 -0800138
Rob Pike136c04f2011-12-08 16:39:05 -0800139<p>
140Go 1 allows goroutines to be created and run during initialization.
141(They used to be created but were not run until after initialization
142completed.) Code that uses goroutines can now be called from
143<code>init</code> routines and global initialization expressions
144without introducing a deadlock.
145</p>
146
147<pre><!--{{code "progs/go1.go" `/PackageGlobal/` `/^}/`}}
148-->var PackageGlobal int
149
150func init() {
151 c := make(chan int)
152 go initializationFunction(c)
153 PackageGlobal = &lt;-c
Andrew Gerrand5353e1e2012-01-06 09:20:31 +1100154}</pre>
Rob Pike136c04f2011-12-08 16:39:05 -0800155
156<p>
157<em>Updating</em>:
158This is a new feature, so existing code needs no changes,
159although it's possible that code that depends on goroutines not starting before <code>main</code> will break.
160There was no such code in the standard repository.
161</p>
162
Rob Pikebab4dec2011-12-07 14:33:37 -0800163<h3 id="rune">The rune type</h3>
164
Rob Pike2e338fa2011-12-09 08:31:57 -0800165<p>
166Go 1 introduces a new basic type, <code>rune</code>, to be used to represent
167individual Unicode code points.
168It is an alias for <code>int32</code>, analogous to <code>byte</code>
169as an alias for <code>uint8</code>.
170</p>
171
172<p>
173Character literals such as <code>'a'</code>, <code>'語'</code>, and <code>'\u0345'</code>
174now have default type <code>rune</code>,
175analogous to <code>1.0</code> having default type <code>float64</code>.
176A variable initialized to a character constant will therefore
177have type <code>rune</code> unless otherwise specified.
178</p>
179
180<p>
181Libraries have been updated to use <code>rune</code> rather than <code>int</code>
182when appropriate. For instance, the functions <code>unicode.ToLower</code> and
183relatives now take and return a <code>rune</code>.
184</p>
185
186<pre><!--{{code "progs/go1.go" `/STARTRUNE/` `/ENDRUNE/`}}
Andrew Gerrand468e6922012-01-09 20:05:34 +1100187--> delta := &#39;δ&#39; // delta has type rune.
Rob Pike2e338fa2011-12-09 08:31:57 -0800188 var DELTA rune
189 DELTA = unicode.ToUpper(delta)
190 epsilon := unicode.ToLower(DELTA + 1)
191 if epsilon != &#39;δ&#39;+1 {
192 log.Fatal(&#34;inconsistent casing for Greek&#34;)
Andrew Gerrand5353e1e2012-01-06 09:20:31 +1100193 }</pre>
Rob Pike2e338fa2011-12-09 08:31:57 -0800194
195<p>
196<em>Updating</em>:
197Most source code will be unaffected by this because the type inference from
198<code>:=</code> initializers introduces the new type silently, and it propagates
199from there.
200Some code may get type errors that a trivial conversion will resolve.
201</p>
202
203<h3 id="error">The error type</h3>
204
205<p>
206Go 1 introduces a new built-in type, <code>error</code>, which has the following definition:
207</p>
208
209<pre>
210 type error interface {
211 Error() string
212 }
213</pre>
214
215<p>
216Since the consequences of this type are all in the package library,
Rob Pikeebdcbf12011-12-12 12:26:56 -0800217it is discussed <a href="#errors">below</a>.
Rob Pike2e338fa2011-12-09 08:31:57 -0800218</p>
219
Rob Pike9d59c402011-12-08 11:35:28 -0800220<h3 id="delete">Deleting from maps</h3>
Rob Pike2fa987b2011-12-07 16:11:17 -0800221
222<p>
223The original syntax for deleting an element in a map was:
224</p>
225
226<pre>
Rob Pike2e338fa2011-12-09 08:31:57 -0800227 m[k] = ignored, false
Rob Pike2fa987b2011-12-07 16:11:17 -0800228</pre>
229
230<p>
Rob Pike9d59c402011-12-08 11:35:28 -0800231In Go 1, that syntax has gone; instead there is a new built-in
Rob Pike2fa987b2011-12-07 16:11:17 -0800232function, <code>delete</code>. The call
233</p>
234
235<pre><!--{{code "progs/go1.go" `/delete\(m, k\)/`}}
Andrew Gerrand468e6922012-01-09 20:05:34 +1100236--> delete(m, k)</pre>
Rob Pike2fa987b2011-12-07 16:11:17 -0800237
238<p>
239will delete the map entry retrieved by the expression <code>m[k]</code>.
240There is no return value. Deleting a non-existent entry is a no-op.
241</p>
242
243<p>
244<em>Updating</em>:
Rob Pike27836912012-02-04 07:49:51 +1100245Running <code>go fix</code> will convert expressions of the form <code>m[k] = ignored,
Rob Pike2fa987b2011-12-07 16:11:17 -0800246false</code> into <code>delete(m, k)</code> when it is clear that
247the ignored value can be safely discarded from the program and
Rob Pike27836912012-02-04 07:49:51 +1100248<code>false</code> refers to the predefined boolean constant.
249The fix tool
Rob Pike2fa987b2011-12-07 16:11:17 -0800250will flag other uses of the syntax for inspection by the programmer.
251</p>
252
Rob Pike136c04f2011-12-08 16:39:05 -0800253<h3 id="iteration">Iterating in maps</h3>
254
255<p>
256In Go 1, the order in which elements are visited when iterating
257over a map using a <code>for</code> <code>range</code> statement
258is defined to be unpredictable, even if the same loop is run multiple
259times with the same map.
260Code should not assume that the elements are visited in any particular order.
261</p>
262
263<pre><!--{{code "progs/go1.go" `/Sunday/` `/^ }/`}}
Andrew Gerrand468e6922012-01-09 20:05:34 +1100264--> m := map[string]int{&#34;Sunday&#34;: 0, &#34;Monday&#34;: 1}
Rob Pike136c04f2011-12-08 16:39:05 -0800265 for name, value := range m {
266 // This loop should not assume Sunday will be visited first.
267 f(name, value)
Andrew Gerrand5353e1e2012-01-06 09:20:31 +1100268 }</pre>
Rob Pike136c04f2011-12-08 16:39:05 -0800269
270<p>
271<em>Updating</em>:
272This is one change where tools cannot help. Most existing code
273will be unaffected, but some programs may break or misbehave; we
274recommend manual checking of all range statements over maps to
275verify they do not depend on iteration order. There were a few such
276examples in the standard repository; they have been fixed.
277Note that it was already incorrect to depend on the iteration order, which
278was unspecified. This change codifies the unpredictability.
279</p>
Rob Pikebab4dec2011-12-07 14:33:37 -0800280
281<h3 id="multiple_assignment">Multiple assignment</h3>
282
Rob Pike136c04f2011-12-08 16:39:05 -0800283<p>
284Go 1 fully specifies the evaluation order in multiple assignment
285statements. In particular, if the left-hand side of the assignment
286statement contains expressions that require evaluation, such as
287function calls or array indexing operations, these will all be done
288using the usual left-to-right rule before any variables are assigned
289their value. Once everything is evaluated, the actual assignments
290proceed in left-to-right order.
291</p>
292
293<p>
294These examples illustrate the behavior.
295</p>
296
297<pre><!--{{code "progs/go1.go" `/sa :=/` `/then sc.0. = 2/`}}
Andrew Gerrand468e6922012-01-09 20:05:34 +1100298--> sa := []int{1, 2, 3}
Rob Pike136c04f2011-12-08 16:39:05 -0800299 i := 0
300 i, sa[i] = 1, 2 // sets i = 1, sa[0] = 2
301
302 sb := []int{1, 2, 3}
303 j := 0
304 sb[j], j = 2, 1 // sets sb[0] = 2, j = 1
305
306 sc := []int{1, 2, 3}
Andrew Gerrand5353e1e2012-01-06 09:20:31 +1100307 sc[0], sc[0] = 1, 2 // sets sc[0] = 1, then sc[0] = 2 (so sc[0] = 2 at end)</pre>
Rob Pike136c04f2011-12-08 16:39:05 -0800308
Rob Pike2e338fa2011-12-09 08:31:57 -0800309<p>
Rob Pike136c04f2011-12-08 16:39:05 -0800310<em>Updating</em>:
311This is one change where tools cannot help, but breakage is unlikely.
312No code in the standard repository was broken by this change, and code
313that depended on the previous unspecified behavior was already incorrect.
314</p>
315
Rob Pikebab4dec2011-12-07 14:33:37 -0800316<h3 id="shadowing">Returns and shadowed variables</h3>
317
Rob Pike136c04f2011-12-08 16:39:05 -0800318<p>
319A shadowed variable is one that has the same name as another variable in an inner scope.
320In functions with named return values,
321the Go 1 compilers disallow return statements without arguments if any of the named return values is shadowed at the point of the return statement.
322(It isn't part of the specification, because this is one area we are still exploring;
323the situation is analogous to the compilers rejecting functions that do not end with an explicit return statement.)
324</p>
325
326<p>
327This function implicitly returns a shadowed return value and will be rejected by the compiler:
328</p>
329
330<pre>
331 func Bug() (i, j, k int) {
Robert Hencke7c9ee5f2012-01-25 21:09:46 -0800332 for i = 0; i &lt; 5; i++ {
333 for j := 0; j &lt; 5; j++ { // Redeclares j.
Rob Pike136c04f2011-12-08 16:39:05 -0800334 k += i*j
335 if k > 100 {
336 return // Rejected: j is shadowed here.
337 }
338 }
339 }
340 return // OK: j is not shadowed here.
341 }
342</pre>
343
344<p>
345<em>Updating</em>:
346Code that shadows return values in this way will be rejected by the compiler and will need to be fixed by hand.
347The few cases that arose in the standard repository were mostly bugs.
348</p>
349
350<h3 id="unexported">Copying structs with unexported fields</h3>
351
Rob Pike2e338fa2011-12-09 08:31:57 -0800352<p>
353Go 1 relaxes the rules about accessing structs with unexported (lower-case) fields,
354permitting a client package to assign (and therefore copy) such a struct.
355Of course, the client package still cannot access such fields individually.
356</p>
357
358<p>
359As an example, if package <code>p</code> includes the definitions,
360</p>
361
362<pre>
363 type Struct struct {
364 Public int
365 secret int
366 }
367 func NewStruct(a int) Struct { // Note: not a pointer.
368 return Struct{a, f(a)}
369 }
370 func (s Struct) String() string {
371 return fmt.Sprintf("{%d (secret %d)}", s.Public, s.secret)
372 }
373</pre>
374
375<p>
376a package that imports <code>p</code> can assign and copy values of type
377<code>p.Struct</code> at will.
378Behind the scenes the unexported fields will be assigned and copied just
379as if they were exported,
380but the client code will never be aware of them. The code
381</p>
382
383<pre>
384 import "p"
385
386 myStruct := p.NewStruct(23)
387 copyOfMyStruct := myStruct
388 fmt.Println(myStruct, copyOfMyStruct)
389</pre>
390
391<p>
392will show that the secret field of the struct has been copied to the new value.
393</p>
394
395<p>
396<em>Updating</em>:
397This is a new feature, so existing code needs no changes.
398</p>
399
Rob Pike9d59c402011-12-08 11:35:28 -0800400<h3 id="equality">Equality of structs and arrays</h3>
Rob Pikebab4dec2011-12-07 14:33:37 -0800401
Rob Pike136c04f2011-12-08 16:39:05 -0800402<p>
403Go 1 defines equality and inequality (<code>==</code> and
404<code>!=</code>) for struct and array values, respectively, provided
405the elements of the data structures can themselves be compared.
406That is, if equality is defined for all the fields of a struct (or
407an array element), then it is defined for the struct (or array).
408</p>
409
410<p>
411As a result, structs and arrays can now be used as map keys:
412</p>
413
414<pre><!--{{code "progs/go1.go" `/type Day struct/` `/Printf/`}}
Andrew Gerrand468e6922012-01-09 20:05:34 +1100415--> type Day struct {
Rob Pike5fa18e12011-12-12 21:08:03 -0800416 long string
417 short string
418 }
419 Christmas := Day{&#34;Christmas&#34;, &#34;XMas&#34;}
420 Thanksgiving := Day{&#34;Thanksgiving&#34;, &#34;Turkey&#34;}
421 holiday := map[Day]bool{
422 Christmas: true,
423 Thanksgiving: true,
424 }
Andrew Gerrand5353e1e2012-01-06 09:20:31 +1100425 fmt.Printf(&#34;Christmas is a holiday: %t\n&#34;, holiday[Christmas])</pre>
Rob Pike136c04f2011-12-08 16:39:05 -0800426
427<p>
428Note that equality is still undefined for slices, for which the
429calculation is in general infeasible. Also note that the ordered
430comparison operators (<code>&lt;</code> <code>&lt;=</code>
431<code>&gt;</code> <code>&gt;=</code>) are still undefined for
432structs and arrays.
433
434<p>
435<em>Updating</em>:
436This is a new feature, so existing code needs no changes.
437</p>
438
439<h3 id="funcs">Function and map equality</h3>
440
441<p>
442Go 1 disallows checking for equality of functions and maps,
443respectively, except to compare them directly to <code>nil</code>.
444</p>
445
446<p>
447<em>Updating</em>:
448Existing code that depends on function or map equality will be
449rejected by the compiler and will need to be fixed by hand.
450Few programs will be affected, but the fix may require some
451redesign.
452</p>
453
Rob Pike0a1376a2012-01-20 14:28:48 -0800454<h2 id="packages">The package hierarchy</h2>
455
456<p>
457This section describes how the packages have been rearranged in Go 1.
458Some have moved, some have been renamed, some have been deleted.
459New packages are described in later sections.
460</p>
Rob Pikebab4dec2011-12-07 14:33:37 -0800461
Rob Pike9d59c402011-12-08 11:35:28 -0800462<h3 id="hierarchy">The package hierarchy</h3>
463
464<p>
465Go 1 has a rearranged package hierarchy that groups related items
466into subdirectories. For instance, <code>utf8</code> and
467<code>utf16</code> now occupy subdirectories of <code>unicode</code>.
468Also, <a href="#subrepo">some packages</a> have moved into
469subrepositories of
470<a href="http://code.google.com/p/go"><code>code.google.com/p/go</code></a>
471while <a href="#deleted">others</a> have been deleted outright.
472</p>
473
474<table class="codetable" frame="border" summary="Moved packages">
475<colgroup align="left" width="60%"></colgroup>
476<colgroup align="left" width="40%"></colgroup>
477<tr>
478<th align="left">Old path</th>
479<th align="left">New path</th>
480</tr>
Rob Pike71ccf732011-12-09 14:12:51 -0800481<tr>
482<td colspan="2"><hr></td>
483</tr>
Rob Pike136c04f2011-12-08 16:39:05 -0800484<tr><td>asn1</td> <td>encoding/asn1</td></tr>
Rob Pike9d59c402011-12-08 11:35:28 -0800485<tr><td>csv</td> <td>encoding/csv</td></tr>
486<tr><td>gob</td> <td>encoding/gob</td></tr>
487<tr><td>json</td> <td>encoding/json</td></tr>
488<tr><td>xml</td> <td>encoding/xml</td></tr>
489<tr>
490<td colspan="2"><hr></td>
491</tr>
492<tr><td>exp/template/html</td> <td>html/template</td></tr>
493<tr>
494<td colspan="2"><hr></td>
495</tr>
496<tr><td>big</td> <td>math/big</td></tr>
497<tr><td>cmath</td> <td>math/cmplx</td></tr>
498<tr><td>rand</td> <td>math/rand</td></tr>
499<tr>
500<td colspan="2"><hr></td>
501</tr>
502<tr><td>http</td> <td>net/http</td></tr>
503<tr><td>http/cgi</td> <td>net/http/cgi</td></tr>
504<tr><td>http/fcgi</td> <td>net/http/fcgi</td></tr>
505<tr><td>http/httptest</td> <td>net/http/httptest</td></tr>
506<tr><td>http/pprof</td> <td>net/http/pprof</td></tr>
507<tr><td>mail</td> <td>net/mail</td></tr>
508<tr><td>rpc</td> <td>net/rpc</td></tr>
509<tr><td>rpc/jsonrpc</td> <td>net/rpc/jsonrpc</td></tr>
510<tr><td>smtp</td> <td>net/smtp</td></tr>
511<tr><td>url</td> <td>net/url</td></tr>
512<tr>
513<td colspan="2"><hr></td>
514</tr>
515<tr><td>exec</td> <td>os/exec</td></tr>
516<tr>
517<td colspan="2"><hr></td>
518</tr>
519<tr><td>scanner</td> <td>text/scanner</td></tr>
520<tr><td>tabwriter</td> <td>text/tabwriter</td></tr>
521<tr><td>template</td> <td>text/template</td></tr>
522<tr><td>template/parse</td> <td>text/template/parse</td></tr>
523<tr>
524<td colspan="2"><hr></td>
525</tr>
526<tr><td>utf8</td> <td>unicode/utf8</td></tr>
527<tr><td>utf16</td> <td>unicode/utf16</td></tr>
528</table>
529
530<p>
531Note that the package names for the old <code>cmath</code> and
532<code>exp/template/html</code> packages have changed to <code>cmplx</code>
533and <code>template</code>.
534</p>
535
536<p>
537<em>Updating</em>:
Rob Pike27836912012-02-04 07:49:51 +1100538Running <code>go fix</code> will update all imports and package renames for packages that
Rob Pike9d59c402011-12-08 11:35:28 -0800539remain inside the standard repository. Programs that import packages
540that are no longer in the standard repository will need to be edited
541by hand.
Rob Pike71ccf732011-12-09 14:12:51 -0800542<br>
Rob Pike27836912012-02-04 07:49:51 +1100543<font color="red">TODO: go fix should warn about deletions.</font>
Rob Pike9d59c402011-12-08 11:35:28 -0800544</p>
Rob Pikebab4dec2011-12-07 14:33:37 -0800545
Rob Pike0a1376a2012-01-20 14:28:48 -0800546<h3 id="exp">The package tree exp</h3>
547
548<p>
549Because they are not standardized, the packages under the <code>exp</code> directory will not be available in the
550standard Go 1 release distributions, although they will be available in source code form
551in <a href="http://code.google.com/p/go/">the repository</a> for
552developers who wish to use them.
553</p>
554
555<p>
556Several packages have moved under <code>exp</code> at the time of Go 1's release:
557</p>
558
559<ul>
560<li><code>ebnf</code></li>
561<li><code>go/types</code></li>
David Symondsb68d9472012-02-02 09:08:50 +1100562<li><code>os/signal</code></li>
Rob Pike0a1376a2012-01-20 14:28:48 -0800563</ul>
564
565<p>
Rob Pike531ded92012-01-20 15:38:03 -0800566All these packages are available under the same names, with the prefix <code>exp/</code>: <code>exp/ebnf</code> etc.
567</p>
568
569<p>
Rob Pike0a1376a2012-01-20 14:28:48 -0800570Also, the <code>utf8.String</code> type has been moved to its own package, <code>exp/utf8string</code>.
571</p>
572
573<p>
Rob Pike531ded92012-01-20 15:38:03 -0800574Finally, the <code>gotype</code> command now resides in <code>exp/gotype</code>, while
Rob Pike27836912012-02-04 07:49:51 +1100575<code>ebnflint</code> is now in <code>exp/ebnflint</code>.
576If they are installed, they now reside in <code>$GOROOT/bin/tool</code>.
Rob Pike0a1376a2012-01-20 14:28:48 -0800577</p>
578
579<p>
580<em>Updating</em>:
581Code that uses packages in <code>exp</code> will need to be updated by hand,
582or else compiled from an installation that has <code>exp</code> available.
Rob Pike27836912012-02-04 07:49:51 +1100583The go fix tool or the compiler will complain about such uses.
Rob Pike0a1376a2012-01-20 14:28:48 -0800584<br>
Rob Pike27836912012-02-04 07:49:51 +1100585<font color="red">TODO: go fix should warn about such uses.</font>
Rob Pike0a1376a2012-01-20 14:28:48 -0800586</p>
587
588<h3 id="old">The package tree old</h3>
589
590<p>
591Because they are deprecated, the packages under the <code>old</code> directory will not be available in the
592standard Go 1 release distributions, although they will be available in source code form for
593developers who wish to use them.
594</p>
595
596<p>
597The packages in their new locations are:
598</p>
599
600<ul>
601<li><code>old/netchan</code></li>
602<li><code>old/regexp</code></li>
603<li><code>old/template</code></li>
604</ul>
605
606<p>
607<em>Updating</em>:
608Code that uses packages now in <code>old</code> will need to be updated by hand,
609or else compiled from an installation that has <code>old</code> available.
Rob Pike27836912012-02-04 07:49:51 +1100610The go fix tool will warn about such uses.
Rob Pike0a1376a2012-01-20 14:28:48 -0800611<br>
Rob Pike27836912012-02-04 07:49:51 +1100612<font color="red">TODO: go fix should warn about such uses.</font>
Rob Pike0a1376a2012-01-20 14:28:48 -0800613</p>
614
615<h3 id="deleted">Deleted packages</h3>
616
617<p>
618Go 1 deletes several packages outright:
619</p>
620
621<ul>
622<li><code>container/vector</code></li>
623<li><code>exp/datafmt</code></li>
624<li><code>go/typechecker</code></li>
625<li><code>try</code></li>
626</ul>
627
628<p>
629and also the command <code>gotry</code>.
630</p>
631
632<p>
633<em>Updating</em>:
634Code that uses <code>container/vector</code> should be updated to use
635slices directly. See
636<a href="http://code.google.com/p/go-wiki/wiki/SliceTricks">the Go
637Language Community Wiki</a> for some suggestions.
638Code that uses the other packages (there should be almost zero) will need to be rethought.
639<br>
Rob Pike27836912012-02-04 07:49:51 +1100640<font color="red">TODO: go fix should warn such uses.</font>
Rob Pike0a1376a2012-01-20 14:28:48 -0800641</p>
642
643<h3 id="subrepo">Packages moving to subrepositories</h3>
644
Rob Pike7eaad5e2012-01-25 13:29:25 -0800645<p>
646Go 1 has moved a number of packages into sub-repositories of
647<a href="http://code.google.com/p/go/">the main Go repository</a>.
648This table lists the old and new import paths:
649
650<table class="codetable" frame="border" summary="Sub-repositories">
651<colgroup align="left" width="40%"></colgroup>
652<colgroup align="left" width="60%"></colgroup>
653<tr>
654<th align="left">Old</th>
655<th align="left">New</th>
656</tr>
657<tr>
658<td colspan="2"><hr></td>
659</tr>
660<tr><td>crypto/bcrypt</td> <td>code.google.com/p/go.crypto/bcrypt</tr>
661<tr><td>crypto/blowfish</td> <td>code.google.com/p/go.crypto/blowfish</tr>
662<tr><td>crypto/cast5</td> <td>code.google.com/p/go.crypto/cast5</tr>
663<tr><td>crypto/md4</td> <td>code.google.com/p/go.crypto/md4</tr>
664<tr><td>crypto/ocsp</td> <td>code.google.com/p/go.crypto/ocsp</tr>
665<tr><td>crypto/openpgp</td> <td>code.google.com/p/go.crypto/openpgp</tr>
666<tr><td>crypto/openpgp/armor</td> <td>code.google.com/p/go.crypto/openpgp/armor</tr>
667<tr><td>crypto/openpgp/elgamal</td> <td>code.google.com/p/go.crypto/openpgp/elgamal</tr>
668<tr><td>crypto/openpgp/errors</td> <td>code.google.com/p/go.crypto/openpgp/errors</tr>
669<tr><td>crypto/openpgp/packet</td> <td>code.google.com/p/go.crypto/openpgp/packet</tr>
670<tr><td>crypto/openpgp/s2k</td> <td>code.google.com/p/go.crypto/openpgp/s2k</tr>
671<tr><td>crypto/ripemd160</td> <td>code.google.com/p/go.crypto/ripemd160</tr>
672<tr><td>crypto/twofish</td> <td>code.google.com/p/go.crypto/twofish</tr>
673<tr><td>crypto/xtea</td> <td>code.google.com/p/go.crypto/xtea</tr>
674<tr><td>exp/ssh</td> <td>code.google.com/p/go.crypto/ssh</tr>
675<tr>
676<td colspan="2"><hr></td>
677</tr>
Nigel Taoceb1ca62012-01-31 12:29:00 +1100678<tr><td>image/bmp</td> <td>code.google.com/p/go.image/bmp</tr>
679<tr><td>image/tiff</td> <td>code.google.com/p/go.image/tiff</tr>
680<tr>
681<td colspan="2"><hr></td>
682</tr>
Rob Pike7eaad5e2012-01-25 13:29:25 -0800683<tr><td>net/dict</td> <td>code.google.com/p/go.net/dict</tr>
684<tr><td>net/websocket</td> <td>code.google.com/p/go.net/websocket</tr>
685<tr><td>exp/spdy</td> <td>code.google.com/p/go.net/spdy</tr>
686<tr>
687<td colspan="2"><hr></td>
688</tr>
689<tr><td>encoding/git85</td> <td>code.google.com/p/go.codereview/git85</tr>
690<tr><td>patch</td> <td>code.google.com/p/go.codereview/patch</tr>
691</table>
692
693<p>
694<em>Updating</em>:
Rob Pike27836912012-02-04 07:49:51 +1100695Running <code>go fix</code> will update imports of these packages to use the new import paths.
Rob Pike7eaad5e2012-01-25 13:29:25 -0800696Installations that depend on these packages will need to install them using
697a <code>go install</code> command.
698</p>
Rob Pike0a1376a2012-01-20 14:28:48 -0800699
700<h2 id="major">Major changes to the library</h2>
701
702<p>
703This section describes significant changes to the core libraries, the ones that
704affect the most programs.
705</p>
706
Rob Pike71ccf732011-12-09 14:12:51 -0800707<h3 id="errors">The error type and errors package</h3>
Rob Pikebab4dec2011-12-07 14:33:37 -0800708
Rob Pikeebdcbf12011-12-12 12:26:56 -0800709<p>
710As mentioned above, Go 1 introduces a new built-in interface type called <code>error</code>.
711Its intent is to replace the old <code>os.Error</code> type with a more central concept.
712So the widely-used <code>String</code> method does not cause accidental satisfaction
713of the <code>error</code> interface, the <code>error</code> interface uses instead
714the name <code>Error</code> for that method:
715</p>
716
717<pre>
718 type error interface {
719 Error() string
720 }
721</pre>
722
723<p>
724The <code>fmt</code> library automatically invokes <code>Error</code>, as it already
725does for <code>String</code>, for easy printing of error values.
726</p>
727
728<pre><!--{{code "progs/go1.go" `/START ERROR EXAMPLE/` `/END ERROR EXAMPLE/`}}
729-->type SyntaxError struct {
730 File string
731 Line int
732 Message string
733}
734
735func (se *SyntaxError) Error() string {
736 return fmt.Sprintf(&#34;%s:%d: %s&#34;, se.File, se.Line, se.Message)
Andrew Gerrand5353e1e2012-01-06 09:20:31 +1100737}</pre>
Rob Pikeebdcbf12011-12-12 12:26:56 -0800738
739<p>
740All standard packages have been updated to use the new interface; the old <code>os.Error</code> is gone.
741</p>
742
743<p>
744A new package, <a href="/pkg/errors/"><code>errors</code></a>, contains the function
745</p>
746
747<pre>
748func New(text string) error
749</pre>
750
751<p>
752to turn a string into an error. It replaces the old <code>os.NewError</code>.
753</p>
754
755<pre><!--{{code "progs/go1.go" `/ErrSyntax/`}}
Andrew Gerrand468e6922012-01-09 20:05:34 +1100756--> var ErrSyntax = errors.New(&#34;syntax error&#34;)</pre>
Rob Pikeebdcbf12011-12-12 12:26:56 -0800757
758<p>
759<em>Updating</em>:
Rob Pike27836912012-02-04 07:49:51 +1100760Running <code>go fix</code> will update almost all code affected by the change.
Rob Pikeebdcbf12011-12-12 12:26:56 -0800761Code that defines error types with a <code>String</code> method will need to be updated
762by hand to rename the methods to <code>Error</code>.
763</p>
764
Rob Pike9d59c402011-12-08 11:35:28 -0800765<h3 id="errno">System call errors</h3>
Rob Pikebab4dec2011-12-07 14:33:37 -0800766
Rob Pike71ccf732011-12-09 14:12:51 -0800767<p>
768In Go 1, the
Rob Pikeebdcbf12011-12-12 12:26:56 -0800769<a href="/pkg/syscall/"><code>syscall</code></a>
Rob Pike71ccf732011-12-09 14:12:51 -0800770package returns an <code>error</code> for system call errors,
771rather than plain integer <code>errno</code> values.
772On Unix, the implementation is done by a
Rob Pikeebdcbf12011-12-12 12:26:56 -0800773<a href="/pkg/syscall/#Errno"><code>syscall.Errno</code></a> type
Rob Pike71ccf732011-12-09 14:12:51 -0800774that satisfies <code>error</code> and replaces the old <code>os.Errno</code>.
775</p>
776
777<p>
778<em>Updating</em>:
Rob Pike27836912012-02-04 07:49:51 +1100779Running <code>go fix</code> will update almost all code affected by the change.
Rob Pike71ccf732011-12-09 14:12:51 -0800780Regardless, most code should use the <code>os</code> package
781rather than <code>syscall</code> and so will be unaffected.
782</p>
783
Rob Pikebab4dec2011-12-07 14:33:37 -0800784<h3 id="time">Time</h3>
785
Rob Pike5fa18e12011-12-12 21:08:03 -0800786<p>
787One of the most sweeping changes in the Go 1 library is the
788complete redesign of the
789<a href="/pkg/time/"><code>time</code></a> package.
790Instead of an integer number of nanoseconds as an <code>int64</code>,
791and a separate <code>*time.Time</code> type to deal with human
792units such as hours and years,
793there are now two fundamental types:
794<a href="/pkg/time/#Time"><code>time.Time</code></a>
795(a value, so the <code>*</code> is gone), which represents a moment in time;
796and <a href="/pkg/time/#Duration"><code>time.Duration</code></a>,
797which represents an interval.
798Both have nanosecond resolution.
799A <code>Time</code> can represent any time into the ancient
800past and remote future, while a <code>Duration</code> can
801span plus or minus only about 290 years.
802There are methods on these types, plus a number of helpful
803predefined constant durations such as <code>time.Second</code>.
804</p>
805
806<p>
807Among the new methods are things like
808<a href="/pkg/time/#Time.Add"><code>Time.Add</code></a>,
809which adds a <code>Duration</code> to a <code>Time</code>, and
810<a href="/pkg/time/#Time.Sub"><code>Time.Sub</code></a>,
811which subtracts two <code>Times</code> to yield a <code>Duration</code>.
812</p>
813
814<p>
815The most important semantic change is that the Unix epoch (Jan 1, 1970) is now
816relevant only for those functions and methods that mention Unix:
817<a href="/pkg/time/#Unix"><code>time.Unix</code></a>
818and the <a href="/pkg/time/#Time.Unix"><code>Unix</code></a>
819and <a href="/pkg/time/#Time.UnixNano"><code>UnixNano</code></a> methods
820of the <code>Time</code> type.
821In particular,
822<a href="/pkg/time/#Now"><code>time.Now</code></a>
823returns a <code>time.Time</code> value rather than, in the old
824API, an integer nanosecond count since the Unix epoch.
825</p>
826
827<pre><!--{{code "progs/go1.go" `/sleepUntil/` `/^}/`}}
828-->// sleepUntil sleeps until the specified time. It returns immediately if it&#39;s too late.
829func sleepUntil(wakeup time.Time) {
830 now := time.Now() // A Time.
831 if !wakeup.After(now) {
832 return
833 }
834 delta := wakeup.Sub(now) // A Duration.
835 log.Printf(&#34;Sleeping for %.3fs&#34;, delta.Seconds())
836 time.Sleep(delta)
Andrew Gerrand5353e1e2012-01-06 09:20:31 +1100837}</pre>
Rob Pike5fa18e12011-12-12 21:08:03 -0800838
839<p>
840The new types, methods, and constants have been propagated through
841all the standard packages that use time, such as <code>os</code> and
842its representation of file time stamps.
843</p>
844
845<p>
846<em>Updating</em>:
Rob Pike27836912012-02-04 07:49:51 +1100847The <code>go fix</code> tool will update many uses of the old <code>time</code> package to use the new
Rob Pike5fa18e12011-12-12 21:08:03 -0800848types and methods, although it does not replace values such as <code>1e9</code>
849representing nanoseconds per second.
850Also, because of type changes in some of the values that arise,
Rob Pike27836912012-02-04 07:49:51 +1100851some of the expressions rewritten by the fix tool may require
Rob Pike5fa18e12011-12-12 21:08:03 -0800852further hand editing; in such cases the rewrite will include
853the correct function or method for the old functionality, but
854may have the wrong type or require further analysis.
855</p>
856
Rob Pike0a1376a2012-01-20 14:28:48 -0800857<h2 id="minor">Minor changes to the library</h2>
858
859<p>
860This section describes smaller changes, such as those to less commonly
861used packages or that affect
Rob Pike27836912012-02-04 07:49:51 +1100862few programs beyond the need to run <code>go fix</code>.
Rob Pike0a1376a2012-01-20 14:28:48 -0800863This category includes packages that are new in Go 1.
864</p>
865
Rob Pikebb7b1a12012-02-08 13:07:13 +1100866<h3 id="bufio">The bufio package</h3>
867
868<p>
869In Go 1, <a href="/pkg/bufio/#NewReaderSize"><code>bufio.NewReaderSize</code></a>
870and
871<a href="/pkg/bufio/#NewWriterSize"><code>bufio.NewWriterSize</code></a>
872functions no longer return an error for invalid sizes.
873If the argument size is too small or invalid, it is adjusted.
874</p>
875
876<p>
877<em>Updating</em>:
Rob Pikecf80ccd2012-02-09 07:09:52 +1100878What little code is affected will be caught by the compiler and must be updated by hand.
Rob Pikebb7b1a12012-02-08 13:07:13 +1100879</p>
880
Rob Pike0a1376a2012-01-20 14:28:48 -0800881<h3 id="crypto_elliptic">The crypto/elliptic package</h3>
882
883<p>
884In Go 1, <a href="/pkg/crypto/elliptic/#Curve"><code>elliptic.Curve</code></a>
885has been made an interface to permit alternative implementations. The curve
886parameters have been moved to the
887<a href="/pkg/crypto/elliptic/#CurveParams"><code>elliptic.CurveParams</code></a>
888structure.
889</p>
890
891<p>
892<em>Updating</em>:
893Existing users of <code>*elliptic.Curve</code> will need to change to
894simply <code>elliptic.Curve</code>. Calls to <code>Marshal</code>,
895<code>Unmarshal</code> and <code>GenerateKey</code> are now functions
896in <code>crypto/elliptic</code> that take an <code>elliptic.Curve</code>
897as their first argument.
898</p>
899
Rob Pike27836912012-02-04 07:49:51 +1100900<h3 id="crypto_hmac">The crypto/hmac package</h3>
Adam Langley68aff952012-01-27 10:12:27 -0800901
902<p>
903In Go 1, the hash-specific functions, such as <code>hmac.NewMD5</code>, have
904been removed from <code>crypto/hmac</code>. Instead, <code>hmac.New</code> takes
905a function that returns a <code>hash.Hash</code>, such as <code>md5.New</code>.
906</p>
907
908<p>
909<em>Updating</em>:
Rob Pike27836912012-02-04 07:49:51 +1100910Running <code>go fix</code> will perform the needed changes.
Adam Langley68aff952012-01-27 10:12:27 -0800911</p>
912
Rob Pike0a1376a2012-01-20 14:28:48 -0800913<h3 id="crypto_x509">The crypto/x509 package</h3>
914
915<p>
916In Go 1, the
917<a href="/pkg/crypto/x509/#CreateCertificate"><code>CreateCertificate</code></a>
918and
919<a href="/pkg/crypto/x509/#CreateCRL"><code>CreateCRL</code></a>
920functions in <code>crypto/x509</code> have been altered to take an
921<code>interface{}</code> where they previously took a <code>*rsa.PublicKey</code>
922or <code>*rsa.PrivateKey</code>. This will allow other public key algorithms
923to be implemented in the future.
924</p>
925
926<p>
927<em>Updating</em>:
928No changes will be needed.
929</p>
930
Rob Pike52ebadd2012-02-08 14:09:20 +1100931<h3 id="encoding_binary">The encoding/binary package</h3>
932
933<p>
Rob Pike1c1ecd72012-02-09 14:40:56 +1100934In Go 1, the <code>binary.TotalSize</code> function has been replaced by
935<a href="/pkg/encoding/binary/#Size"><code>Size</code></a>,
936which takes an <code>interface{}</code> argument rather than
937a <code>reflect.Value</code>.
Rob Pike52ebadd2012-02-08 14:09:20 +1100938</p>
939
940<p>
941<em>Updating</em>:
Rob Pikecf80ccd2012-02-09 07:09:52 +1100942What little code is affected will be caught by the compiler and must be updated by hand.
Rob Pike52ebadd2012-02-08 14:09:20 +1100943</p>
944
945<h3 id="encoding_xml">The encoding/xml package</h3>
946
947<p>
948In Go 1, the <a href="/pkg/encoding/xml/"><code>xml</code></a> package
949has been brought closer in design to the other marshaling packages such
950as <a href="/pkg/encoding/gob/"><code>encoding/gob</code></a>.
951</p>
952
953<p>
954The old <code>Parser</code> type is renamed
955<a href="/pkg/encoding/xml/#Decoder"><code>Decoder</code></a> and has a new
956<a href="/pkg/encoding/xml/#Decoder.Decode"><code>Decode</code></a> method. An
957<a href="/pkg/encoding/xml/#Encoder"><code>Encoder</code></a> type was also
958introduced.
959</p>
960
961<p>
962The functions <a href="/pkg/encoding/xml/#Marshal"><code>Marshal</code></a>
963and <a href="/pkg/encoding/xml/#Unmarshal"><code>Unmarshal</code></a>
964work with <code>[]byte</code> values now. To work with streams,
965use the new <a href="/pkg/encoding/xml/#Encoder"><code>Encoder</code></a>
966and <a href="/pkg/encoding/xml/#Decoder"><code>Decoder</code></a> types.
967</p>
968
969<p>
970When marshaling or unmarshaling values, the format of supported flags in
971field tags has changed to be closer to the
972<a href="/pkg/encoding/json"><code>json</code></a> package
973(<code>`xml:"name,flag"`</code>). The matching done between field tags, field
974names, and the XML attribute and element names is now case-sensitive.
975The <code>XMLName</code> field tag, if present, must also match the name
976of the XML element being marshaled.
977</p>
978
979<p>
980<em>Updating</em>:
981Running <code>go fix</code> will update most uses of the package except for some calls to
982<code>Unmarshal</code>. Special care must be taken with field tags,
983since the fix tool will not update them and if not fixed by hand they will
984misbehave silently in some cases. For example, the old
985<code>"attr"</code> is now written <code>",attr"</code> while plain
986<code>"attr"</code> remains valid but with a different meaning.
987</p>
988
David Symonds715588f2012-02-04 14:32:05 +1100989<h3 id="expvar">The expvar package</h3>
990
991<p>
992In Go 1, the <code>RemoveAll</code> function has been removed.
993The <code>Iter</code> function and Iter method on <code>*Map</code> have
994been replaced by
995<a href="/pkg/expvar/#Do"><code>Do</code></a>
996and
997<a href="/pkg/expvar/#Map.Do"><code>(*Map).Do</code></a>.
998</p>
999
1000<p>
1001<em>Updating</em>:
1002Most code using <code>expvar</code> will not need changing. The rare code that used
David Symonds2943ca6b2012-02-04 21:55:38 +11001003<code>Iter</code> can be updated to pass a closure to <code>Do</code> to achieve the same effect.
David Symonds715588f2012-02-04 14:32:05 +11001004</p>
1005
Rob Pike531ded92012-01-20 15:38:03 -08001006<h3 id="flag">The flag package</h3>
1007
1008<p>
1009In Go 1, the interface <a href="/pkg/flag/#Value"><code>flag.Value</code></a> has changed slightly.
1010The <code>Set</code> method now returns an <code>error</code> instead of
1011a <code>bool</code> to indicate success or failure.
1012</p>
1013
1014<p>
1015There is also a new kind of flag, <code>Duration</code>, to support argument
1016values specifying time intervals.
1017Values for such flags must be given units, just as <code>time.Duration</code>
1018formats them: <code>10s</code>, <code>1h30m</code>, etc.
1019</p>
1020
1021<pre><!--{{code "progs/go1.go" `/timeout/`}}
1022-->var timeout = flag.Duration(&#34;timeout&#34;, 30*time.Second, &#34;how long to wait for completion&#34;)</pre>
1023
1024<p>
1025<em>Updating</em>:
1026Programs that implement their own flags will need minor manual fixes to update their
1027<code>Set</code> methods.
1028The <code>Duration</code> flag is new and affects no existing code.
1029</p>
1030
1031
Rob Pike0a1376a2012-01-20 14:28:48 -08001032<h3 id="go">The go/* packages</h3>
1033
1034<p>
1035Several packages under <code>go</code> have slightly revised APIs.
1036</p>
1037
1038<p>
1039The modes <code>AllowIllegalChars</code> and <code>InsertSemis</code> have been removed
1040from the <a href="/pkg/go/scanner/"><code>go/scanner</code></a> package. They were mostly
1041useful for scanning text other then Go source files. Instead, the
1042<a href="/pkg/text/scanner/"><code>text/scanner</code></a> package should be used
1043for that purpose.
1044</p>
1045
1046<p>
Robert Griesemerd08dd8b2012-02-08 11:41:32 -08001047The <a href="/pkg/go/scanner/#ErrorHandler"><code>ErrorHandler</code></a> provided
1048to the scanner's <a href="/pkg/go/scanner/#Scanner.Init"><code>Init</code></a> method is
1049now simply a function rather than an interface. The <code>ErrorVector</code> type has
1050been removed in favor of the (existing) <a href="/pkg/go/scanner/#ErrorList"><code>ErrorList</code></a>
1051type, and the <code>ErrorVector</code> methods have been migrated. Instead of embedding
1052an <code>ErrorVector</code> in a client of the scanner, now a client should maintain
1053an <code>ErrorList</code>.
1054</p>
1055
1056<p>
Rob Pike0a1376a2012-01-20 14:28:48 -08001057The set of parse functions provided by the <a href="/pkg/go/parser/"><code>go/parser</code></a>
1058package has been reduced to the primary parse function
Gustavo Niemeyer75e9d242012-01-25 23:42:36 -02001059<a href="/pkg/go/parser/#ParseFile"><code>ParseFile</code></a>, and a couple of
1060convenience functions <a href="/pkg/go/parser/#ParseDir"><code>ParseDir</code></a>
1061and <a href="/pkg/go/parser/#ParseExpr"><code>ParseExpr</code></a>.
Rob Pike0a1376a2012-01-20 14:28:48 -08001062</p>
1063
1064<p>
Gustavo Niemeyer75e9d242012-01-25 23:42:36 -02001065The type names of the <a href="/pkg/go/doc/"><code>go/doc</code></a> package have been
Rob Pike0a1376a2012-01-20 14:28:48 -08001066streamlined by removing the <code>Doc</code> suffix: <code>PackageDoc</code>
1067is now <code>Package</code>, <code>ValueDoc</code> is <code>Value</code>, etc.
1068Also, all types now consistently have a <code>Name</code> field (or <code>Names</code>,
Robert Griesemerd571c5c2012-01-25 16:48:06 -08001069in the case of type <code>Value</code>) and <code>Type.Factories</code> has become
1070<code>Type.Funcs</code>.
Rob Pike0a1376a2012-01-20 14:28:48 -08001071Instead of calling <code>doc.NewPackageDoc(pkg, importpath)</code>,
1072documentation for a package is created with:
1073</p>
1074
1075<pre>
1076 doc.New(pkg, importpath, mode)
1077</pre>
1078
1079<p>
1080where the new <code>mode</code> parameter specifies the operation mode:
Gustavo Niemeyer75e9d242012-01-25 23:42:36 -02001081if set to <a href="/pkg/go/doc/#AllDecls"><code>AllDecls</code></a>, all declarations
Rob Pike0a1376a2012-01-20 14:28:48 -08001082(not just exported ones) are considered.
1083The function <code>NewFileDoc</code> was removed, and the function
1084<code>CommentText</code> has become the method
Gustavo Niemeyer75e9d242012-01-25 23:42:36 -02001085<a href="/pkg/go/ast/#Text"><code>Text</code></a> of
1086<a href="/pkg/go/ast/#CommentGroup"><code>ast.CommentGroup</code></a>.
Rob Pike0a1376a2012-01-20 14:28:48 -08001087</p>
1088
1089<p>
Gustavo Niemeyer75e9d242012-01-25 23:42:36 -02001090In package <a href="/pkg/go/token/"><code>go/token</code></a>, the
1091<a href="/pkg/go/token/#FileSet"><code>token.FileSet</code></a> method <code>Files</code>
Rob Pike0a1376a2012-01-20 14:28:48 -08001092(which originally returned a channel of <code>*token.File</code>s) has been replaced
Gustavo Niemeyer75e9d242012-01-25 23:42:36 -02001093with the iterator <a href="/pkg/go/token/#FileSet.Iterate"><code>Iterate</code></a> that
Rob Pike0a1376a2012-01-20 14:28:48 -08001094accepts a function argument instead.
1095</p>
1096
1097<p>
1098<em>Updating</em>:
1099Code that uses packages in <code>go</code> will have to be updated by hand; the
1100compiler will reject incorrect uses. Templates used in conjuction with any of the
1101<code>go/doc</code> types may need manual fixes; the renamed fields will lead
1102to run-time errors.
1103</p>
1104
Russ Cox1f1c9ba2012-01-18 10:36:43 -05001105<h3 id="hash">The hash package</h3>
1106
1107<p>
1108In Go 1, the definition of <a href="/pkg/hash/#Hash"><code>hash.Hash</code></a> includes
1109a new method, <code>BlockSize</code>. This new method is used primarily in the
1110cryptographic libraries.
1111</p>
1112
1113<p>
Rob Pike03ea8b12012-01-24 16:36:40 -08001114The <code>Sum</code> method of the
1115<a href="/pkg/hash/#Hash"><code>hash.Hash</code></a> interface now takes a
1116<code>[]byte</code> argument, to which the hash value will be appended.
1117The previous behavior can be recreated by adding a <code>nil</code> argument to the call.
1118</p>
1119
1120<p>
Russ Cox1f1c9ba2012-01-18 10:36:43 -05001121<em>Updating</em>:
1122Existing implementations of <code>hash.Hash</code> will need to add a
1123<code>BlockSize</code> method. Hashes that process the input one byte at
1124a time can implement <code>BlockSize</code> to return 1.
Rob Pike27836912012-02-04 07:49:51 +11001125Running <code>go fix</code> will update calls to the <code>Sum</code> methods of the various
Rob Pike03ea8b12012-01-24 16:36:40 -08001126implementations of <code>hash.Hash</code>.
Rob Pikef76bd4f2011-12-12 19:25:25 -08001127</p>
1128
1129<p>
1130<em>Updating</em>:
1131Since the package's functionality is new, no updating is necessary.
1132</p>
1133
Rob Pikebab4dec2011-12-07 14:33:37 -08001134<h3 id="http">The http package</h3>
1135
Rob Pikef76bd4f2011-12-12 19:25:25 -08001136<p>
Jongmin Kim343098e2012-01-17 09:47:34 -08001137In Go 1 the <a href="/pkg/net/http/"><code>http</code></a> package is refactored,
Rob Pikef76bd4f2011-12-12 19:25:25 -08001138putting some of the utilities into a
Jongmin Kim343098e2012-01-17 09:47:34 -08001139<a href="/pkg/net/httputil/"><code>httputil</code></a> subdirectory.
Rob Pikef76bd4f2011-12-12 19:25:25 -08001140These pieces are only rarely needed by HTTP clients.
1141The affected items are:
1142</p>
1143
1144<ul>
1145<li>ClientConn</li>
1146<li>DumpRequest</li>
1147<li>DumpRequest</li>
1148<li>DumpRequestOut</li>
1149<li>DumpResponse</li>
1150<li>NewChunkedReader</li>
1151<li>NewChunkedWriter</li>
1152<li>NewClientConn</li>
1153<li>NewProxyClientConn</li>
1154<li>NewServerConn</li>
1155<li>NewSingleHostReverseProxy</li>
1156<li>ReverseProxy</li>
1157<li>ServerConn</li>
1158</ul>
1159
1160<p>
Russ Coxd0dc6892012-02-08 13:50:00 -05001161The <code>Request.RawURL</code> field has been removed; it was a
Rob Pikef76bd4f2011-12-12 19:25:25 -08001162historical artifact.
1163</p>
1164
1165<p>
Russ Coxd0dc6892012-02-08 13:50:00 -05001166The <code>Handle</code> and <code>HandleFunc</code>
1167functions, and the similarly-named methods of <code>ServeMux</code>,
1168now panic if an attempt is made to register the same pattern twice.
1169</p>
1170
1171<p>
Rob Pikef76bd4f2011-12-12 19:25:25 -08001172<em>Updating</em>:
Rob Pike27836912012-02-04 07:49:51 +11001173Running <code>go fix</code> will update the few programs that are affected except for
Rob Pikef76bd4f2011-12-12 19:25:25 -08001174uses of <code>RawURL</code>, which must be fixed by hand.
1175</p>
1176
Rob Pike2257e762012-01-23 16:11:49 -08001177<h3 id="image">The image package</h3>
1178
1179<p>
1180The <a href="/pkg/image/"><code>image</code></a> package has had a number of
1181minor changes, rearrangements and renamings.
1182</p>
1183
1184<p>
1185Most of the color handling code has been moved into its own package,
1186<a href="/pkg/image/color/"><code>image/color</code></a>.
1187For the elements that moved, a symmetry arises; for instance,
1188each pixel of an
1189<a href="/pkg/image/#RGBA"><code>image.RGBA</code></a>
1190is a
1191<a href="/pkg/image/color/#RGBA"><code>color.RGBA</code></a>.
1192</p>
1193
1194<p>
1195The old <code>image/ycbcr</code> package has been folded, with some
1196renamings, into the
1197<a href="/pkg/image/"><code>image</code></a>
1198and
1199<a href="/pkg/image/color/"><code>image/color</code></a>
1200packages.
1201</p>
1202
1203<p>
1204The old <code>image.ColorImage</code> type is still in the <code>image</code>
1205package but has been renamed
1206<a href="/pkg/image/#Uniform"><code>image.Uniform</code></a>,
Nigel Tao5e381d32012-02-08 11:41:47 +11001207while <code>image.Tiled</code> has been removed.
Rob Pike2257e762012-01-23 16:11:49 -08001208</p>
1209
1210<p>
1211This table lists the renamings.
1212</p>
1213
1214<table class="codetable" frame="border" summary="image renames">
1215<colgroup align="left" width="50%"></colgroup>
1216<colgroup align="left" width="50%"></colgroup>
1217<tr>
1218<th align="left">Old</th>
1219<th align="left">New</th>
1220</tr>
1221<tr>
1222<td colspan="2"><hr></td>
1223</tr>
1224<tr><td>image.Color</td> <td>color.Color</td></tr>
1225<tr><td>image.ColorModel</td> <td>color.Model</td></tr>
1226<tr><td>image.ColorModelFunc</td> <td>color.ModelFunc</td></tr>
1227<tr><td>image.PalettedColorModel</td> <td>color.Palette</td></tr>
1228<tr>
1229<td colspan="2"><hr></td>
1230</tr>
1231<tr><td>image.RGBAColor</td> <td>color.RGBA</td></tr>
1232<tr><td>image.RGBA64Color</td> <td>color.RGBA64</td></tr>
1233<tr><td>image.NRGBAColor</td> <td>color.NRGBA</td></tr>
1234<tr><td>image.NRGBA64Color</td> <td>color.NRGBA64</td></tr>
1235<tr><td>image.AlphaColor</td> <td>color.Alpha</td></tr>
1236<tr><td>image.Alpha16Color</td> <td>color.Alpha16</td></tr>
1237<tr><td>image.GrayColor</td> <td>color.Gray</td></tr>
1238<tr><td>image.Gray16Color</td> <td>color.Gray16</td></tr>
1239<tr>
1240<td colspan="2"><hr></td>
1241</tr>
1242<tr><td>image.RGBAColorModel</td> <td>color.RGBAModel</td></tr>
1243<tr><td>image.RGBA64ColorModel</td> <td>color.RGBA64Model</td></tr>
1244<tr><td>image.NRGBAColorModel</td> <td>color.NRGBAModel</td></tr>
1245<tr><td>image.NRGBA64ColorModel</td> <td>color.NRGBA64Model</td></tr>
1246<tr><td>image.AlphaColorModel</td> <td>color.AlphaModel</td></tr>
1247<tr><td>image.Alpha16ColorModel</td> <td>color.Alpha16Model</td></tr>
1248<tr><td>image.GrayColorModel</td> <td>color.GrayModel</td></tr>
1249<tr><td>image.Gray16ColorModel</td> <td>color.Gray16Model</td></tr>
1250<tr>
1251<td colspan="2"><hr></td>
1252</tr>
1253<tr><td>ycbcr.RGBToYCbCr</td> <td>color.RGBToYCbCr</td></tr>
1254<tr><td>ycbcr.YCbCrToRGB</td> <td>color.YCbCrToRGB</td></tr>
1255<tr><td>ycbcr.YCbCrColorModel</td> <td>color.YCbCrModel</td></tr>
1256<tr><td>ycbcr.YCbCrColor</td> <td>color.YCbCr</td></tr>
1257<tr><td>ycbcr.YCbCr</td> <td>image.YCbCr</td></tr>
1258<tr>
1259<td colspan="2"><hr></td>
1260</tr>
1261<tr><td>ycbcr.SubsampleRatio444</td> <td>image.YCbCrSubsampleRatio444</td></tr>
1262<tr><td>ycbcr.SubsampleRatio422</td> <td>image.YCbCrSubsampleRatio422</td></tr>
1263<tr><td>ycbcr.SubsampleRatio420</td> <td>image.YCbCrSubsampleRatio420</td></tr>
1264<tr>
1265<td colspan="2"><hr></td>
1266</tr>
1267<tr><td>image.ColorImage</td> <td>image.Uniform</td></tr>
Rob Pike2257e762012-01-23 16:11:49 -08001268</table>
1269
1270<p>
1271The image package's <code>New</code> functions
1272(<a href="/pkg/image/#NewRGBA"><code>NewRGBA</code></a>,
1273<a href="/pkg/image/#NewRGBA64"><code>NewRGBA64</code></a>, etc.)
1274take an <a href="/pkg/image/#Rectangle"><code>image.Rectangle</code></a> as an argument
1275instead of four integers.
1276</p>
1277
1278<p>
1279Finally, there are new predefined <code>color.Color</code> variables
1280<a href="/pkg/image/color/#Black"><code>color.Black</code></a>,
1281<a href="/pkg/image/color/#White"><code>color.White</code></a>,
1282<a href="/pkg/image/color/#Opaque"><code>color.Opaque</code></a>
1283and
1284<a href="/pkg/image/color/#Transparent"><code>color.Transparent</code></a>.
1285</p>
1286
1287<p>
1288<em>Updating</em>:
Rob Pike27836912012-02-04 07:49:51 +11001289Running <code>go fix</code> will update almost all code affected by the change.
Rob Pike2257e762012-01-23 16:11:49 -08001290</p>
1291
Rob Pike1c1ecd72012-02-09 14:40:56 +11001292<h3 id="log_syslog">The log/syslog package</h3>
1293
1294<p>
1295In Go 1, the <a href="/pkg/log/syslog/#NewLogger"><code>syslog.NewLogger</code></a>
1296function returns an error as well as a <code>log.Logger</code>.
1297</p>
1298
1299<p>
1300<em>Updating</em>:
1301What little code is affected will be caught by the compiler and must be updated by hand.
1302</p>
1303
Rob Pikedd442a52012-01-24 17:02:06 -08001304<h3 id="mime">The mime package</h3>
1305
1306<p>
1307In Go 1, the <a href="/pkg/mime/#FormatMediaType"><code>FormatMediaType</code></a> function
1308of the <code>mime</code> package has been simplified to make it
1309consistent with
1310<a href="/pkg/mime/#ParseMediaType"><code>ParseMediaType</code></a>.
1311It now takes <code>"text/html"</code> rather than <code>"text"</code> and <code>"html"</code>.
1312</p>
1313
1314<p>
1315<em>Updating</em>:
1316What little code is affected will be caught by the compiler and must be updated by hand.
1317</p>
1318
Brad Fitzpatrickb71883e2012-01-18 16:24:06 -08001319<h3 id="net">The net package</h3>
1320
Rob Pike03ea8b12012-01-24 16:36:40 -08001321<p>
1322In Go 1, the various <code>SetTimeout</code>,
Brad Fitzpatrickb71883e2012-01-18 16:24:06 -08001323<code>SetReadTimeout</code>, and <code>SetWriteTimeout</code> methods
Rob Pike03ea8b12012-01-24 16:36:40 -08001324have been replaced with
1325<a href="/pkg/net/#IPConn.SetDeadline"><code>SetDeadline</code></a>,
1326<a href="/pkg/net/#IPConn.SetReadDeadline"><code>SetReadDeadline</code></a>, and
1327<a href="/pkg/net/#IPConn.SetWriteDeadline"><code>SetWriteDeadline</code></a>,
Brad Fitzpatrickb71883e2012-01-18 16:24:06 -08001328respectively. Rather than taking a timeout value in nanoseconds that
1329apply to any activity on the connection, the new methods set an
1330absolute deadline (as a <code>time.Time</code> value) after which
Rob Pike03ea8b12012-01-24 16:36:40 -08001331reads and writes will time out and no longer block.
1332</p>
1333
1334<p>
Mikio Hara2f63afd2012-02-01 01:53:26 +09001335There are also new functions
1336<a href="/pkg/net/#DialTimeout"><code>net.DialTimeout</code></a>
1337to simplify timing out dialing a network address and
1338<a href="/pkg/net/#ListenMulticastUDP"><code>net.ListenMulticastUDP</code></a>
1339to allow multicast UDP to listen concurrently across multiple listeners.
1340The <code>net.ListenMulticastUDP</code> function replaces the old
1341<code>JoinGroup</code> and <code>LeaveGroup</code> methods.
Rob Pike03ea8b12012-01-24 16:36:40 -08001342</p>
1343
1344<p>
1345<em>Updating</em>:
1346Code that uses the old methods will fail to compile and must be updated by hand.
Rob Pike27836912012-02-04 07:49:51 +11001347The semantic change makes it difficult for the fix tool to update automatically.
Rob Pike03ea8b12012-01-24 16:36:40 -08001348</p>
Brad Fitzpatrickb71883e2012-01-18 16:24:06 -08001349
Rob Pike0a1376a2012-01-20 14:28:48 -08001350<h3 id="os_fileinfo">The os.FileInfo type</h3>
1351
1352<p>
1353Go 1 redefines the <a href="/pkg/os/#FileInfo"><code>os.FileInfo</code></a> type,
1354changing it from a struct to an interface:
1355</p>
1356
1357<pre>
1358 type FileInfo interface {
1359 Name() string // base name of the file
1360 Size() int64 // length in bytes
1361 Mode() FileMode // file mode bits
1362 ModTime() time.Time // modification time
1363 IsDir() bool // abbreviation for Mode().IsDir()
1364 }
1365</pre>
1366
1367<p>
1368The file mode information has been moved into a subtype called
1369<a href="/pkg/os/#FileMode"><code>os.FileMode</code></a>,
1370a simple integer type with <code>IsDir</code>, <code>Perm</code>, and <code>String</code>
1371methods.
1372</p>
1373
1374<p>
1375The system-specific details of file modes and properties such as (on Unix)
1376i-number have been removed from <code>FileInfo</code> altogether.
1377Instead, each operating system's <code>os</code> package provides an
1378implementation of the <code>FileInfo</code> interface, <code>*os.FileStat</code>,
1379which in turn contains a <code>Sys</code> field that stores the
1380system-specific representation of file metadata.
1381For instance, to discover the i-number of a file on a Unix system, unpack
1382the <code>FileInfo</code> like this:
1383</p>
1384
1385<pre>
1386 fi, err := os.Stat("hello.go")
1387 if err != nil {
1388 log.Fatal(err)
1389 }
1390 // Make sure it's an implementation known to package os.
1391 fileStat, ok := fi.(*os.FileStat)
1392 if !ok {
1393 log.Fatal("hello.go: not an os File")
1394 }
1395 // Now check that it's a Unix file.
1396 unixStat, ok := fileStat.Sys.(*syscall.Stat_t)
1397 if !ok {
1398 log.Fatal("hello.go: not a Unix file")
1399 }
1400 fmt.Printf("file i-number: %d\n", unixStat.Ino)
1401</pre>
1402
1403<p>
1404Assuming (which is unwise) that <code>"hello.go"</code> is a Unix file,
1405the i-number expression could be contracted to
1406</p>
1407
1408<pre>
1409 fi.(*os.FileStat).Sys.(*syscall.Stat_t).Ino
1410</pre>
1411
1412<p>
1413The vast majority of uses of <code>FileInfo</code> need only the methods
1414of the standard interface.
1415</p>
1416
1417<p>
1418<em>Updating</em>:
Rob Pike27836912012-02-04 07:49:51 +11001419Running <code>go fix</code> will update code that uses the old equivalent of the current <code>os.FileInfo</code>
Rob Pike0a1376a2012-01-20 14:28:48 -08001420and <code>os.FileMode</code> API.
1421Code that needs system-specific file details will need to be updated by hand.
1422</p>
1423
Rob Pikedd442a52012-01-24 17:02:06 -08001424<h3 id="path_filepath">The path/filepath package</h3>
1425
1426<p>
1427In Go 1, the <a href="/pkg/path/filepath/#Walk"><code>Walk</code></a> function of the
1428<code>path/filepath</code> package
1429has been changed to take a function value of type
1430<a href="/pkg/path/filepath/#WalkFunc"><code>WalkFunc</code></a>
1431instead of a <code>Visitor</code> interface value.
1432<code>WalkFunc</code> unifies the handling of both files and directories.
1433</p>
1434
1435<pre>
1436 type WalkFunc func(path string, info *os.FileInfo, err os.Error) os.Error
1437</pre>
1438
1439<p>
1440The <code>WalkFunc</code> function will be called even for files or directories that could not be opened;
1441in such cases the error argument will describe the failure.
1442If a directory's contents are to be skipped,
1443the function should return the value <code>SkipDir</code>.
1444</p>
1445
1446<p>
1447<font color="red">TODO: add an example?</font>
1448</p>
1449
1450<p>
1451<em>Updating</em>:
1452The change simplifies most code but has subtle consequences, so affected programs
1453will need to be updated by hand.
1454The compiler will catch code using the old interface.
1455</p>
1456
Rob Pike531ded92012-01-20 15:38:03 -08001457<h3 id="runtime">The runtime package</h3>
1458
1459<p>
1460The <code>runtime</code> package in Go 1 includes a new niladic function,
1461<a href="/pkg/runtime/#NumCPU"><code>runtime.NumCPU</code></a>, that returns the number of CPUs available
1462for parallel execution, as reported by the operating system kernel.
1463Its value can inform the setting of <code>GOMAXPROCS</code>.
1464</p>
1465
1466<p>
1467<em>Updating</em>:
1468No existing code is affected.
1469</p>
1470
Rob Pikebab4dec2011-12-07 14:33:37 -08001471<h3 id="strconv">The strconv package</h3>
1472
Rob Pike71ccf732011-12-09 14:12:51 -08001473<p>
1474In Go 1, the
Rob Pikeebdcbf12011-12-12 12:26:56 -08001475<a href="/pkg/strconv/"><code>strconv</code></a>
Rob Pike71ccf732011-12-09 14:12:51 -08001476package has been significantly reworked to make it more Go-like and less C-like,
1477although <code>Atoi</code> lives on (it's similar to
1478<code>int(ParseInt(x, 10, 0))</code>, as does
1479<code>Itoa(x)</code> (<code>FormatInt(int64(x), 10)</code>).
1480There are also new variants of some of the functions that append to byte slices rather than
1481return strings, to allow control over allocation.
1482</p>
1483
1484<p>
1485This table summarizes the renamings; see the
Rob Pikeebdcbf12011-12-12 12:26:56 -08001486<a href="/pkg/strconv/">package documentation</a>
Rob Pike71ccf732011-12-09 14:12:51 -08001487for full details.
1488</p>
1489
1490<table class="codetable" frame="border" summary="strconv renames">
1491<colgroup align="left" width="50%"></colgroup>
1492<colgroup align="left" width="50%"></colgroup>
1493<tr>
1494<th align="left">Old call</th>
1495<th align="left">New call</th>
1496</tr>
1497<tr>
1498<td colspan="2"><hr></td>
1499</tr>
1500<tr><td>Atob(x)</td> <td>ParseBool(x)</td></tr>
1501<tr>
1502<td colspan="2"><hr></td>
1503</tr>
1504<tr><td>Atof32(x)</td> <td>ParseFloat(x, 32)§</td></tr>
1505<tr><td>Atof64(x)</td> <td>ParseFloat(x, 64)</td></tr>
1506<tr><td>AtofN(x, n)</td> <td>ParseFloat(x, n)</td></tr>
1507<tr>
1508<td colspan="2"><hr></td>
1509</tr>
1510<tr><td>Atoi(x)</td> <td>Atoi(x)</td></tr>
1511<tr><td>Atoi(x)</td> <td>ParseInt(x, 10, 0)§</td></tr>
1512<tr><td>Atoi64(x)</td> <td>ParseInt(x, 10, 64)</td></tr>
1513<tr>
1514<td colspan="2"><hr></td>
1515</tr>
1516<tr><td>Atoui(x)</td> <td>ParseUint(x, 10, 0)§</td></tr>
1517<tr><td>Atoi64(x)</td> <td>ParseInt(x, 10, 64)</td></tr>
1518<tr>
1519<td colspan="2"><hr></td>
1520</tr>
1521<tr><td>Btoi64(x, b)</td> <td>ParseInt(x, b, 64)</td></tr>
1522<tr><td>Btoui64(x, b)</td> <td>ParseUint(x, b, 64)</td></tr>
1523<tr>
1524<td colspan="2"><hr></td>
1525</tr>
1526<tr><td>Btoa(x)</td> <td>FormatBool(x)</td></tr>
1527<tr>
1528<td colspan="2"><hr></td>
1529</tr>
1530<tr><td>Ftoa32(x, f, p)</td> <td>FormatFloat(x, float64(f), p, 32)</td></tr>
1531<tr><td>Ftoa64(x, f, p)</td> <td>FormatFloat(x, f, p, 64)</td></tr>
1532<tr><td>FtoaN(x, f, p, n)</td> <td>FormatFloat(x, f, p, n)</td></tr>
1533<tr>
1534<td colspan="2"><hr></td>
1535</tr>
1536<tr><td>Itoa(x)</td> <td>Itoa(x)</td></tr>
1537<tr><td>Itoa(x)</td> <td>FormatInt(int64(x), 10)</td></tr>
1538<tr><td>Itoa64(x)</td> <td>FormatInt(x, 10)</td></tr>
1539<tr>
1540<td colspan="2"><hr></td>
1541</tr>
1542<tr><td>Itob(x, b)</td> <td>FormatInt(int64(x), b)</td></tr>
1543<tr><td>Itob64(x, b)</td> <td>FormatInt(x, b)</td></tr>
1544<tr>
1545<td colspan="2"><hr></td>
1546</tr>
1547<tr><td>Uitoa(x)</td> <td>FormatUint(uint64(x), 10)</td></tr>
1548<tr><td>Uitoa64(x)</td> <td>FormatUint(x, 10)</td></tr>
1549<tr>
1550<td colspan="2"><hr></td>
1551</tr>
1552<tr><td>Uitob(x, b)</td> <td>FormatUint(uint64(x), b)</td></tr>
1553<tr><td>Uitob64(x, b)</td> <td>FormatUint(x, b)</td></tr>
1554</table>
1555
1556<p>
1557<em>Updating</em>:
Rob Pike27836912012-02-04 07:49:51 +11001558Running <code>go fix</code> will update almost all code affected by the change.
Rob Pike71ccf732011-12-09 14:12:51 -08001559<br>
1560§ <code>Atoi</code> persists but <code>Atoui</code> and <code>Atof32</code> do not, so
1561they may require
Rob Pike27836912012-02-04 07:49:51 +11001562a cast that must be added by hand; the go fix tool will warn about it.
Rob Pike71ccf732011-12-09 14:12:51 -08001563</p>
1564
Rob Pikebab4dec2011-12-07 14:33:37 -08001565
Rob Pike531ded92012-01-20 15:38:03 -08001566<h3 id="testing">The testing package</h3>
1567
1568<p>
1569The testing package has a type, <code>B</code>, passed as an argument to benchmark functions.
1570In Go 1, <code>B</code> has new methods, analogous to those of <code>T</code>, enabling
1571logging and failure reporting.
1572</p>
1573
1574<pre><!--{{code "progs/go1.go" `/func.*Benchmark/` `/^}/`}}
1575-->func BenchmarkSprintf(b *testing.B) {
1576 // Verify correctness before running benchmark.
1577 b.StopTimer()
1578 got := fmt.Sprintf(&#34;%x&#34;, 23)
1579 const expect = &#34;17&#34;
1580 if expect != got {
1581 b.Fatalf(&#34;expected %q; got %q&#34;, expect, got)
1582 }
1583 b.StartTimer()
1584 for i := 0; i &lt; b.N; i++ {
1585 fmt.Sprintf(&#34;%x&#34;, 23)
1586 }
1587}</pre>
1588
1589<p>
1590<em>Updating</em>:
1591Existing code is unaffected, although benchmarks that use <code>println</code>
Rob Pike2257e762012-01-23 16:11:49 -08001592or <code>panic</code> should be updated to use the new methods.
Rob Pike531ded92012-01-20 15:38:03 -08001593</p>
1594
Gustavo Niemeyer805d6202012-01-25 23:11:25 -02001595<h3 id="url">The url package</h3>
1596
1597<p>
Gustavo Niemeyer7b504852012-01-26 00:59:50 -02001598In Go 1 several fields from the <a href="/pkg/net/url/#URL"><code>url.URL</code></a> type
Gustavo Niemeyer805d6202012-01-25 23:11:25 -02001599were removed or replaced.
1600</p>
1601
1602<p>
Gustavo Niemeyer7b504852012-01-26 00:59:50 -02001603The <a href="/pkg/net/url/#URL.String"><code>String</code></a> method now
Gustavo Niemeyer805d6202012-01-25 23:11:25 -02001604predictably rebuilds an encoded URL string using all of <code>URL</code>'s
1605fields as necessary. The resulting string will also no longer have
1606passwords escaped.
1607</p>
1608
1609<p>
1610The <code>Raw</code> field has been removed. In most cases the <code>String</code>
1611method may be used in its place.
1612</p>
1613
1614<p>
1615The old <code>RawUserinfo</code> field is replaced by the <code>User</code>
Gustavo Niemeyer7b504852012-01-26 00:59:50 -02001616field, of type <a href="/pkg/net/url/#Userinfo"><code>*net.Userinfo</code></a>.
1617Values of this type may be created using the new <a href="/pkg/net/url/#User"><code>net.User</code></a>
1618and <a href="/pkg/net/url/#UserPassword"><code>net.UserPassword</code></a>
Gustavo Niemeyer805d6202012-01-25 23:11:25 -02001619functions. The <code>EscapeUserinfo</code> and <code>UnescapeUserinfo</code>
1620functions are also gone.
1621</p>
1622
1623<p>
1624The <code>RawAuthority</code> field has been removed. The same information is
1625available in the <code>Host</code> and <code>User</code> fields.
1626</p>
1627
1628<p>
1629The <code>RawPath</code> field and the <code>EncodedPath</code> method have
1630been removed. The path information in rooted URLs (with a slash following the
1631schema) is now available only in decoded form in the <code>Path</code> field.
1632Occasionally, the encoded data may be required to obtain information that
1633was lost in the decoding process. These cases must be handled by accessing
1634the data the URL was built from.
1635</p>
1636
1637<p>
1638URLs with non-rooted paths, such as <code>"mailto:dev@golang.org?subject=Hi"</code>,
1639are also handled differently. The <code>OpaquePath</code> boolean field has been
1640removed and a new <code>Opaque</code> string field introduced to hold the encoded
1641path for such URLs. In Go 1, the cited URL parses as:
1642</p>
1643
1644<pre>
1645 URL{
1646 Scheme: "mailto",
1647 Opaque: "dev@golang.org",
1648 RawQuery: "subject=Hi",
1649 }
1650</pre>
1651
1652<p>
Gustavo Niemeyer7b504852012-01-26 00:59:50 -02001653A new <a href="/pkg/net/url/#URL.RequestURI"><code>RequestURI</code></a> method was
Gustavo Niemeyer805d6202012-01-25 23:11:25 -02001654added to <code>URL</code>.
1655</p>
1656
1657<p>
1658<em>Updating</em>:
1659Code that uses the old fields will fail to compile and must be updated by hand.
Rob Pike27836912012-02-04 07:49:51 +11001660The semantic changes make it difficult for the fix tool to update automatically.
Gustavo Niemeyer805d6202012-01-25 23:11:25 -02001661</p>
1662
Rob Pikebab4dec2011-12-07 14:33:37 -08001663<h2 id="go_command">The go command</h2>
1664
1665<h2 id="releases">Packaged releases</h2>
1666