blob: 6e63882f09f95c553f2b7ca1fe550822d9ea0f69 [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
Nigel Taocc9ed442012-02-10 18:49:19 +1100881<h3 id="bufio">The compress/flate, compress/gzip and compress/zlib packages</h3>
882
883<p>
Nigel Tao22636be2012-02-11 12:09:11 +1100884In Go 1, the <code>NewWriterXxx</code> functions in
885<a href="/pkg/compress/flate"><code>compress/flate</code></a>,
886<a href="/pkg/compress/gzip"><code>compress/gzip</code></a> and
887<a href="/pkg/compress/zlib"><code>compress/zlib</code></a>
888all return <code>(*Writer, error)</code> if they take a compression level,
889and <code>*Writer</code> otherwise. Package <code>gzip</code>'s
890<code>Compressor</code> and <code>Decompressor</code> types have been renamed
891to <code>Writer</code> and <code>Reader</code>. Package <code>flate</code>'s
892<code>WrongValueError</code> type has been removed.
Nigel Taocc9ed442012-02-10 18:49:19 +1100893</p>
894
895<p>
896<em>Updating</em>:
897What little code is affected will be caught by the compiler and must be updated by hand.
898</p>
899
Rob Pike0a1376a2012-01-20 14:28:48 -0800900<h3 id="crypto_elliptic">The crypto/elliptic package</h3>
901
902<p>
903In Go 1, <a href="/pkg/crypto/elliptic/#Curve"><code>elliptic.Curve</code></a>
904has been made an interface to permit alternative implementations. The curve
905parameters have been moved to the
906<a href="/pkg/crypto/elliptic/#CurveParams"><code>elliptic.CurveParams</code></a>
907structure.
908</p>
909
910<p>
911<em>Updating</em>:
912Existing users of <code>*elliptic.Curve</code> will need to change to
913simply <code>elliptic.Curve</code>. Calls to <code>Marshal</code>,
914<code>Unmarshal</code> and <code>GenerateKey</code> are now functions
915in <code>crypto/elliptic</code> that take an <code>elliptic.Curve</code>
916as their first argument.
917</p>
918
Rob Pike27836912012-02-04 07:49:51 +1100919<h3 id="crypto_hmac">The crypto/hmac package</h3>
Adam Langley68aff952012-01-27 10:12:27 -0800920
921<p>
922In Go 1, the hash-specific functions, such as <code>hmac.NewMD5</code>, have
923been removed from <code>crypto/hmac</code>. Instead, <code>hmac.New</code> takes
924a function that returns a <code>hash.Hash</code>, such as <code>md5.New</code>.
925</p>
926
927<p>
928<em>Updating</em>:
Rob Pike27836912012-02-04 07:49:51 +1100929Running <code>go fix</code> will perform the needed changes.
Adam Langley68aff952012-01-27 10:12:27 -0800930</p>
931
Rob Pike0a1376a2012-01-20 14:28:48 -0800932<h3 id="crypto_x509">The crypto/x509 package</h3>
933
934<p>
935In Go 1, the
936<a href="/pkg/crypto/x509/#CreateCertificate"><code>CreateCertificate</code></a>
937and
938<a href="/pkg/crypto/x509/#CreateCRL"><code>CreateCRL</code></a>
939functions in <code>crypto/x509</code> have been altered to take an
940<code>interface{}</code> where they previously took a <code>*rsa.PublicKey</code>
941or <code>*rsa.PrivateKey</code>. This will allow other public key algorithms
942to be implemented in the future.
943</p>
944
945<p>
946<em>Updating</em>:
947No changes will be needed.
948</p>
949
Rob Pike52ebadd2012-02-08 14:09:20 +1100950<h3 id="encoding_binary">The encoding/binary package</h3>
951
952<p>
Rob Pike1c1ecd72012-02-09 14:40:56 +1100953In Go 1, the <code>binary.TotalSize</code> function has been replaced by
954<a href="/pkg/encoding/binary/#Size"><code>Size</code></a>,
955which takes an <code>interface{}</code> argument rather than
956a <code>reflect.Value</code>.
Rob Pike52ebadd2012-02-08 14:09:20 +1100957</p>
958
959<p>
960<em>Updating</em>:
Rob Pikecf80ccd2012-02-09 07:09:52 +1100961What little code is affected will be caught by the compiler and must be updated by hand.
Rob Pike52ebadd2012-02-08 14:09:20 +1100962</p>
963
964<h3 id="encoding_xml">The encoding/xml package</h3>
965
966<p>
967In Go 1, the <a href="/pkg/encoding/xml/"><code>xml</code></a> package
968has been brought closer in design to the other marshaling packages such
969as <a href="/pkg/encoding/gob/"><code>encoding/gob</code></a>.
970</p>
971
972<p>
973The old <code>Parser</code> type is renamed
974<a href="/pkg/encoding/xml/#Decoder"><code>Decoder</code></a> and has a new
975<a href="/pkg/encoding/xml/#Decoder.Decode"><code>Decode</code></a> method. An
976<a href="/pkg/encoding/xml/#Encoder"><code>Encoder</code></a> type was also
977introduced.
978</p>
979
980<p>
981The functions <a href="/pkg/encoding/xml/#Marshal"><code>Marshal</code></a>
982and <a href="/pkg/encoding/xml/#Unmarshal"><code>Unmarshal</code></a>
983work with <code>[]byte</code> values now. To work with streams,
984use the new <a href="/pkg/encoding/xml/#Encoder"><code>Encoder</code></a>
985and <a href="/pkg/encoding/xml/#Decoder"><code>Decoder</code></a> types.
986</p>
987
988<p>
989When marshaling or unmarshaling values, the format of supported flags in
990field tags has changed to be closer to the
991<a href="/pkg/encoding/json"><code>json</code></a> package
992(<code>`xml:"name,flag"`</code>). The matching done between field tags, field
993names, and the XML attribute and element names is now case-sensitive.
994The <code>XMLName</code> field tag, if present, must also match the name
995of the XML element being marshaled.
996</p>
997
998<p>
999<em>Updating</em>:
1000Running <code>go fix</code> will update most uses of the package except for some calls to
1001<code>Unmarshal</code>. Special care must be taken with field tags,
1002since the fix tool will not update them and if not fixed by hand they will
1003misbehave silently in some cases. For example, the old
1004<code>"attr"</code> is now written <code>",attr"</code> while plain
1005<code>"attr"</code> remains valid but with a different meaning.
1006</p>
1007
David Symonds715588f2012-02-04 14:32:05 +11001008<h3 id="expvar">The expvar package</h3>
1009
1010<p>
1011In Go 1, the <code>RemoveAll</code> function has been removed.
1012The <code>Iter</code> function and Iter method on <code>*Map</code> have
1013been replaced by
1014<a href="/pkg/expvar/#Do"><code>Do</code></a>
1015and
1016<a href="/pkg/expvar/#Map.Do"><code>(*Map).Do</code></a>.
1017</p>
1018
1019<p>
1020<em>Updating</em>:
1021Most code using <code>expvar</code> will not need changing. The rare code that used
David Symonds2943ca6b2012-02-04 21:55:38 +11001022<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 +11001023</p>
1024
Rob Pike531ded92012-01-20 15:38:03 -08001025<h3 id="flag">The flag package</h3>
1026
1027<p>
1028In Go 1, the interface <a href="/pkg/flag/#Value"><code>flag.Value</code></a> has changed slightly.
1029The <code>Set</code> method now returns an <code>error</code> instead of
1030a <code>bool</code> to indicate success or failure.
1031</p>
1032
1033<p>
1034There is also a new kind of flag, <code>Duration</code>, to support argument
1035values specifying time intervals.
1036Values for such flags must be given units, just as <code>time.Duration</code>
1037formats them: <code>10s</code>, <code>1h30m</code>, etc.
1038</p>
1039
1040<pre><!--{{code "progs/go1.go" `/timeout/`}}
1041-->var timeout = flag.Duration(&#34;timeout&#34;, 30*time.Second, &#34;how long to wait for completion&#34;)</pre>
1042
1043<p>
1044<em>Updating</em>:
1045Programs that implement their own flags will need minor manual fixes to update their
1046<code>Set</code> methods.
1047The <code>Duration</code> flag is new and affects no existing code.
1048</p>
1049
1050
Rob Pike0a1376a2012-01-20 14:28:48 -08001051<h3 id="go">The go/* packages</h3>
1052
1053<p>
1054Several packages under <code>go</code> have slightly revised APIs.
1055</p>
1056
1057<p>
Robert Griesemerf8cf82f2012-02-10 13:27:32 -08001058A concrete <code>Mode</code> type was introduced for configuration mode flags
1059in the packages
1060<a href="/pkg/go/scanner/"><code>go/scanner</code></a>,
1061<a href="/pkg/go/parser/"><code>go/parser</code></a>,
1062<a href="/pkg/go/printer/"><code>go/printer</code></a>, and
1063<a href="/pkg/go/doc/"><code>go/doc</code></a>.
1064</p>
1065
1066<p>
Rob Pike0a1376a2012-01-20 14:28:48 -08001067The modes <code>AllowIllegalChars</code> and <code>InsertSemis</code> have been removed
1068from the <a href="/pkg/go/scanner/"><code>go/scanner</code></a> package. They were mostly
1069useful for scanning text other then Go source files. Instead, the
1070<a href="/pkg/text/scanner/"><code>text/scanner</code></a> package should be used
1071for that purpose.
1072</p>
1073
1074<p>
Robert Griesemerd08dd8b2012-02-08 11:41:32 -08001075The <a href="/pkg/go/scanner/#ErrorHandler"><code>ErrorHandler</code></a> provided
1076to the scanner's <a href="/pkg/go/scanner/#Scanner.Init"><code>Init</code></a> method is
1077now simply a function rather than an interface. The <code>ErrorVector</code> type has
1078been removed in favor of the (existing) <a href="/pkg/go/scanner/#ErrorList"><code>ErrorList</code></a>
1079type, and the <code>ErrorVector</code> methods have been migrated. Instead of embedding
1080an <code>ErrorVector</code> in a client of the scanner, now a client should maintain
1081an <code>ErrorList</code>.
1082</p>
1083
1084<p>
Rob Pike0a1376a2012-01-20 14:28:48 -08001085The set of parse functions provided by the <a href="/pkg/go/parser/"><code>go/parser</code></a>
1086package has been reduced to the primary parse function
Gustavo Niemeyer75e9d242012-01-25 23:42:36 -02001087<a href="/pkg/go/parser/#ParseFile"><code>ParseFile</code></a>, and a couple of
1088convenience functions <a href="/pkg/go/parser/#ParseDir"><code>ParseDir</code></a>
1089and <a href="/pkg/go/parser/#ParseExpr"><code>ParseExpr</code></a>.
Rob Pike0a1376a2012-01-20 14:28:48 -08001090</p>
1091
1092<p>
Robert Griesemerf8cf82f2012-02-10 13:27:32 -08001093The <a href="/pkg/go/printer/"><code>go/printer</code></a> package supports an additional
1094configuration mode <a href="/pkg/go/printer/#Mode"><code>SourcePos</code></a>;
1095if set, the printer will emit <code>//line</code> comments such that the generated
1096output contains the original source code position information. The new type
1097<a href="/pkg/go/printer/#CommentedNode"><code>CommentedNode</code></a> can be
1098used to provide comments associated with an arbitrary
1099<a href="/pkg/go/ast/#Node"><code>ast.Node</code></a> (until now only
1100<a href="/pkg/go/ast/#File"><code>ast.File</code></a> carried comment information).
1101</p>
1102
1103<p>
Gustavo Niemeyer75e9d242012-01-25 23:42:36 -02001104The type names of the <a href="/pkg/go/doc/"><code>go/doc</code></a> package have been
Rob Pike0a1376a2012-01-20 14:28:48 -08001105streamlined by removing the <code>Doc</code> suffix: <code>PackageDoc</code>
1106is now <code>Package</code>, <code>ValueDoc</code> is <code>Value</code>, etc.
1107Also, all types now consistently have a <code>Name</code> field (or <code>Names</code>,
Robert Griesemerd571c5c2012-01-25 16:48:06 -08001108in the case of type <code>Value</code>) and <code>Type.Factories</code> has become
1109<code>Type.Funcs</code>.
Rob Pike0a1376a2012-01-20 14:28:48 -08001110Instead of calling <code>doc.NewPackageDoc(pkg, importpath)</code>,
1111documentation for a package is created with:
1112</p>
1113
1114<pre>
1115 doc.New(pkg, importpath, mode)
1116</pre>
1117
1118<p>
1119where the new <code>mode</code> parameter specifies the operation mode:
Gustavo Niemeyer75e9d242012-01-25 23:42:36 -02001120if set to <a href="/pkg/go/doc/#AllDecls"><code>AllDecls</code></a>, all declarations
Rob Pike0a1376a2012-01-20 14:28:48 -08001121(not just exported ones) are considered.
1122The function <code>NewFileDoc</code> was removed, and the function
1123<code>CommentText</code> has become the method
Gustavo Niemeyer75e9d242012-01-25 23:42:36 -02001124<a href="/pkg/go/ast/#Text"><code>Text</code></a> of
1125<a href="/pkg/go/ast/#CommentGroup"><code>ast.CommentGroup</code></a>.
Rob Pike0a1376a2012-01-20 14:28:48 -08001126</p>
1127
1128<p>
Gustavo Niemeyer75e9d242012-01-25 23:42:36 -02001129In package <a href="/pkg/go/token/"><code>go/token</code></a>, the
1130<a href="/pkg/go/token/#FileSet"><code>token.FileSet</code></a> method <code>Files</code>
Rob Pike0a1376a2012-01-20 14:28:48 -08001131(which originally returned a channel of <code>*token.File</code>s) has been replaced
Gustavo Niemeyer75e9d242012-01-25 23:42:36 -02001132with the iterator <a href="/pkg/go/token/#FileSet.Iterate"><code>Iterate</code></a> that
Rob Pike0a1376a2012-01-20 14:28:48 -08001133accepts a function argument instead.
1134</p>
1135
1136<p>
1137<em>Updating</em>:
1138Code that uses packages in <code>go</code> will have to be updated by hand; the
1139compiler will reject incorrect uses. Templates used in conjuction with any of the
1140<code>go/doc</code> types may need manual fixes; the renamed fields will lead
1141to run-time errors.
1142</p>
1143
Russ Cox1f1c9ba2012-01-18 10:36:43 -05001144<h3 id="hash">The hash package</h3>
1145
1146<p>
1147In Go 1, the definition of <a href="/pkg/hash/#Hash"><code>hash.Hash</code></a> includes
1148a new method, <code>BlockSize</code>. This new method is used primarily in the
1149cryptographic libraries.
1150</p>
1151
1152<p>
Rob Pike03ea8b12012-01-24 16:36:40 -08001153The <code>Sum</code> method of the
1154<a href="/pkg/hash/#Hash"><code>hash.Hash</code></a> interface now takes a
1155<code>[]byte</code> argument, to which the hash value will be appended.
1156The previous behavior can be recreated by adding a <code>nil</code> argument to the call.
1157</p>
1158
1159<p>
Russ Cox1f1c9ba2012-01-18 10:36:43 -05001160<em>Updating</em>:
1161Existing implementations of <code>hash.Hash</code> will need to add a
1162<code>BlockSize</code> method. Hashes that process the input one byte at
1163a time can implement <code>BlockSize</code> to return 1.
Rob Pike27836912012-02-04 07:49:51 +11001164Running <code>go fix</code> will update calls to the <code>Sum</code> methods of the various
Rob Pike03ea8b12012-01-24 16:36:40 -08001165implementations of <code>hash.Hash</code>.
Rob Pikef76bd4f2011-12-12 19:25:25 -08001166</p>
1167
1168<p>
1169<em>Updating</em>:
1170Since the package's functionality is new, no updating is necessary.
1171</p>
1172
Rob Pikebab4dec2011-12-07 14:33:37 -08001173<h3 id="http">The http package</h3>
1174
Rob Pikef76bd4f2011-12-12 19:25:25 -08001175<p>
Jongmin Kim343098e2012-01-17 09:47:34 -08001176In Go 1 the <a href="/pkg/net/http/"><code>http</code></a> package is refactored,
Rob Pikef76bd4f2011-12-12 19:25:25 -08001177putting some of the utilities into a
Jongmin Kim343098e2012-01-17 09:47:34 -08001178<a href="/pkg/net/httputil/"><code>httputil</code></a> subdirectory.
Rob Pikef76bd4f2011-12-12 19:25:25 -08001179These pieces are only rarely needed by HTTP clients.
1180The affected items are:
1181</p>
1182
1183<ul>
1184<li>ClientConn</li>
1185<li>DumpRequest</li>
1186<li>DumpRequest</li>
1187<li>DumpRequestOut</li>
1188<li>DumpResponse</li>
1189<li>NewChunkedReader</li>
1190<li>NewChunkedWriter</li>
1191<li>NewClientConn</li>
1192<li>NewProxyClientConn</li>
1193<li>NewServerConn</li>
1194<li>NewSingleHostReverseProxy</li>
1195<li>ReverseProxy</li>
1196<li>ServerConn</li>
1197</ul>
1198
1199<p>
Russ Coxd0dc6892012-02-08 13:50:00 -05001200The <code>Request.RawURL</code> field has been removed; it was a
Rob Pikef76bd4f2011-12-12 19:25:25 -08001201historical artifact.
1202</p>
1203
1204<p>
Russ Coxd0dc6892012-02-08 13:50:00 -05001205The <code>Handle</code> and <code>HandleFunc</code>
1206functions, and the similarly-named methods of <code>ServeMux</code>,
1207now panic if an attempt is made to register the same pattern twice.
1208</p>
1209
1210<p>
Rob Pikef76bd4f2011-12-12 19:25:25 -08001211<em>Updating</em>:
Rob Pike27836912012-02-04 07:49:51 +11001212Running <code>go fix</code> will update the few programs that are affected except for
Rob Pikef76bd4f2011-12-12 19:25:25 -08001213uses of <code>RawURL</code>, which must be fixed by hand.
1214</p>
1215
Rob Pike2257e762012-01-23 16:11:49 -08001216<h3 id="image">The image package</h3>
1217
1218<p>
1219The <a href="/pkg/image/"><code>image</code></a> package has had a number of
1220minor changes, rearrangements and renamings.
1221</p>
1222
1223<p>
1224Most of the color handling code has been moved into its own package,
1225<a href="/pkg/image/color/"><code>image/color</code></a>.
1226For the elements that moved, a symmetry arises; for instance,
1227each pixel of an
1228<a href="/pkg/image/#RGBA"><code>image.RGBA</code></a>
1229is a
1230<a href="/pkg/image/color/#RGBA"><code>color.RGBA</code></a>.
1231</p>
1232
1233<p>
1234The old <code>image/ycbcr</code> package has been folded, with some
1235renamings, into the
1236<a href="/pkg/image/"><code>image</code></a>
1237and
1238<a href="/pkg/image/color/"><code>image/color</code></a>
1239packages.
1240</p>
1241
1242<p>
1243The old <code>image.ColorImage</code> type is still in the <code>image</code>
1244package but has been renamed
1245<a href="/pkg/image/#Uniform"><code>image.Uniform</code></a>,
Nigel Tao5e381d32012-02-08 11:41:47 +11001246while <code>image.Tiled</code> has been removed.
Rob Pike2257e762012-01-23 16:11:49 -08001247</p>
1248
1249<p>
1250This table lists the renamings.
1251</p>
1252
1253<table class="codetable" frame="border" summary="image renames">
1254<colgroup align="left" width="50%"></colgroup>
1255<colgroup align="left" width="50%"></colgroup>
1256<tr>
1257<th align="left">Old</th>
1258<th align="left">New</th>
1259</tr>
1260<tr>
1261<td colspan="2"><hr></td>
1262</tr>
1263<tr><td>image.Color</td> <td>color.Color</td></tr>
1264<tr><td>image.ColorModel</td> <td>color.Model</td></tr>
1265<tr><td>image.ColorModelFunc</td> <td>color.ModelFunc</td></tr>
1266<tr><td>image.PalettedColorModel</td> <td>color.Palette</td></tr>
1267<tr>
1268<td colspan="2"><hr></td>
1269</tr>
1270<tr><td>image.RGBAColor</td> <td>color.RGBA</td></tr>
1271<tr><td>image.RGBA64Color</td> <td>color.RGBA64</td></tr>
1272<tr><td>image.NRGBAColor</td> <td>color.NRGBA</td></tr>
1273<tr><td>image.NRGBA64Color</td> <td>color.NRGBA64</td></tr>
1274<tr><td>image.AlphaColor</td> <td>color.Alpha</td></tr>
1275<tr><td>image.Alpha16Color</td> <td>color.Alpha16</td></tr>
1276<tr><td>image.GrayColor</td> <td>color.Gray</td></tr>
1277<tr><td>image.Gray16Color</td> <td>color.Gray16</td></tr>
1278<tr>
1279<td colspan="2"><hr></td>
1280</tr>
1281<tr><td>image.RGBAColorModel</td> <td>color.RGBAModel</td></tr>
1282<tr><td>image.RGBA64ColorModel</td> <td>color.RGBA64Model</td></tr>
1283<tr><td>image.NRGBAColorModel</td> <td>color.NRGBAModel</td></tr>
1284<tr><td>image.NRGBA64ColorModel</td> <td>color.NRGBA64Model</td></tr>
1285<tr><td>image.AlphaColorModel</td> <td>color.AlphaModel</td></tr>
1286<tr><td>image.Alpha16ColorModel</td> <td>color.Alpha16Model</td></tr>
1287<tr><td>image.GrayColorModel</td> <td>color.GrayModel</td></tr>
1288<tr><td>image.Gray16ColorModel</td> <td>color.Gray16Model</td></tr>
1289<tr>
1290<td colspan="2"><hr></td>
1291</tr>
1292<tr><td>ycbcr.RGBToYCbCr</td> <td>color.RGBToYCbCr</td></tr>
1293<tr><td>ycbcr.YCbCrToRGB</td> <td>color.YCbCrToRGB</td></tr>
1294<tr><td>ycbcr.YCbCrColorModel</td> <td>color.YCbCrModel</td></tr>
1295<tr><td>ycbcr.YCbCrColor</td> <td>color.YCbCr</td></tr>
1296<tr><td>ycbcr.YCbCr</td> <td>image.YCbCr</td></tr>
1297<tr>
1298<td colspan="2"><hr></td>
1299</tr>
1300<tr><td>ycbcr.SubsampleRatio444</td> <td>image.YCbCrSubsampleRatio444</td></tr>
1301<tr><td>ycbcr.SubsampleRatio422</td> <td>image.YCbCrSubsampleRatio422</td></tr>
1302<tr><td>ycbcr.SubsampleRatio420</td> <td>image.YCbCrSubsampleRatio420</td></tr>
1303<tr>
1304<td colspan="2"><hr></td>
1305</tr>
1306<tr><td>image.ColorImage</td> <td>image.Uniform</td></tr>
Rob Pike2257e762012-01-23 16:11:49 -08001307</table>
1308
1309<p>
1310The image package's <code>New</code> functions
1311(<a href="/pkg/image/#NewRGBA"><code>NewRGBA</code></a>,
1312<a href="/pkg/image/#NewRGBA64"><code>NewRGBA64</code></a>, etc.)
1313take an <a href="/pkg/image/#Rectangle"><code>image.Rectangle</code></a> as an argument
1314instead of four integers.
1315</p>
1316
1317<p>
1318Finally, there are new predefined <code>color.Color</code> variables
1319<a href="/pkg/image/color/#Black"><code>color.Black</code></a>,
1320<a href="/pkg/image/color/#White"><code>color.White</code></a>,
1321<a href="/pkg/image/color/#Opaque"><code>color.Opaque</code></a>
1322and
1323<a href="/pkg/image/color/#Transparent"><code>color.Transparent</code></a>.
1324</p>
1325
1326<p>
1327<em>Updating</em>:
Rob Pike27836912012-02-04 07:49:51 +11001328Running <code>go fix</code> will update almost all code affected by the change.
Rob Pike2257e762012-01-23 16:11:49 -08001329</p>
1330
Rob Pike1c1ecd72012-02-09 14:40:56 +11001331<h3 id="log_syslog">The log/syslog package</h3>
1332
1333<p>
1334In Go 1, the <a href="/pkg/log/syslog/#NewLogger"><code>syslog.NewLogger</code></a>
1335function returns an error as well as a <code>log.Logger</code>.
1336</p>
1337
1338<p>
1339<em>Updating</em>:
1340What little code is affected will be caught by the compiler and must be updated by hand.
1341</p>
1342
Rob Pikedd442a52012-01-24 17:02:06 -08001343<h3 id="mime">The mime package</h3>
1344
1345<p>
1346In Go 1, the <a href="/pkg/mime/#FormatMediaType"><code>FormatMediaType</code></a> function
1347of the <code>mime</code> package has been simplified to make it
1348consistent with
1349<a href="/pkg/mime/#ParseMediaType"><code>ParseMediaType</code></a>.
1350It now takes <code>"text/html"</code> rather than <code>"text"</code> and <code>"html"</code>.
1351</p>
1352
1353<p>
1354<em>Updating</em>:
1355What little code is affected will be caught by the compiler and must be updated by hand.
1356</p>
1357
Brad Fitzpatrickb71883e2012-01-18 16:24:06 -08001358<h3 id="net">The net package</h3>
1359
Rob Pike03ea8b12012-01-24 16:36:40 -08001360<p>
1361In Go 1, the various <code>SetTimeout</code>,
Brad Fitzpatrickb71883e2012-01-18 16:24:06 -08001362<code>SetReadTimeout</code>, and <code>SetWriteTimeout</code> methods
Rob Pike03ea8b12012-01-24 16:36:40 -08001363have been replaced with
1364<a href="/pkg/net/#IPConn.SetDeadline"><code>SetDeadline</code></a>,
1365<a href="/pkg/net/#IPConn.SetReadDeadline"><code>SetReadDeadline</code></a>, and
1366<a href="/pkg/net/#IPConn.SetWriteDeadline"><code>SetWriteDeadline</code></a>,
Brad Fitzpatrickb71883e2012-01-18 16:24:06 -08001367respectively. Rather than taking a timeout value in nanoseconds that
1368apply to any activity on the connection, the new methods set an
1369absolute deadline (as a <code>time.Time</code> value) after which
Rob Pike03ea8b12012-01-24 16:36:40 -08001370reads and writes will time out and no longer block.
1371</p>
1372
1373<p>
Mikio Hara2f63afd2012-02-01 01:53:26 +09001374There are also new functions
1375<a href="/pkg/net/#DialTimeout"><code>net.DialTimeout</code></a>
1376to simplify timing out dialing a network address and
1377<a href="/pkg/net/#ListenMulticastUDP"><code>net.ListenMulticastUDP</code></a>
1378to allow multicast UDP to listen concurrently across multiple listeners.
1379The <code>net.ListenMulticastUDP</code> function replaces the old
1380<code>JoinGroup</code> and <code>LeaveGroup</code> methods.
Rob Pike03ea8b12012-01-24 16:36:40 -08001381</p>
1382
1383<p>
1384<em>Updating</em>:
1385Code that uses the old methods will fail to compile and must be updated by hand.
Rob Pike27836912012-02-04 07:49:51 +11001386The semantic change makes it difficult for the fix tool to update automatically.
Rob Pike03ea8b12012-01-24 16:36:40 -08001387</p>
Brad Fitzpatrickb71883e2012-01-18 16:24:06 -08001388
Brad Fitzpatrick7750fc82012-02-10 11:44:51 +11001389<h3 id="os">The os package</h3>
1390
1391<p>The <code>Time</code> function has been removed; callers should use
1392the <a href="/pkg/time/#Time"><code>Time</code></a> type from the
1393<code>time</code> package.</p>
1394
Brad Fitzpatrick4152b432012-02-10 14:16:15 +11001395<p>The <code>Exec</code> function has been removed; callers should use
1396<code>Exec</code> from the <code>syscall</code> package, where available.</p>
1397
1398<p>The <code>ShellExpand</code> function has been renamed to <a
1399href="/pkg/os/#ExpandEnv"><code>ExpandEnv</code></a>.</p>
1400
1401<p>The <a href="/pkg/os/#NewFile"><code>NewFile</code></a> function
1402now takes a <code>uintptr</code> fd, instead of an <code>int</code>.
1403The <a href="/pkg/os/#File.Fd"><code>Fd</code></a> method on files now
1404also returns a <code>uintptr</code>.</p>
1405
1406<p><em>Updating</em>: Code will fail to compile and must be updated
1407by hand. </p>
Brad Fitzpatrick7750fc82012-02-10 11:44:51 +11001408
1409<h4 id="os_fileinfo">The os.FileInfo type</h4>
Rob Pike0a1376a2012-01-20 14:28:48 -08001410
1411<p>
1412Go 1 redefines the <a href="/pkg/os/#FileInfo"><code>os.FileInfo</code></a> type,
1413changing it from a struct to an interface:
1414</p>
1415
1416<pre>
1417 type FileInfo interface {
1418 Name() string // base name of the file
1419 Size() int64 // length in bytes
1420 Mode() FileMode // file mode bits
1421 ModTime() time.Time // modification time
1422 IsDir() bool // abbreviation for Mode().IsDir()
Rob Pike46dc76f2012-02-12 09:17:57 +11001423 Sys() interface{} // underlying data source (can return nil)
Rob Pike0a1376a2012-01-20 14:28:48 -08001424 }
1425</pre>
1426
1427<p>
1428The file mode information has been moved into a subtype called
1429<a href="/pkg/os/#FileMode"><code>os.FileMode</code></a>,
1430a simple integer type with <code>IsDir</code>, <code>Perm</code>, and <code>String</code>
1431methods.
1432</p>
1433
1434<p>
1435The system-specific details of file modes and properties such as (on Unix)
1436i-number have been removed from <code>FileInfo</code> altogether.
1437Instead, each operating system's <code>os</code> package provides an
1438implementation of the <code>FileInfo</code> interface, <code>*os.FileStat</code>,
Rob Pike46dc76f2012-02-12 09:17:57 +11001439which has a <code>Sys</code> method that returns the
Rob Pike0a1376a2012-01-20 14:28:48 -08001440system-specific representation of file metadata.
1441For instance, to discover the i-number of a file on a Unix system, unpack
1442the <code>FileInfo</code> like this:
1443</p>
1444
1445<pre>
1446 fi, err := os.Stat("hello.go")
1447 if err != nil {
1448 log.Fatal(err)
1449 }
Rob Pike46dc76f2012-02-12 09:17:57 +11001450 // Check that it's a Unix file.
1451 unixStat, ok := fi.Sys().(*syscall.Stat_t)
Rob Pike0a1376a2012-01-20 14:28:48 -08001452 if !ok {
1453 log.Fatal("hello.go: not a Unix file")
1454 }
1455 fmt.Printf("file i-number: %d\n", unixStat.Ino)
1456</pre>
1457
1458<p>
1459Assuming (which is unwise) that <code>"hello.go"</code> is a Unix file,
1460the i-number expression could be contracted to
1461</p>
1462
1463<pre>
1464 fi.(*os.FileStat).Sys.(*syscall.Stat_t).Ino
1465</pre>
1466
1467<p>
1468The vast majority of uses of <code>FileInfo</code> need only the methods
1469of the standard interface.
1470</p>
1471
1472<p>
1473<em>Updating</em>:
Rob Pike27836912012-02-04 07:49:51 +11001474Running <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 -08001475and <code>os.FileMode</code> API.
1476Code that needs system-specific file details will need to be updated by hand.
1477</p>
1478
Rob Pikedd442a52012-01-24 17:02:06 -08001479<h3 id="path_filepath">The path/filepath package</h3>
1480
1481<p>
1482In Go 1, the <a href="/pkg/path/filepath/#Walk"><code>Walk</code></a> function of the
1483<code>path/filepath</code> package
1484has been changed to take a function value of type
1485<a href="/pkg/path/filepath/#WalkFunc"><code>WalkFunc</code></a>
1486instead of a <code>Visitor</code> interface value.
1487<code>WalkFunc</code> unifies the handling of both files and directories.
1488</p>
1489
1490<pre>
1491 type WalkFunc func(path string, info *os.FileInfo, err os.Error) os.Error
1492</pre>
1493
1494<p>
1495The <code>WalkFunc</code> function will be called even for files or directories that could not be opened;
1496in such cases the error argument will describe the failure.
1497If a directory's contents are to be skipped,
1498the function should return the value <code>SkipDir</code>.
1499</p>
1500
1501<p>
1502<font color="red">TODO: add an example?</font>
1503</p>
1504
1505<p>
1506<em>Updating</em>:
1507The change simplifies most code but has subtle consequences, so affected programs
1508will need to be updated by hand.
1509The compiler will catch code using the old interface.
1510</p>
1511
Rob Pike531ded92012-01-20 15:38:03 -08001512<h3 id="runtime">The runtime package</h3>
1513
1514<p>
1515The <code>runtime</code> package in Go 1 includes a new niladic function,
1516<a href="/pkg/runtime/#NumCPU"><code>runtime.NumCPU</code></a>, that returns the number of CPUs available
1517for parallel execution, as reported by the operating system kernel.
1518Its value can inform the setting of <code>GOMAXPROCS</code>.
1519</p>
1520
1521<p>
1522<em>Updating</em>:
1523No existing code is affected.
1524</p>
1525
Rob Pikebab4dec2011-12-07 14:33:37 -08001526<h3 id="strconv">The strconv package</h3>
1527
Rob Pike71ccf732011-12-09 14:12:51 -08001528<p>
1529In Go 1, the
Rob Pikeebdcbf12011-12-12 12:26:56 -08001530<a href="/pkg/strconv/"><code>strconv</code></a>
Rob Pike71ccf732011-12-09 14:12:51 -08001531package has been significantly reworked to make it more Go-like and less C-like,
1532although <code>Atoi</code> lives on (it's similar to
1533<code>int(ParseInt(x, 10, 0))</code>, as does
1534<code>Itoa(x)</code> (<code>FormatInt(int64(x), 10)</code>).
1535There are also new variants of some of the functions that append to byte slices rather than
1536return strings, to allow control over allocation.
1537</p>
1538
1539<p>
1540This table summarizes the renamings; see the
Rob Pikeebdcbf12011-12-12 12:26:56 -08001541<a href="/pkg/strconv/">package documentation</a>
Rob Pike71ccf732011-12-09 14:12:51 -08001542for full details.
1543</p>
1544
1545<table class="codetable" frame="border" summary="strconv renames">
1546<colgroup align="left" width="50%"></colgroup>
1547<colgroup align="left" width="50%"></colgroup>
1548<tr>
1549<th align="left">Old call</th>
1550<th align="left">New call</th>
1551</tr>
1552<tr>
1553<td colspan="2"><hr></td>
1554</tr>
1555<tr><td>Atob(x)</td> <td>ParseBool(x)</td></tr>
1556<tr>
1557<td colspan="2"><hr></td>
1558</tr>
1559<tr><td>Atof32(x)</td> <td>ParseFloat(x, 32)§</td></tr>
1560<tr><td>Atof64(x)</td> <td>ParseFloat(x, 64)</td></tr>
1561<tr><td>AtofN(x, n)</td> <td>ParseFloat(x, n)</td></tr>
1562<tr>
1563<td colspan="2"><hr></td>
1564</tr>
1565<tr><td>Atoi(x)</td> <td>Atoi(x)</td></tr>
1566<tr><td>Atoi(x)</td> <td>ParseInt(x, 10, 0)§</td></tr>
1567<tr><td>Atoi64(x)</td> <td>ParseInt(x, 10, 64)</td></tr>
1568<tr>
1569<td colspan="2"><hr></td>
1570</tr>
1571<tr><td>Atoui(x)</td> <td>ParseUint(x, 10, 0)§</td></tr>
1572<tr><td>Atoi64(x)</td> <td>ParseInt(x, 10, 64)</td></tr>
1573<tr>
1574<td colspan="2"><hr></td>
1575</tr>
1576<tr><td>Btoi64(x, b)</td> <td>ParseInt(x, b, 64)</td></tr>
1577<tr><td>Btoui64(x, b)</td> <td>ParseUint(x, b, 64)</td></tr>
1578<tr>
1579<td colspan="2"><hr></td>
1580</tr>
1581<tr><td>Btoa(x)</td> <td>FormatBool(x)</td></tr>
1582<tr>
1583<td colspan="2"><hr></td>
1584</tr>
1585<tr><td>Ftoa32(x, f, p)</td> <td>FormatFloat(x, float64(f), p, 32)</td></tr>
1586<tr><td>Ftoa64(x, f, p)</td> <td>FormatFloat(x, f, p, 64)</td></tr>
1587<tr><td>FtoaN(x, f, p, n)</td> <td>FormatFloat(x, f, p, n)</td></tr>
1588<tr>
1589<td colspan="2"><hr></td>
1590</tr>
1591<tr><td>Itoa(x)</td> <td>Itoa(x)</td></tr>
1592<tr><td>Itoa(x)</td> <td>FormatInt(int64(x), 10)</td></tr>
1593<tr><td>Itoa64(x)</td> <td>FormatInt(x, 10)</td></tr>
1594<tr>
1595<td colspan="2"><hr></td>
1596</tr>
1597<tr><td>Itob(x, b)</td> <td>FormatInt(int64(x), b)</td></tr>
1598<tr><td>Itob64(x, b)</td> <td>FormatInt(x, b)</td></tr>
1599<tr>
1600<td colspan="2"><hr></td>
1601</tr>
1602<tr><td>Uitoa(x)</td> <td>FormatUint(uint64(x), 10)</td></tr>
1603<tr><td>Uitoa64(x)</td> <td>FormatUint(x, 10)</td></tr>
1604<tr>
1605<td colspan="2"><hr></td>
1606</tr>
1607<tr><td>Uitob(x, b)</td> <td>FormatUint(uint64(x), b)</td></tr>
1608<tr><td>Uitob64(x, b)</td> <td>FormatUint(x, b)</td></tr>
1609</table>
1610
1611<p>
1612<em>Updating</em>:
Rob Pike27836912012-02-04 07:49:51 +11001613Running <code>go fix</code> will update almost all code affected by the change.
Rob Pike71ccf732011-12-09 14:12:51 -08001614<br>
1615§ <code>Atoi</code> persists but <code>Atoui</code> and <code>Atof32</code> do not, so
1616they may require
Rob Pike27836912012-02-04 07:49:51 +11001617a cast that must be added by hand; the go fix tool will warn about it.
Rob Pike71ccf732011-12-09 14:12:51 -08001618</p>
1619
Rob Pikebab4dec2011-12-07 14:33:37 -08001620
Rob Pike531ded92012-01-20 15:38:03 -08001621<h3 id="testing">The testing package</h3>
1622
1623<p>
1624The testing package has a type, <code>B</code>, passed as an argument to benchmark functions.
1625In Go 1, <code>B</code> has new methods, analogous to those of <code>T</code>, enabling
1626logging and failure reporting.
1627</p>
1628
1629<pre><!--{{code "progs/go1.go" `/func.*Benchmark/` `/^}/`}}
1630-->func BenchmarkSprintf(b *testing.B) {
1631 // Verify correctness before running benchmark.
1632 b.StopTimer()
1633 got := fmt.Sprintf(&#34;%x&#34;, 23)
1634 const expect = &#34;17&#34;
1635 if expect != got {
1636 b.Fatalf(&#34;expected %q; got %q&#34;, expect, got)
1637 }
1638 b.StartTimer()
1639 for i := 0; i &lt; b.N; i++ {
1640 fmt.Sprintf(&#34;%x&#34;, 23)
1641 }
1642}</pre>
1643
1644<p>
1645<em>Updating</em>:
1646Existing code is unaffected, although benchmarks that use <code>println</code>
Rob Pike2257e762012-01-23 16:11:49 -08001647or <code>panic</code> should be updated to use the new methods.
Rob Pike531ded92012-01-20 15:38:03 -08001648</p>
1649
Rob Pikecbd6c342012-02-10 14:31:08 +11001650<h3 id="testing_script">The testing/script package</h3>
1651
1652<p>
1653The testing/script package has been deleted. It was a dreg.
1654</p>
1655
1656<p>
1657<em>Updating</em>:
1658No code is likely to be affected.
1659</p>
1660
Gustavo Niemeyer805d6202012-01-25 23:11:25 -02001661<h3 id="url">The url package</h3>
1662
1663<p>
Gustavo Niemeyer7b504852012-01-26 00:59:50 -02001664In 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 -02001665were removed or replaced.
1666</p>
1667
1668<p>
Gustavo Niemeyer7b504852012-01-26 00:59:50 -02001669The <a href="/pkg/net/url/#URL.String"><code>String</code></a> method now
Gustavo Niemeyer805d6202012-01-25 23:11:25 -02001670predictably rebuilds an encoded URL string using all of <code>URL</code>'s
1671fields as necessary. The resulting string will also no longer have
1672passwords escaped.
1673</p>
1674
1675<p>
1676The <code>Raw</code> field has been removed. In most cases the <code>String</code>
1677method may be used in its place.
1678</p>
1679
1680<p>
1681The old <code>RawUserinfo</code> field is replaced by the <code>User</code>
Gustavo Niemeyer7b504852012-01-26 00:59:50 -02001682field, of type <a href="/pkg/net/url/#Userinfo"><code>*net.Userinfo</code></a>.
1683Values of this type may be created using the new <a href="/pkg/net/url/#User"><code>net.User</code></a>
1684and <a href="/pkg/net/url/#UserPassword"><code>net.UserPassword</code></a>
Gustavo Niemeyer805d6202012-01-25 23:11:25 -02001685functions. The <code>EscapeUserinfo</code> and <code>UnescapeUserinfo</code>
1686functions are also gone.
1687</p>
1688
1689<p>
1690The <code>RawAuthority</code> field has been removed. The same information is
1691available in the <code>Host</code> and <code>User</code> fields.
1692</p>
1693
1694<p>
1695The <code>RawPath</code> field and the <code>EncodedPath</code> method have
1696been removed. The path information in rooted URLs (with a slash following the
1697schema) is now available only in decoded form in the <code>Path</code> field.
1698Occasionally, the encoded data may be required to obtain information that
1699was lost in the decoding process. These cases must be handled by accessing
1700the data the URL was built from.
1701</p>
1702
1703<p>
1704URLs with non-rooted paths, such as <code>"mailto:dev@golang.org?subject=Hi"</code>,
1705are also handled differently. The <code>OpaquePath</code> boolean field has been
1706removed and a new <code>Opaque</code> string field introduced to hold the encoded
1707path for such URLs. In Go 1, the cited URL parses as:
1708</p>
1709
1710<pre>
1711 URL{
1712 Scheme: "mailto",
1713 Opaque: "dev@golang.org",
1714 RawQuery: "subject=Hi",
1715 }
1716</pre>
1717
1718<p>
Gustavo Niemeyer7b504852012-01-26 00:59:50 -02001719A new <a href="/pkg/net/url/#URL.RequestURI"><code>RequestURI</code></a> method was
Gustavo Niemeyer805d6202012-01-25 23:11:25 -02001720added to <code>URL</code>.
1721</p>
1722
1723<p>
1724<em>Updating</em>:
1725Code that uses the old fields will fail to compile and must be updated by hand.
Rob Pike27836912012-02-04 07:49:51 +11001726The semantic changes make it difficult for the fix tool to update automatically.
Gustavo Niemeyer805d6202012-01-25 23:11:25 -02001727</p>
1728
Rob Pikebab4dec2011-12-07 14:33:37 -08001729<h2 id="go_command">The go command</h2>
1730
1731<h2 id="releases">Packaged releases</h2>
1732