blob: 2687827c0e360310bd5e5bb4f060c0b7dabcc572 [file] [log] [blame]
Andrew Gerrand7cb21a72012-01-19 11:24:54 +11001<!--{
Russ Coxa40065a2012-03-08 08:39:20 -05002 "Title": "Go 1 Release Notes",
3 "Template": true
Andrew Gerrand7cb21a72012-01-19 11:24:54 +11004}-->
Rob Pikebab4dec2011-12-07 14:33:37 -08005
6<h2 id="introduction">Introduction to Go 1</h2>
7
8<p>
Rob Pikeb36d25f2012-02-25 08:02:35 +11009Go version 1, Go 1 for short, defines a language and a set of core libraries
10that provide a stable foundation for creating reliable products, projects, and
11publications.
Rob Pikebab4dec2011-12-07 14:33:37 -080012</p>
13
14<p>
Rob Pikeb36d25f2012-02-25 08:02:35 +110015The driving motivation for Go 1 is stability for its users. People should be able to
16write Go programs and expect that they will continue to compile and run without
17change, on a time scale of years, including in production environments such as
18Google App Engine. Similarly, people should be able to write books about Go, be
19able to say which version of Go the book is describing, and have that version
20number still be meaningful much later.
Rob Pikebab4dec2011-12-07 14:33:37 -080021</p>
22
23<p>
Rob Pikeb36d25f2012-02-25 08:02:35 +110024Code that compiles in Go 1 should, with few exceptions, continue to compile and
25run throughout the lifetime of that version, even as we issue updates and bug
26fixes such as Go version 1.1, 1.2, and so on. Other than critical fixes, changes
27made to the language and library for subsequent releases of Go 1 may
28add functionality but will not break existing Go 1 programs.
29<a href="go1compat.html">The Go 1 compatibility document</a>
30explains the compatibility guidelines in more detail.
31</p>
32
33<p>
34Go 1 is a representation of Go as it used today, not a wholesale rethinking of
35the language. We avoided designing new features and instead focused on cleaning
36up problems and inconsistencies and improving portability. There are a number
37changes to the Go language and packages that we had considered for some time and
38prototyped but not released primarily because they are significant and
39backwards-incompatible. Go 1 was an opportunity to get them out, which is
40helpful for the long term, but also means that Go 1 introduces incompatibilities
41for old programs. Fortunately, the <code>go</code> <code>fix</code> tool can
42automate much of the work needed to bring programs up to the Go 1 standard.
43</p>
44
45<p>
46This document outlines the major changes in Go 1 that will affect programmers
47updating existing code; its reference point is the prior release, r60 (tagged as
48r60.3). It also explains how to update code from r60 to run under Go 1.
Rob Pike136c04f2011-12-08 16:39:05 -080049</p>
Rob Pikebab4dec2011-12-07 14:33:37 -080050
51<h2 id="language">Changes to the language</h2>
52
53<h3 id="append">Append</h3>
54
Rob Pike136c04f2011-12-08 16:39:05 -080055<p>
Rob Pike68c7e8a2012-02-27 07:31:34 +110056The <code>append</code> predeclared variadic function makes it easy to grow a slice
57by adding elements to the end.
58A common use is to add bytes to the end of a byte slice when generating output.
59However, <code>append</code> did not provide a way to append a string to a <code>[]byte</code>,
60which is another common case.
Rob Pike136c04f2011-12-08 16:39:05 -080061</p>
62
Russ Coxa40065a2012-03-08 08:39:20 -050063{{code "/doc/progs/go1.go" `/greeting := ..byte/` `/append.*hello/`}}
Rob Pike136c04f2011-12-08 16:39:05 -080064
65<p>
66By analogy with the similar property of <code>copy</code>, Go 1
67permits a string to be appended (byte-wise) directly to a byte
Rob Pike68c7e8a2012-02-27 07:31:34 +110068slice, reducing the friction between strings and byte slices.
69The conversion is no longer necessary:
Rob Pike136c04f2011-12-08 16:39:05 -080070</p>
71
Russ Coxa40065a2012-03-08 08:39:20 -050072{{code "/doc/progs/go1.go" `/append.*world/`}}
Rob Pike136c04f2011-12-08 16:39:05 -080073
74<p>
75<em>Updating</em>:
76This is a new feature, so existing code needs no changes.
77</p>
78
Rob Pikebab4dec2011-12-07 14:33:37 -080079<h3 id="close">Close</h3>
80
Rob Pike136c04f2011-12-08 16:39:05 -080081<p>
Rob Pike68c7e8a2012-02-27 07:31:34 +110082The <code>close</code> predeclared function provides a mechanism
83for a sender to signal that no more values will be sent.
84It is important to the implementation of <code>for</code> <code>range</code>
85loops over channels and is helpful in other situations.
86Partly by design and partly because of race conditions that can occur otherwise,
87it is intended for use only by the goroutine sending on the channel,
88not by the goroutine receiving data.
89However, before Go 1 there was no compile-time checking that <code>close</code>
90was being used correctly.
91</p>
92
93<p>
94To close this gap, at least in part, Go 1 disallows <code>close</code> on receive-only channels.
95Attempting to close such a channel is a compile-time error.
Rob Pike136c04f2011-12-08 16:39:05 -080096</p>
97
98<pre>
99 var c chan int
Robert Hencke7c9ee5f2012-01-25 21:09:46 -0800100 var csend chan&lt;- int = c
101 var crecv &lt;-chan int = c
Rob Pike136c04f2011-12-08 16:39:05 -0800102 close(c) // legal
103 close(csend) // legal
104 close(crecv) // illegal
105</pre>
106
107<p>
108<em>Updating</em>:
109Existing code that attempts to close a receive-only channel was
110erroneous even before Go 1 and should be fixed. The compiler will
111now reject such code.
112</p>
113
Rob Pike9d59c402011-12-08 11:35:28 -0800114<h3 id="literals">Composite literals</h3>
Rob Pikebab4dec2011-12-07 14:33:37 -0800115
Rob Pike2e338fa2011-12-09 08:31:57 -0800116<p>
117In Go 1, a composite literal of array, slice, or map type can elide the
118type specification for the elements' initializers if they are of pointer type.
119All four of the initializations in this example are legal; the last one was illegal before Go 1.
120</p>
121
Russ Coxa40065a2012-03-08 08:39:20 -0500122{{code "/doc/progs/go1.go" `/type Date struct/` `/STOP/`}}
Rob Pike2e338fa2011-12-09 08:31:57 -0800123
124<p>
125<em>Updating</em>:
126This change has no effect on existing code, but the command
127<code>gofmt</code> <code>-s</code> applied to existing source
128will, among other things, elide explicit element types wherever permitted.
129</p>
130
131
Rob Pike9d59c402011-12-08 11:35:28 -0800132<h3 id="init">Goroutines during init</h3>
Rob Pikebab4dec2011-12-07 14:33:37 -0800133
Rob Pike136c04f2011-12-08 16:39:05 -0800134<p>
Rob Pike68c7e8a2012-02-27 07:31:34 +1100135The old language defined that <code>go</code> statements executed during initialization created goroutines but that they did not begin to run until initialization of the entire program was complete.
136This introduced clumsiness in many places and, in effect, limited the utility
137of the <code>init</code> construct:
138if it was possible for another package to use the library during initialization, the library
139was forced to avoid goroutines.
140This design was done for reasons of simplicity and safety but,
141as our confidence in the language grew, it seemed unnecessary.
142Running goroutines during initialization is no more complex or unsafe than running them during normal execution.
143</p>
144
145<p>
146In Go 1, code that uses goroutines can be called from
Rob Pike136c04f2011-12-08 16:39:05 -0800147<code>init</code> routines and global initialization expressions
148without introducing a deadlock.
149</p>
150
Russ Coxa40065a2012-03-08 08:39:20 -0500151{{code "/doc/progs/go1.go" `/PackageGlobal/` `/^}/`}}
Rob Pike136c04f2011-12-08 16:39:05 -0800152
153<p>
154<em>Updating</em>:
155This is a new feature, so existing code needs no changes,
156although it's possible that code that depends on goroutines not starting before <code>main</code> will break.
157There was no such code in the standard repository.
158</p>
159
Rob Pikebab4dec2011-12-07 14:33:37 -0800160<h3 id="rune">The rune type</h3>
161
Rob Pike2e338fa2011-12-09 08:31:57 -0800162<p>
Rob Pike68c7e8a2012-02-27 07:31:34 +1100163The language spec allows the <code>int</code> type to be 32 or 64 bits wide, but current implementations set <code>int</code> to 32 bits even on 64-bit platforms.
164It would be preferable to have <code>int</code> be 64 bits on 64-bit platforms.
165(There are important consequences for indexing large slices.)
166However, this change would waste space when processing Unicode characters with
167the old language because the <code>int</code> type was also used to hold Unicode code points: each code point would waste an extra 32 bits of storage if <code>int</code> grew from 32 bits to 64.
168</p>
169
170<p>
171To make changing to 64-bit <code>int</code> feasible,
172Go 1 introduces a new basic type, <code>rune</code>, to represent
Rob Pike2e338fa2011-12-09 08:31:57 -0800173individual Unicode code points.
174It is an alias for <code>int32</code>, analogous to <code>byte</code>
175as an alias for <code>uint8</code>.
176</p>
177
178<p>
179Character literals such as <code>'a'</code>, <code>'語'</code>, and <code>'\u0345'</code>
180now have default type <code>rune</code>,
181analogous to <code>1.0</code> having default type <code>float64</code>.
182A variable initialized to a character constant will therefore
183have type <code>rune</code> unless otherwise specified.
184</p>
185
186<p>
187Libraries have been updated to use <code>rune</code> rather than <code>int</code>
188when appropriate. For instance, the functions <code>unicode.ToLower</code> and
189relatives now take and return a <code>rune</code>.
190</p>
191
Russ Coxa40065a2012-03-08 08:39:20 -0500192{{code "/doc/progs/go1.go" `/STARTRUNE/` `/ENDRUNE/`}}
Rob Pike2e338fa2011-12-09 08:31:57 -0800193
194<p>
195<em>Updating</em>:
196Most source code will be unaffected by this because the type inference from
197<code>:=</code> initializers introduces the new type silently, and it propagates
198from there.
199Some code may get type errors that a trivial conversion will resolve.
200</p>
201
202<h3 id="error">The error type</h3>
203
204<p>
205Go 1 introduces a new built-in type, <code>error</code>, which has the following definition:
206</p>
207
208<pre>
209 type error interface {
210 Error() string
211 }
212</pre>
213
214<p>
215Since the consequences of this type are all in the package library,
Rob Pikeebdcbf12011-12-12 12:26:56 -0800216it is discussed <a href="#errors">below</a>.
Rob Pike2e338fa2011-12-09 08:31:57 -0800217</p>
218
Rob Pike9d59c402011-12-08 11:35:28 -0800219<h3 id="delete">Deleting from maps</h3>
Rob Pike2fa987b2011-12-07 16:11:17 -0800220
221<p>
Rob Pike68c7e8a2012-02-27 07:31:34 +1100222In the old language, to delete the entry with key <code>k</code> from map <code>m</code>, one wrote the statement,
Rob Pike2fa987b2011-12-07 16:11:17 -0800223</p>
224
225<pre>
Rob Pike68c7e8a2012-02-27 07:31:34 +1100226 m[k] = value, false
Rob Pike2fa987b2011-12-07 16:11:17 -0800227</pre>
228
229<p>
Rob Pike68c7e8a2012-02-27 07:31:34 +1100230This syntax was a peculiar special case, the only two-to-one assignment.
231It required passing a value (usually ignored) that is evaluated but discarded,
232plus a boolean that was nearly always the constant <code>false</code>.
233It did the job but was odd and a point of contention.
234</p>
235
236<p>
Rob Pike9d59c402011-12-08 11:35:28 -0800237In Go 1, that syntax has gone; instead there is a new built-in
Rob Pike2fa987b2011-12-07 16:11:17 -0800238function, <code>delete</code>. The call
239</p>
240
Russ Coxa40065a2012-03-08 08:39:20 -0500241{{code "/doc/progs/go1.go" `/delete\(m, k\)/`}}
Rob Pike2fa987b2011-12-07 16:11:17 -0800242
243<p>
244will delete the map entry retrieved by the expression <code>m[k]</code>.
245There is no return value. Deleting a non-existent entry is a no-op.
246</p>
247
248<p>
249<em>Updating</em>:
Rob Pike68c7e8a2012-02-27 07:31:34 +1100250Running <code>go</code> <code>fix</code> will convert expressions of the form <code>m[k] = value,
Rob Pike2fa987b2011-12-07 16:11:17 -0800251false</code> into <code>delete(m, k)</code> when it is clear that
252the ignored value can be safely discarded from the program and
Rob Pike27836912012-02-04 07:49:51 +1100253<code>false</code> refers to the predefined boolean constant.
254The fix tool
Rob Pike2fa987b2011-12-07 16:11:17 -0800255will flag other uses of the syntax for inspection by the programmer.
256</p>
257
Rob Pike136c04f2011-12-08 16:39:05 -0800258<h3 id="iteration">Iterating in maps</h3>
259
260<p>
Rob Pike68c7e8a2012-02-27 07:31:34 +1100261The old language specification did not define the order of iteration for maps,
262and in practice it differed across hardware platforms.
263This caused tests that iterated over maps to be fragile and non-portable, with the
264unpleasant property that a test might always pass on one machine but break on another.
265</p>
266
267<p>
Rob Pike136c04f2011-12-08 16:39:05 -0800268In Go 1, the order in which elements are visited when iterating
269over a map using a <code>for</code> <code>range</code> statement
270is defined to be unpredictable, even if the same loop is run multiple
271times with the same map.
272Code should not assume that the elements are visited in any particular order.
273</p>
274
Rob Pike68c7e8a2012-02-27 07:31:34 +1100275<p>
276This change means that code that depends on iteration order is very likely to break early and be fixed long before it becomes a problem.
277Just as important, it allows the map implementation to ensure better map balancing even when programs are using range loops to select an element from a map.
278</p>
279
Russ Coxa40065a2012-03-08 08:39:20 -0500280{{code "/doc/progs/go1.go" `/Sunday/` `/^ }/`}}
Rob Pike136c04f2011-12-08 16:39:05 -0800281
282<p>
283<em>Updating</em>:
284This is one change where tools cannot help. Most existing code
285will be unaffected, but some programs may break or misbehave; we
286recommend manual checking of all range statements over maps to
287verify they do not depend on iteration order. There were a few such
288examples in the standard repository; they have been fixed.
289Note that it was already incorrect to depend on the iteration order, which
290was unspecified. This change codifies the unpredictability.
291</p>
Rob Pikebab4dec2011-12-07 14:33:37 -0800292
293<h3 id="multiple_assignment">Multiple assignment</h3>
294
Rob Pike136c04f2011-12-08 16:39:05 -0800295<p>
Rob Pike9e7e6d92012-02-29 11:29:33 +1100296The language specification has long guaranteed that in assignments
Rob Pike68c7e8a2012-02-27 07:31:34 +1100297the right-hand-side expressions are all evaluated before any left-hand-side expressions are assigned.
298To guarantee predictable behavior,
299Go 1 refines the specification further.
300</p>
301
302<p>
303If the left-hand side of the assignment
Rob Pike136c04f2011-12-08 16:39:05 -0800304statement contains expressions that require evaluation, such as
305function calls or array indexing operations, these will all be done
306using the usual left-to-right rule before any variables are assigned
307their value. Once everything is evaluated, the actual assignments
308proceed in left-to-right order.
309</p>
310
311<p>
312These examples illustrate the behavior.
313</p>
314
Russ Coxa40065a2012-03-08 08:39:20 -0500315{{code "/doc/progs/go1.go" `/sa :=/` `/then sc.0. = 2/`}}
Rob Pike136c04f2011-12-08 16:39:05 -0800316
Rob Pike2e338fa2011-12-09 08:31:57 -0800317<p>
Rob Pike136c04f2011-12-08 16:39:05 -0800318<em>Updating</em>:
319This is one change where tools cannot help, but breakage is unlikely.
320No code in the standard repository was broken by this change, and code
321that depended on the previous unspecified behavior was already incorrect.
322</p>
323
Rob Pikebab4dec2011-12-07 14:33:37 -0800324<h3 id="shadowing">Returns and shadowed variables</h3>
325
Rob Pike136c04f2011-12-08 16:39:05 -0800326<p>
Rob Pike68c7e8a2012-02-27 07:31:34 +1100327A common mistake is to use <code>return</code> (without arguments) after an assignment to a variable that has the same name as a result variable but is not the same variable.
328This situation is called <em>shadowing</em>: the result variable has been shadowed by another variable with the same name declared in an inner scope.
329</p>
330
331<p>
Rob Pike136c04f2011-12-08 16:39:05 -0800332In functions with named return values,
333the Go 1 compilers disallow return statements without arguments if any of the named return values is shadowed at the point of the return statement.
334(It isn't part of the specification, because this is one area we are still exploring;
335the situation is analogous to the compilers rejecting functions that do not end with an explicit return statement.)
336</p>
337
338<p>
339This function implicitly returns a shadowed return value and will be rejected by the compiler:
340</p>
341
342<pre>
343 func Bug() (i, j, k int) {
Robert Hencke7c9ee5f2012-01-25 21:09:46 -0800344 for i = 0; i &lt; 5; i++ {
345 for j := 0; j &lt; 5; j++ { // Redeclares j.
Rob Pike136c04f2011-12-08 16:39:05 -0800346 k += i*j
347 if k > 100 {
348 return // Rejected: j is shadowed here.
349 }
350 }
351 }
352 return // OK: j is not shadowed here.
353 }
354</pre>
355
356<p>
357<em>Updating</em>:
358Code that shadows return values in this way will be rejected by the compiler and will need to be fixed by hand.
359The few cases that arose in the standard repository were mostly bugs.
360</p>
361
362<h3 id="unexported">Copying structs with unexported fields</h3>
363
Rob Pike2e338fa2011-12-09 08:31:57 -0800364<p>
Rob Pike68c7e8a2012-02-27 07:31:34 +1100365The old language did not allow a package to make a copy of a struct value containing unexported fields belonging to a different package.
366There was, however, a required exception for a method receiver;
367also, the implementations of <code>copy</code> and <code>append</code> have never honored the restriction.
368</p>
369
370<p>
371Go 1 will allow packages to copy struct values containing unexported fields from other packages.
372Besides resolving the inconsistency,
373this change admits a new kind of API: a package can return an opaque value without resorting to a pointer or interface.
374The new implementations of <code>time.Time</code> and
375<code>reflect.Value</code> are examples of types taking advantage of this new property.
Rob Pike2e338fa2011-12-09 08:31:57 -0800376</p>
377
378<p>
379As an example, if package <code>p</code> includes the definitions,
380</p>
381
382<pre>
383 type Struct struct {
384 Public int
385 secret int
386 }
387 func NewStruct(a int) Struct { // Note: not a pointer.
388 return Struct{a, f(a)}
389 }
390 func (s Struct) String() string {
391 return fmt.Sprintf("{%d (secret %d)}", s.Public, s.secret)
392 }
393</pre>
394
395<p>
396a package that imports <code>p</code> can assign and copy values of type
397<code>p.Struct</code> at will.
398Behind the scenes the unexported fields will be assigned and copied just
399as if they were exported,
400but the client code will never be aware of them. The code
401</p>
402
403<pre>
404 import "p"
405
406 myStruct := p.NewStruct(23)
407 copyOfMyStruct := myStruct
408 fmt.Println(myStruct, copyOfMyStruct)
409</pre>
410
411<p>
412will show that the secret field of the struct has been copied to the new value.
413</p>
414
415<p>
416<em>Updating</em>:
417This is a new feature, so existing code needs no changes.
418</p>
419
Rob Pike68c7e8a2012-02-27 07:31:34 +1100420<h3 id="equality">Equality</h3>
Rob Pikebab4dec2011-12-07 14:33:37 -0800421
Rob Pike136c04f2011-12-08 16:39:05 -0800422<p>
Rob Pike68c7e8a2012-02-27 07:31:34 +1100423Before Go 1, the language did not define equality on struct and array values.
424This meant,
425among other things, that structs and arrays could not be used as map keys.
426On the other hand, Go did define equality on function and map values.
427Function equality was problematic in the presence of closures
428(when are two closures equal?)
429while map equality compared pointers, not the maps' content, which was usually
430not what the user would want.
Rob Pike136c04f2011-12-08 16:39:05 -0800431</p>
432
433<p>
Rob Pike68c7e8a2012-02-27 07:31:34 +1100434Go 1 addressed these issues.
435First, structs and arrays can be compared for equality and inequality
436(<code>==</code> and <code>!=</code>),
437and therefore be used as map keys,
438provided they are composed from elements for which equality is also defined,
439using element-wise comparison.
Rob Pike136c04f2011-12-08 16:39:05 -0800440</p>
441
Russ Coxa40065a2012-03-08 08:39:20 -0500442{{code "/doc/progs/go1.go" `/type Day struct/` `/Printf/`}}
Rob Pike136c04f2011-12-08 16:39:05 -0800443
444<p>
Rob Pike68c7e8a2012-02-27 07:31:34 +1100445Second, Go 1 removes the definition of equality for function values,
446except for comparison with <code>nil</code>.
Rob Pike9e7e6d92012-02-29 11:29:33 +1100447Finally, map equality is gone too, also except for comparison with <code>nil</code>.
Rob Pike68c7e8a2012-02-27 07:31:34 +1100448</p>
449
450<p>
Rob Pike136c04f2011-12-08 16:39:05 -0800451Note that equality is still undefined for slices, for which the
452calculation is in general infeasible. Also note that the ordered
453comparison operators (<code>&lt;</code> <code>&lt;=</code>
454<code>&gt;</code> <code>&gt;=</code>) are still undefined for
455structs and arrays.
456
457<p>
458<em>Updating</em>:
Rob Pike68c7e8a2012-02-27 07:31:34 +1100459Struct and array equality is a new feature, so existing code needs no changes.
Rob Pike136c04f2011-12-08 16:39:05 -0800460Existing code that depends on function or map equality will be
461rejected by the compiler and will need to be fixed by hand.
462Few programs will be affected, but the fix may require some
463redesign.
464</p>
465
Rob Pike0a1376a2012-01-20 14:28:48 -0800466<h2 id="packages">The package hierarchy</h2>
467
468<p>
Rob Pike68c7e8a2012-02-27 07:31:34 +1100469Go 1 addresses many deficiencies in the old standard library and
470cleans up a number of packages, making them more internally consistent
471and portable.
472</p>
473
474<p>
Rob Pike0a1376a2012-01-20 14:28:48 -0800475This section describes how the packages have been rearranged in Go 1.
476Some have moved, some have been renamed, some have been deleted.
477New packages are described in later sections.
478</p>
Rob Pikebab4dec2011-12-07 14:33:37 -0800479
Rob Pike9d59c402011-12-08 11:35:28 -0800480<h3 id="hierarchy">The package hierarchy</h3>
481
482<p>
483Go 1 has a rearranged package hierarchy that groups related items
484into subdirectories. For instance, <code>utf8</code> and
485<code>utf16</code> now occupy subdirectories of <code>unicode</code>.
486Also, <a href="#subrepo">some packages</a> have moved into
487subrepositories of
488<a href="http://code.google.com/p/go"><code>code.google.com/p/go</code></a>
489while <a href="#deleted">others</a> have been deleted outright.
490</p>
491
492<table class="codetable" frame="border" summary="Moved packages">
493<colgroup align="left" width="60%"></colgroup>
494<colgroup align="left" width="40%"></colgroup>
495<tr>
496<th align="left">Old path</th>
497<th align="left">New path</th>
498</tr>
Rob Pike71ccf732011-12-09 14:12:51 -0800499<tr>
500<td colspan="2"><hr></td>
501</tr>
Rob Pike136c04f2011-12-08 16:39:05 -0800502<tr><td>asn1</td> <td>encoding/asn1</td></tr>
Rob Pike9d59c402011-12-08 11:35:28 -0800503<tr><td>csv</td> <td>encoding/csv</td></tr>
504<tr><td>gob</td> <td>encoding/gob</td></tr>
505<tr><td>json</td> <td>encoding/json</td></tr>
506<tr><td>xml</td> <td>encoding/xml</td></tr>
507<tr>
508<td colspan="2"><hr></td>
509</tr>
510<tr><td>exp/template/html</td> <td>html/template</td></tr>
511<tr>
512<td colspan="2"><hr></td>
513</tr>
514<tr><td>big</td> <td>math/big</td></tr>
515<tr><td>cmath</td> <td>math/cmplx</td></tr>
516<tr><td>rand</td> <td>math/rand</td></tr>
517<tr>
518<td colspan="2"><hr></td>
519</tr>
520<tr><td>http</td> <td>net/http</td></tr>
521<tr><td>http/cgi</td> <td>net/http/cgi</td></tr>
522<tr><td>http/fcgi</td> <td>net/http/fcgi</td></tr>
523<tr><td>http/httptest</td> <td>net/http/httptest</td></tr>
524<tr><td>http/pprof</td> <td>net/http/pprof</td></tr>
525<tr><td>mail</td> <td>net/mail</td></tr>
526<tr><td>rpc</td> <td>net/rpc</td></tr>
527<tr><td>rpc/jsonrpc</td> <td>net/rpc/jsonrpc</td></tr>
528<tr><td>smtp</td> <td>net/smtp</td></tr>
529<tr><td>url</td> <td>net/url</td></tr>
530<tr>
531<td colspan="2"><hr></td>
532</tr>
533<tr><td>exec</td> <td>os/exec</td></tr>
534<tr>
535<td colspan="2"><hr></td>
536</tr>
537<tr><td>scanner</td> <td>text/scanner</td></tr>
538<tr><td>tabwriter</td> <td>text/tabwriter</td></tr>
539<tr><td>template</td> <td>text/template</td></tr>
540<tr><td>template/parse</td> <td>text/template/parse</td></tr>
541<tr>
542<td colspan="2"><hr></td>
543</tr>
544<tr><td>utf8</td> <td>unicode/utf8</td></tr>
545<tr><td>utf16</td> <td>unicode/utf16</td></tr>
546</table>
547
548<p>
549Note that the package names for the old <code>cmath</code> and
550<code>exp/template/html</code> packages have changed to <code>cmplx</code>
551and <code>template</code>.
552</p>
553
554<p>
555<em>Updating</em>:
Rob Pike5cff0292012-02-24 13:08:11 +1100556Running <code>go</code> <code>fix</code> will update all imports and package renames for packages that
Rob Pike9d59c402011-12-08 11:35:28 -0800557remain inside the standard repository. Programs that import packages
558that are no longer in the standard repository will need to be edited
559by hand.
Rob Pike9d59c402011-12-08 11:35:28 -0800560</p>
Rob Pikebab4dec2011-12-07 14:33:37 -0800561
Rob Pike0a1376a2012-01-20 14:28:48 -0800562<h3 id="exp">The package tree exp</h3>
563
564<p>
565Because they are not standardized, the packages under the <code>exp</code> directory will not be available in the
566standard Go 1 release distributions, although they will be available in source code form
567in <a href="http://code.google.com/p/go/">the repository</a> for
568developers who wish to use them.
569</p>
570
571<p>
572Several packages have moved under <code>exp</code> at the time of Go 1's release:
573</p>
574
575<ul>
576<li><code>ebnf</code></li>
Shenghou Ma6a005cb2012-03-03 00:47:11 +0800577<li><code>html</code><sup>&#8224;</sup></li>
Rob Pike0a1376a2012-01-20 14:28:48 -0800578<li><code>go/types</code></li>
Rob Pike0a1376a2012-01-20 14:28:48 -0800579</ul>
580
581<p>
Shenghou Ma6a005cb2012-03-03 00:47:11 +0800582(<sup>&#8224;</sup>The <code>EscapeString</code> and <code>UnescapeString</code> types remain
Andrew Gerrand47d614e2012-03-02 11:52:46 +1100583in package <code>html</code>.)
584</p>
585
586<p>
Rob Pike531ded92012-01-20 15:38:03 -0800587All these packages are available under the same names, with the prefix <code>exp/</code>: <code>exp/ebnf</code> etc.
588</p>
589
590<p>
Rob Pike0a1376a2012-01-20 14:28:48 -0800591Also, the <code>utf8.String</code> type has been moved to its own package, <code>exp/utf8string</code>.
592</p>
593
594<p>
Rob Pike531ded92012-01-20 15:38:03 -0800595Finally, the <code>gotype</code> command now resides in <code>exp/gotype</code>, while
Rob Pike27836912012-02-04 07:49:51 +1100596<code>ebnflint</code> is now in <code>exp/ebnflint</code>.
597If they are installed, they now reside in <code>$GOROOT/bin/tool</code>.
Rob Pike0a1376a2012-01-20 14:28:48 -0800598</p>
599
600<p>
601<em>Updating</em>:
602Code that uses packages in <code>exp</code> will need to be updated by hand,
603or else compiled from an installation that has <code>exp</code> available.
Rob Pike5cff0292012-02-24 13:08:11 +1100604The <code>go</code> <code>fix</code> tool or the compiler will complain about such uses.
Rob Pike0a1376a2012-01-20 14:28:48 -0800605</p>
606
607<h3 id="old">The package tree old</h3>
608
609<p>
610Because they are deprecated, the packages under the <code>old</code> directory will not be available in the
611standard Go 1 release distributions, although they will be available in source code form for
612developers who wish to use them.
613</p>
614
615<p>
616The packages in their new locations are:
617</p>
618
619<ul>
620<li><code>old/netchan</code></li>
Rob Pike0a1376a2012-01-20 14:28:48 -0800621</ul>
622
623<p>
624<em>Updating</em>:
625Code that uses packages now in <code>old</code> will need to be updated by hand,
626or else compiled from an installation that has <code>old</code> available.
Rob Pike5cff0292012-02-24 13:08:11 +1100627The <code>go</code> <code>fix</code> tool will warn about such uses.
Rob Pike0a1376a2012-01-20 14:28:48 -0800628</p>
629
630<h3 id="deleted">Deleted packages</h3>
631
632<p>
633Go 1 deletes several packages outright:
634</p>
635
636<ul>
637<li><code>container/vector</code></li>
638<li><code>exp/datafmt</code></li>
639<li><code>go/typechecker</code></li>
David Symonds9ce770a2012-04-27 15:12:24 +1000640<li><code>old/regexp</code></li>
641<li><code>old/template</code></li>
Rob Pike0a1376a2012-01-20 14:28:48 -0800642<li><code>try</code></li>
643</ul>
644
645<p>
646and also the command <code>gotry</code>.
647</p>
648
649<p>
650<em>Updating</em>:
651Code that uses <code>container/vector</code> should be updated to use
652slices directly. See
653<a href="http://code.google.com/p/go-wiki/wiki/SliceTricks">the Go
654Language Community Wiki</a> for some suggestions.
655Code that uses the other packages (there should be almost zero) will need to be rethought.
Rob Pike0a1376a2012-01-20 14:28:48 -0800656</p>
657
658<h3 id="subrepo">Packages moving to subrepositories</h3>
659
Rob Pike7eaad5e2012-01-25 13:29:25 -0800660<p>
Alex Brainmana93047a2012-03-08 10:01:15 +1100661Go 1 has moved a number of packages into other repositories, usually sub-repositories of
Rob Pike7eaad5e2012-01-25 13:29:25 -0800662<a href="http://code.google.com/p/go/">the main Go repository</a>.
663This table lists the old and new import paths:
664
665<table class="codetable" frame="border" summary="Sub-repositories">
666<colgroup align="left" width="40%"></colgroup>
667<colgroup align="left" width="60%"></colgroup>
668<tr>
669<th align="left">Old</th>
670<th align="left">New</th>
671</tr>
672<tr>
673<td colspan="2"><hr></td>
674</tr>
675<tr><td>crypto/bcrypt</td> <td>code.google.com/p/go.crypto/bcrypt</tr>
676<tr><td>crypto/blowfish</td> <td>code.google.com/p/go.crypto/blowfish</tr>
677<tr><td>crypto/cast5</td> <td>code.google.com/p/go.crypto/cast5</tr>
678<tr><td>crypto/md4</td> <td>code.google.com/p/go.crypto/md4</tr>
679<tr><td>crypto/ocsp</td> <td>code.google.com/p/go.crypto/ocsp</tr>
680<tr><td>crypto/openpgp</td> <td>code.google.com/p/go.crypto/openpgp</tr>
681<tr><td>crypto/openpgp/armor</td> <td>code.google.com/p/go.crypto/openpgp/armor</tr>
682<tr><td>crypto/openpgp/elgamal</td> <td>code.google.com/p/go.crypto/openpgp/elgamal</tr>
683<tr><td>crypto/openpgp/errors</td> <td>code.google.com/p/go.crypto/openpgp/errors</tr>
684<tr><td>crypto/openpgp/packet</td> <td>code.google.com/p/go.crypto/openpgp/packet</tr>
685<tr><td>crypto/openpgp/s2k</td> <td>code.google.com/p/go.crypto/openpgp/s2k</tr>
686<tr><td>crypto/ripemd160</td> <td>code.google.com/p/go.crypto/ripemd160</tr>
687<tr><td>crypto/twofish</td> <td>code.google.com/p/go.crypto/twofish</tr>
688<tr><td>crypto/xtea</td> <td>code.google.com/p/go.crypto/xtea</tr>
689<tr><td>exp/ssh</td> <td>code.google.com/p/go.crypto/ssh</tr>
690<tr>
691<td colspan="2"><hr></td>
692</tr>
Nigel Taoceb1ca62012-01-31 12:29:00 +1100693<tr><td>image/bmp</td> <td>code.google.com/p/go.image/bmp</tr>
694<tr><td>image/tiff</td> <td>code.google.com/p/go.image/tiff</tr>
695<tr>
696<td colspan="2"><hr></td>
697</tr>
Rob Pike7eaad5e2012-01-25 13:29:25 -0800698<tr><td>net/dict</td> <td>code.google.com/p/go.net/dict</tr>
699<tr><td>net/websocket</td> <td>code.google.com/p/go.net/websocket</tr>
700<tr><td>exp/spdy</td> <td>code.google.com/p/go.net/spdy</tr>
701<tr>
702<td colspan="2"><hr></td>
703</tr>
704<tr><td>encoding/git85</td> <td>code.google.com/p/go.codereview/git85</tr>
705<tr><td>patch</td> <td>code.google.com/p/go.codereview/patch</tr>
Alex Brainman5aee1f32012-03-07 17:48:09 +1100706<tr>
707<td colspan="2"><hr></td>
708</tr>
709<tr><td>exp/wingui</td> <td>code.google.com/p/gowingui</tr>
Rob Pike7eaad5e2012-01-25 13:29:25 -0800710</table>
711
712<p>
713<em>Updating</em>:
Rob Pike5cff0292012-02-24 13:08:11 +1100714Running <code>go</code> <code>fix</code> will update imports of these packages to use the new import paths.
Rob Pike7eaad5e2012-01-25 13:29:25 -0800715Installations that depend on these packages will need to install them using
Rob Pikec5f695e2012-03-24 10:14:07 +1100716a <code>go get</code> command.
Rob Pike7eaad5e2012-01-25 13:29:25 -0800717</p>
Rob Pike0a1376a2012-01-20 14:28:48 -0800718
719<h2 id="major">Major changes to the library</h2>
720
721<p>
722This section describes significant changes to the core libraries, the ones that
723affect the most programs.
724</p>
725
Rob Pike71ccf732011-12-09 14:12:51 -0800726<h3 id="errors">The error type and errors package</h3>
Rob Pikebab4dec2011-12-07 14:33:37 -0800727
Rob Pikeebdcbf12011-12-12 12:26:56 -0800728<p>
Rob Pike68c7e8a2012-02-27 07:31:34 +1100729The placement of <code>os.Error</code> in package <code>os</code> is mostly historical: errors first came up when implementing package <code>os</code>, and they seemed system-related at the time.
730Since then it has become clear that errors are more fundamental than the operating system. For example, it would be nice to use <code>Errors</code> in packages that <code>os</code> depends on, like <code>syscall</code>.
731Also, having <code>Error</code> in <code>os</code> introduces many dependencies on <code>os</code> that would otherwise not exist.
732</p>
733
734<p>
735Go 1 solves these problems by introducing a built-in <code>error</code> interface type and a separate <code>errors</code> package (analogous to <code>bytes</code> and <code>strings</code>) that contains utility functions.
736It replaces <code>os.NewError</code> with
737<a href="/pkg/errors/#New"><code>errors.New</code></a>,
738giving errors a more central place in the environment.
739</p>
740
741<p>
Rob Pikeebdcbf12011-12-12 12:26:56 -0800742So the widely-used <code>String</code> method does not cause accidental satisfaction
743of the <code>error</code> interface, the <code>error</code> interface uses instead
744the name <code>Error</code> for that method:
745</p>
746
747<pre>
748 type error interface {
749 Error() string
750 }
751</pre>
752
753<p>
754The <code>fmt</code> library automatically invokes <code>Error</code>, as it already
755does for <code>String</code>, for easy printing of error values.
756</p>
757
Russ Coxa40065a2012-03-08 08:39:20 -0500758{{code "/doc/progs/go1.go" `/START ERROR EXAMPLE/` `/END ERROR EXAMPLE/`}}
Rob Pikeebdcbf12011-12-12 12:26:56 -0800759
760<p>
761All standard packages have been updated to use the new interface; the old <code>os.Error</code> is gone.
762</p>
763
764<p>
765A new package, <a href="/pkg/errors/"><code>errors</code></a>, contains the function
766</p>
767
768<pre>
769func New(text string) error
770</pre>
771
772<p>
773to turn a string into an error. It replaces the old <code>os.NewError</code>.
774</p>
775
Russ Coxa40065a2012-03-08 08:39:20 -0500776{{code "/doc/progs/go1.go" `/ErrSyntax/`}}
Rob Pikeebdcbf12011-12-12 12:26:56 -0800777
778<p>
779<em>Updating</em>:
Rob Pike5cff0292012-02-24 13:08:11 +1100780Running <code>go</code> <code>fix</code> will update almost all code affected by the change.
Rob Pikeebdcbf12011-12-12 12:26:56 -0800781Code that defines error types with a <code>String</code> method will need to be updated
782by hand to rename the methods to <code>Error</code>.
783</p>
784
Rob Pike9d59c402011-12-08 11:35:28 -0800785<h3 id="errno">System call errors</h3>
Rob Pikebab4dec2011-12-07 14:33:37 -0800786
Rob Pike71ccf732011-12-09 14:12:51 -0800787<p>
Rob Pike68c7e8a2012-02-27 07:31:34 +1100788The old <code>syscall</code> package, which predated <code>os.Error</code>
789(and just about everything else),
790returned errors as <code>int</code> values.
791In turn, the <code>os</code> package forwarded many of these errors, such
792as <code>EINVAL</code>, but using a different set of errors on each platform.
793This behavior was unpleasant and unportable.
794</p>
795
796<p>
Rob Pike71ccf732011-12-09 14:12:51 -0800797In Go 1, the
Rob Pikeebdcbf12011-12-12 12:26:56 -0800798<a href="/pkg/syscall/"><code>syscall</code></a>
Rob Pike68c7e8a2012-02-27 07:31:34 +1100799package instead returns an <code>error</code> for system call errors.
Rob Pike1cd272d2012-03-08 17:15:23 +1100800On Unix, the implementation is done by a
Rob Pikeebdcbf12011-12-12 12:26:56 -0800801<a href="/pkg/syscall/#Errno"><code>syscall.Errno</code></a> type
Rob Pike71ccf732011-12-09 14:12:51 -0800802that satisfies <code>error</code> and replaces the old <code>os.Errno</code>.
803</p>
804
805<p>
Rob Pike68c7e8a2012-02-27 07:31:34 +1100806The changes affecting <code>os.EINVAL</code> and relatives are
807described <a href="#os">elsewhere</a>.
808
809<p>
Rob Pike71ccf732011-12-09 14:12:51 -0800810<em>Updating</em>:
Rob Pike5cff0292012-02-24 13:08:11 +1100811Running <code>go</code> <code>fix</code> will update almost all code affected by the change.
Rob Pike71ccf732011-12-09 14:12:51 -0800812Regardless, most code should use the <code>os</code> package
813rather than <code>syscall</code> and so will be unaffected.
814</p>
815
Rob Pikebab4dec2011-12-07 14:33:37 -0800816<h3 id="time">Time</h3>
817
Rob Pike5fa18e12011-12-12 21:08:03 -0800818<p>
Rob Pike68c7e8a2012-02-27 07:31:34 +1100819Time is always a challenge to support well in a programming language.
820The old Go <code>time</code> package had <code>int64</code> units, no
821real type safety,
822and no distinction between absolute times and durations.
823</p>
824
825<p>
826One of the most sweeping changes in the Go 1 library is therefore a
Rob Pike1cd272d2012-03-08 17:15:23 +1100827complete redesign of the
Rob Pike5fa18e12011-12-12 21:08:03 -0800828<a href="/pkg/time/"><code>time</code></a> package.
829Instead of an integer number of nanoseconds as an <code>int64</code>,
830and a separate <code>*time.Time</code> type to deal with human
831units such as hours and years,
832there are now two fundamental types:
833<a href="/pkg/time/#Time"><code>time.Time</code></a>
834(a value, so the <code>*</code> is gone), which represents a moment in time;
835and <a href="/pkg/time/#Duration"><code>time.Duration</code></a>,
836which represents an interval.
837Both have nanosecond resolution.
838A <code>Time</code> can represent any time into the ancient
839past and remote future, while a <code>Duration</code> can
840span plus or minus only about 290 years.
841There are methods on these types, plus a number of helpful
842predefined constant durations such as <code>time.Second</code>.
843</p>
844
845<p>
846Among the new methods are things like
847<a href="/pkg/time/#Time.Add"><code>Time.Add</code></a>,
848which adds a <code>Duration</code> to a <code>Time</code>, and
849<a href="/pkg/time/#Time.Sub"><code>Time.Sub</code></a>,
850which subtracts two <code>Times</code> to yield a <code>Duration</code>.
851</p>
852
853<p>
854The most important semantic change is that the Unix epoch (Jan 1, 1970) is now
855relevant only for those functions and methods that mention Unix:
856<a href="/pkg/time/#Unix"><code>time.Unix</code></a>
857and the <a href="/pkg/time/#Time.Unix"><code>Unix</code></a>
858and <a href="/pkg/time/#Time.UnixNano"><code>UnixNano</code></a> methods
859of the <code>Time</code> type.
860In particular,
861<a href="/pkg/time/#Now"><code>time.Now</code></a>
862returns a <code>time.Time</code> value rather than, in the old
863API, an integer nanosecond count since the Unix epoch.
864</p>
865
Russ Coxa40065a2012-03-08 08:39:20 -0500866{{code "/doc/progs/go1.go" `/sleepUntil/` `/^}/`}}
Rob Pike5fa18e12011-12-12 21:08:03 -0800867
868<p>
869The new types, methods, and constants have been propagated through
870all the standard packages that use time, such as <code>os</code> and
871its representation of file time stamps.
872</p>
873
874<p>
875<em>Updating</em>:
Rob Pike5cff0292012-02-24 13:08:11 +1100876The <code>go</code> <code>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 -0800877types and methods, although it does not replace values such as <code>1e9</code>
878representing nanoseconds per second.
879Also, because of type changes in some of the values that arise,
Rob Pike27836912012-02-04 07:49:51 +1100880some of the expressions rewritten by the fix tool may require
Rob Pike5fa18e12011-12-12 21:08:03 -0800881further hand editing; in such cases the rewrite will include
882the correct function or method for the old functionality, but
883may have the wrong type or require further analysis.
884</p>
885
Rob Pike0a1376a2012-01-20 14:28:48 -0800886<h2 id="minor">Minor changes to the library</h2>
887
888<p>
889This section describes smaller changes, such as those to less commonly
890used packages or that affect
Rob Pike5cff0292012-02-24 13:08:11 +1100891few programs beyond the need to run <code>go</code> <code>fix</code>.
Rob Pike0a1376a2012-01-20 14:28:48 -0800892This category includes packages that are new in Go 1.
Rob Pike68c7e8a2012-02-27 07:31:34 +1100893Collectively they improve portability, regularize behavior, and
894make the interfaces more modern and Go-like.
Rob Pike0a1376a2012-01-20 14:28:48 -0800895</p>
896
Andrew Gerrand04868b22012-02-14 10:47:48 +1100897<h3 id="archive_zip">The archive/zip package</h3>
898
899<p>
900In Go 1, <a href="/pkg/archive/zip/#Writer"><code>*zip.Writer</code></a> no
901longer has a <code>Write</code> method. Its presence was a mistake.
902</p>
903
904<p>
Nigel Taoda8f0372012-02-15 14:41:47 +1100905<em>Updating</em>:
906What little code is affected will be caught by the compiler and must be updated by hand.
Andrew Gerrand04868b22012-02-14 10:47:48 +1100907</p>
908
Adam Langleyc2e58dc2012-02-14 07:13:57 -0500909<h3 id="bufio">The bufio package</h3>
910
911<p>
912In Go 1, <a href="/pkg/bufio/#NewReaderSize"><code>bufio.NewReaderSize</code></a>
913and
914<a href="/pkg/bufio/#NewWriterSize"><code>bufio.NewWriterSize</code></a>
915functions no longer return an error for invalid sizes.
916If the argument size is too small or invalid, it is adjusted.
917</p>
918
919<p>
920<em>Updating</em>:
Rob Pike5cff0292012-02-24 13:08:11 +1100921Running <code>go</code> <code>fix</code> will update calls that assign the error to _.
Nigel Taoda8f0372012-02-15 14:41:47 +1100922Calls that aren't fixed will be caught by the compiler and must be updated by hand.
Adam Langleyc2e58dc2012-02-14 07:13:57 -0500923</p>
924
Rob Pikec3ef1982012-02-19 14:15:26 +1100925<h3 id="compress">The compress/flate, compress/gzip and compress/zlib packages</h3>
Adam Langleyc2e58dc2012-02-14 07:13:57 -0500926
927<p>
928In Go 1, the <code>NewWriterXxx</code> functions in
929<a href="/pkg/compress/flate"><code>compress/flate</code></a>,
930<a href="/pkg/compress/gzip"><code>compress/gzip</code></a> and
931<a href="/pkg/compress/zlib"><code>compress/zlib</code></a>
932all return <code>(*Writer, error)</code> if they take a compression level,
933and <code>*Writer</code> otherwise. Package <code>gzip</code>'s
934<code>Compressor</code> and <code>Decompressor</code> types have been renamed
935to <code>Writer</code> and <code>Reader</code>. Package <code>flate</code>'s
936<code>WrongValueError</code> type has been removed.
937</p>
938
939<p>
940<em>Updating</em>
Rob Pike5cff0292012-02-24 13:08:11 +1100941Running <code>go</code> <code>fix</code> will update old names and calls that assign the error to _.
Nigel Taoda8f0372012-02-15 14:41:47 +1100942Calls that aren't fixed will be caught by the compiler and must be updated by hand.
Adam Langleyc2e58dc2012-02-14 07:13:57 -0500943</p>
944
Adam Langleycdd7e022012-02-13 12:38:45 -0500945<h3 id="crypto_aes_des">The crypto/aes and crypto/des packages</h3>
Rob Pikebb7b1a12012-02-08 13:07:13 +1100946
947<p>
Adam Langleycdd7e022012-02-13 12:38:45 -0500948In Go 1, the <code>Reset</code> method has been removed. Go does not guarantee
949that memory is not copied and therefore this method was misleading.
950</p>
951
952<p>
953The cipher-specific types <code>*aes.Cipher</code>, <code>*des.Cipher</code>,
954and <code>*des.TripleDESCipher</code> have been removed in favor of
955<code>cipher.Block</code>.
Rob Pikebb7b1a12012-02-08 13:07:13 +1100956</p>
957
958<p>
959<em>Updating</em>:
Adam Langleycdd7e022012-02-13 12:38:45 -0500960Remove the calls to Reset. Replace uses of the specific cipher types with
961cipher.Block.
Nigel Taocc9ed442012-02-10 18:49:19 +1100962</p>
963
Rob Pike0a1376a2012-01-20 14:28:48 -0800964<h3 id="crypto_elliptic">The crypto/elliptic package</h3>
965
966<p>
967In Go 1, <a href="/pkg/crypto/elliptic/#Curve"><code>elliptic.Curve</code></a>
968has been made an interface to permit alternative implementations. The curve
969parameters have been moved to the
970<a href="/pkg/crypto/elliptic/#CurveParams"><code>elliptic.CurveParams</code></a>
971structure.
972</p>
973
974<p>
975<em>Updating</em>:
976Existing users of <code>*elliptic.Curve</code> will need to change to
977simply <code>elliptic.Curve</code>. Calls to <code>Marshal</code>,
978<code>Unmarshal</code> and <code>GenerateKey</code> are now functions
979in <code>crypto/elliptic</code> that take an <code>elliptic.Curve</code>
980as their first argument.
981</p>
982
Rob Pike27836912012-02-04 07:49:51 +1100983<h3 id="crypto_hmac">The crypto/hmac package</h3>
Adam Langley68aff952012-01-27 10:12:27 -0800984
985<p>
986In Go 1, the hash-specific functions, such as <code>hmac.NewMD5</code>, have
987been removed from <code>crypto/hmac</code>. Instead, <code>hmac.New</code> takes
988a function that returns a <code>hash.Hash</code>, such as <code>md5.New</code>.
989</p>
990
991<p>
992<em>Updating</em>:
Rob Pike5cff0292012-02-24 13:08:11 +1100993Running <code>go</code> <code>fix</code> will perform the needed changes.
Adam Langley68aff952012-01-27 10:12:27 -0800994</p>
995
Rob Pike0a1376a2012-01-20 14:28:48 -0800996<h3 id="crypto_x509">The crypto/x509 package</h3>
997
998<p>
999In Go 1, the
1000<a href="/pkg/crypto/x509/#CreateCertificate"><code>CreateCertificate</code></a>
Brad Fitzpatrick12566a62013-04-18 12:43:23 -07001001function and
1002<a href="/pkg/crypto/x509/#Certificate.CreateCRL"><code>CreateCRL</code></a>
1003method in <code>crypto/x509</code> have been altered to take an
Rob Pike0a1376a2012-01-20 14:28:48 -08001004<code>interface{}</code> where they previously took a <code>*rsa.PublicKey</code>
1005or <code>*rsa.PrivateKey</code>. This will allow other public key algorithms
1006to be implemented in the future.
1007</p>
1008
1009<p>
1010<em>Updating</em>:
1011No changes will be needed.
1012</p>
1013
Rob Pike1cd272d2012-03-08 17:15:23 +11001014<h3 id="encoding_binary">The encoding/binary package</h3>
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001015
1016<p>
1017In Go 1, the <code>binary.TotalSize</code> function has been replaced by
1018<a href="/pkg/encoding/binary/#Size"><code>Size</code></a>,
1019which takes an <code>interface{}</code> argument rather than
1020a <code>reflect.Value</code>.
1021</p>
1022
1023<p>
1024<em>Updating</em>:
1025What little code is affected will be caught by the compiler and must be updated by hand.
1026</p>
1027
1028<h3 id="encoding_xml">The encoding/xml package</h3>
1029
1030<p>
1031In Go 1, the <a href="/pkg/encoding/xml/"><code>xml</code></a> package
1032has been brought closer in design to the other marshaling packages such
1033as <a href="/pkg/encoding/gob/"><code>encoding/gob</code></a>.
1034</p>
1035
1036<p>
1037The old <code>Parser</code> type is renamed
1038<a href="/pkg/encoding/xml/#Decoder"><code>Decoder</code></a> and has a new
1039<a href="/pkg/encoding/xml/#Decoder.Decode"><code>Decode</code></a> method. An
Rob Pike9e7e6d92012-02-29 11:29:33 +11001040<a href="/pkg/encoding/xml/#Encoder"><code>Encoder</code></a> type was also introduced.
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001041</p>
1042
1043<p>
1044The functions <a href="/pkg/encoding/xml/#Marshal"><code>Marshal</code></a>
1045and <a href="/pkg/encoding/xml/#Unmarshal"><code>Unmarshal</code></a>
1046work with <code>[]byte</code> values now. To work with streams,
1047use the new <a href="/pkg/encoding/xml/#Encoder"><code>Encoder</code></a>
1048and <a href="/pkg/encoding/xml/#Decoder"><code>Decoder</code></a> types.
1049</p>
1050
1051<p>
1052When marshaling or unmarshaling values, the format of supported flags in
1053field tags has changed to be closer to the
1054<a href="/pkg/encoding/json"><code>json</code></a> package
1055(<code>`xml:"name,flag"`</code>). The matching done between field tags, field
1056names, and the XML attribute and element names is now case-sensitive.
1057The <code>XMLName</code> field tag, if present, must also match the name
1058of the XML element being marshaled.
1059</p>
1060
1061<p>
1062<em>Updating</em>:
Rob Pike5cff0292012-02-24 13:08:11 +11001063Running <code>go</code> <code>fix</code> will update most uses of the package except for some calls to
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001064<code>Unmarshal</code>. Special care must be taken with field tags,
1065since the fix tool will not update them and if not fixed by hand they will
1066misbehave silently in some cases. For example, the old
1067<code>"attr"</code> is now written <code>",attr"</code> while plain
1068<code>"attr"</code> remains valid but with a different meaning.
1069</p>
1070
David Symonds715588f2012-02-04 14:32:05 +11001071<h3 id="expvar">The expvar package</h3>
1072
1073<p>
1074In Go 1, the <code>RemoveAll</code> function has been removed.
1075The <code>Iter</code> function and Iter method on <code>*Map</code> have
1076been replaced by
1077<a href="/pkg/expvar/#Do"><code>Do</code></a>
1078and
1079<a href="/pkg/expvar/#Map.Do"><code>(*Map).Do</code></a>.
1080</p>
1081
1082<p>
1083<em>Updating</em>:
1084Most code using <code>expvar</code> will not need changing. The rare code that used
David Symonds2943ca6b2012-02-04 21:55:38 +11001085<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 +11001086</p>
1087
Rob Pike531ded92012-01-20 15:38:03 -08001088<h3 id="flag">The flag package</h3>
1089
1090<p>
1091In Go 1, the interface <a href="/pkg/flag/#Value"><code>flag.Value</code></a> has changed slightly.
1092The <code>Set</code> method now returns an <code>error</code> instead of
1093a <code>bool</code> to indicate success or failure.
1094</p>
1095
1096<p>
1097There is also a new kind of flag, <code>Duration</code>, to support argument
1098values specifying time intervals.
1099Values for such flags must be given units, just as <code>time.Duration</code>
1100formats them: <code>10s</code>, <code>1h30m</code>, etc.
1101</p>
1102
Russ Coxa40065a2012-03-08 08:39:20 -05001103{{code "/doc/progs/go1.go" `/timeout/`}}
Rob Pike531ded92012-01-20 15:38:03 -08001104
1105<p>
1106<em>Updating</em>:
1107Programs that implement their own flags will need minor manual fixes to update their
1108<code>Set</code> methods.
1109The <code>Duration</code> flag is new and affects no existing code.
1110</p>
1111
1112
Rob Pike0a1376a2012-01-20 14:28:48 -08001113<h3 id="go">The go/* packages</h3>
1114
1115<p>
1116Several packages under <code>go</code> have slightly revised APIs.
1117</p>
1118
1119<p>
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001120A concrete <code>Mode</code> type was introduced for configuration mode flags
1121in the packages
1122<a href="/pkg/go/scanner/"><code>go/scanner</code></a>,
1123<a href="/pkg/go/parser/"><code>go/parser</code></a>,
1124<a href="/pkg/go/printer/"><code>go/printer</code></a>, and
1125<a href="/pkg/go/doc/"><code>go/doc</code></a>.
1126</p>
1127
1128<p>
Rob Pike0a1376a2012-01-20 14:28:48 -08001129The modes <code>AllowIllegalChars</code> and <code>InsertSemis</code> have been removed
1130from the <a href="/pkg/go/scanner/"><code>go/scanner</code></a> package. They were mostly
1131useful for scanning text other then Go source files. Instead, the
1132<a href="/pkg/text/scanner/"><code>text/scanner</code></a> package should be used
1133for that purpose.
1134</p>
1135
1136<p>
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001137The <a href="/pkg/go/scanner/#ErrorHandler"><code>ErrorHandler</code></a> provided
1138to the scanner's <a href="/pkg/go/scanner/#Scanner.Init"><code>Init</code></a> method is
1139now simply a function rather than an interface. The <code>ErrorVector</code> type has
1140been removed in favor of the (existing) <a href="/pkg/go/scanner/#ErrorList"><code>ErrorList</code></a>
1141type, and the <code>ErrorVector</code> methods have been migrated. Instead of embedding
1142an <code>ErrorVector</code> in a client of the scanner, now a client should maintain
1143an <code>ErrorList</code>.
1144</p>
1145
1146<p>
Rob Pike0a1376a2012-01-20 14:28:48 -08001147The set of parse functions provided by the <a href="/pkg/go/parser/"><code>go/parser</code></a>
1148package has been reduced to the primary parse function
Gustavo Niemeyer75e9d242012-01-25 23:42:36 -02001149<a href="/pkg/go/parser/#ParseFile"><code>ParseFile</code></a>, and a couple of
1150convenience functions <a href="/pkg/go/parser/#ParseDir"><code>ParseDir</code></a>
1151and <a href="/pkg/go/parser/#ParseExpr"><code>ParseExpr</code></a>.
Rob Pike0a1376a2012-01-20 14:28:48 -08001152</p>
1153
1154<p>
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001155The <a href="/pkg/go/printer/"><code>go/printer</code></a> package supports an additional
1156configuration mode <a href="/pkg/go/printer/#Mode"><code>SourcePos</code></a>;
1157if set, the printer will emit <code>//line</code> comments such that the generated
1158output contains the original source code position information. The new type
Rob Pike1cd272d2012-03-08 17:15:23 +11001159<a href="/pkg/go/printer/#CommentedNode"><code>CommentedNode</code></a> can be
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001160used to provide comments associated with an arbitrary
1161<a href="/pkg/go/ast/#Node"><code>ast.Node</code></a> (until now only
1162<a href="/pkg/go/ast/#File"><code>ast.File</code></a> carried comment information).
1163</p>
1164
1165<p>
Gustavo Niemeyer75e9d242012-01-25 23:42:36 -02001166The type names of the <a href="/pkg/go/doc/"><code>go/doc</code></a> package have been
Rob Pike0a1376a2012-01-20 14:28:48 -08001167streamlined by removing the <code>Doc</code> suffix: <code>PackageDoc</code>
1168is now <code>Package</code>, <code>ValueDoc</code> is <code>Value</code>, etc.
1169Also, all types now consistently have a <code>Name</code> field (or <code>Names</code>,
Robert Griesemerd571c5c2012-01-25 16:48:06 -08001170in the case of type <code>Value</code>) and <code>Type.Factories</code> has become
1171<code>Type.Funcs</code>.
Rob Pike0a1376a2012-01-20 14:28:48 -08001172Instead of calling <code>doc.NewPackageDoc(pkg, importpath)</code>,
1173documentation for a package is created with:
1174</p>
1175
1176<pre>
1177 doc.New(pkg, importpath, mode)
1178</pre>
1179
1180<p>
1181where the new <code>mode</code> parameter specifies the operation mode:
Gustavo Niemeyer75e9d242012-01-25 23:42:36 -02001182if set to <a href="/pkg/go/doc/#AllDecls"><code>AllDecls</code></a>, all declarations
Rob Pike0a1376a2012-01-20 14:28:48 -08001183(not just exported ones) are considered.
1184The function <code>NewFileDoc</code> was removed, and the function
1185<code>CommentText</code> has become the method
Brad Fitzpatrick12566a62013-04-18 12:43:23 -07001186<a href="/pkg/go/ast/#CommentGroup.Text"><code>Text</code></a> of
Gustavo Niemeyer75e9d242012-01-25 23:42:36 -02001187<a href="/pkg/go/ast/#CommentGroup"><code>ast.CommentGroup</code></a>.
Rob Pike0a1376a2012-01-20 14:28:48 -08001188</p>
1189
1190<p>
Gustavo Niemeyer75e9d242012-01-25 23:42:36 -02001191In package <a href="/pkg/go/token/"><code>go/token</code></a>, the
1192<a href="/pkg/go/token/#FileSet"><code>token.FileSet</code></a> method <code>Files</code>
Rob Pike0a1376a2012-01-20 14:28:48 -08001193(which originally returned a channel of <code>*token.File</code>s) has been replaced
Gustavo Niemeyer75e9d242012-01-25 23:42:36 -02001194with the iterator <a href="/pkg/go/token/#FileSet.Iterate"><code>Iterate</code></a> that
Rob Pike0a1376a2012-01-20 14:28:48 -08001195accepts a function argument instead.
1196</p>
1197
1198<p>
Russ Cox9996f7f2012-03-01 18:17:28 -05001199In package <a href="/pkg/go/build/"><code>go/build</code></a>, the API
1200has been nearly completely replaced.
1201The package still computes Go package information
1202but it does not run the build: the <code>Cmd</code> and <code>Script</code>
1203types are gone.
1204(To build code, use the new
1205<a href="/cmd/go/"><code>go</code></a> command instead.)
1206The <code>DirInfo</code> type is now named
1207<a href="/pkg/go/build/#Package"><code>Package</code></a>.
1208<code>FindTree</code> and <code>ScanDir</code> are replaced by
1209<a href="/pkg/go/build/#Import"><code>Import</code></a>
1210and
1211<a href="/pkg/go/build/#ImportDir"><code>ImportDir</code></a>.
1212</p>
1213
1214<p>
Rob Pike0a1376a2012-01-20 14:28:48 -08001215<em>Updating</em>:
1216Code that uses packages in <code>go</code> will have to be updated by hand; the
Rob Pike68c7e8a2012-02-27 07:31:34 +11001217compiler will reject incorrect uses. Templates used in conjunction with any of the
Rob Pike0a1376a2012-01-20 14:28:48 -08001218<code>go/doc</code> types may need manual fixes; the renamed fields will lead
1219to run-time errors.
1220</p>
1221
Russ Cox1f1c9ba2012-01-18 10:36:43 -05001222<h3 id="hash">The hash package</h3>
1223
1224<p>
1225In Go 1, the definition of <a href="/pkg/hash/#Hash"><code>hash.Hash</code></a> includes
Rob Pike1cd272d2012-03-08 17:15:23 +11001226a new method, <code>BlockSize</code>. This new method is used primarily in the
Russ Cox1f1c9ba2012-01-18 10:36:43 -05001227cryptographic libraries.
1228</p>
1229
1230<p>
Rob Pike03ea8b12012-01-24 16:36:40 -08001231The <code>Sum</code> method of the
1232<a href="/pkg/hash/#Hash"><code>hash.Hash</code></a> interface now takes a
1233<code>[]byte</code> argument, to which the hash value will be appended.
1234The previous behavior can be recreated by adding a <code>nil</code> argument to the call.
1235</p>
1236
1237<p>
Russ Cox1f1c9ba2012-01-18 10:36:43 -05001238<em>Updating</em>:
1239Existing implementations of <code>hash.Hash</code> will need to add a
1240<code>BlockSize</code> method. Hashes that process the input one byte at
1241a time can implement <code>BlockSize</code> to return 1.
Rob Pike5cff0292012-02-24 13:08:11 +11001242Running <code>go</code> <code>fix</code> will update calls to the <code>Sum</code> methods of the various
Rob Pike03ea8b12012-01-24 16:36:40 -08001243implementations of <code>hash.Hash</code>.
Rob Pikef76bd4f2011-12-12 19:25:25 -08001244</p>
1245
1246<p>
1247<em>Updating</em>:
1248Since the package's functionality is new, no updating is necessary.
1249</p>
1250
Rob Pikebab4dec2011-12-07 14:33:37 -08001251<h3 id="http">The http package</h3>
1252
Rob Pikef76bd4f2011-12-12 19:25:25 -08001253<p>
Jongmin Kim343098e2012-01-17 09:47:34 -08001254In Go 1 the <a href="/pkg/net/http/"><code>http</code></a> package is refactored,
Rob Pikef76bd4f2011-12-12 19:25:25 -08001255putting some of the utilities into a
Shenghou Mac80a32b2012-03-30 14:06:12 +08001256<a href="/pkg/net/http/httputil/"><code>httputil</code></a> subdirectory.
Rob Pikef76bd4f2011-12-12 19:25:25 -08001257These pieces are only rarely needed by HTTP clients.
1258The affected items are:
1259</p>
1260
1261<ul>
1262<li>ClientConn</li>
1263<li>DumpRequest</li>
Rob Pikef76bd4f2011-12-12 19:25:25 -08001264<li>DumpRequestOut</li>
1265<li>DumpResponse</li>
1266<li>NewChunkedReader</li>
1267<li>NewChunkedWriter</li>
1268<li>NewClientConn</li>
1269<li>NewProxyClientConn</li>
1270<li>NewServerConn</li>
1271<li>NewSingleHostReverseProxy</li>
1272<li>ReverseProxy</li>
1273<li>ServerConn</li>
1274</ul>
1275
1276<p>
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001277The <code>Request.RawURL</code> field has been removed; it was a
Rob Pikef76bd4f2011-12-12 19:25:25 -08001278historical artifact.
1279</p>
1280
1281<p>
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001282The <code>Handle</code> and <code>HandleFunc</code>
1283functions, and the similarly-named methods of <code>ServeMux</code>,
1284now panic if an attempt is made to register the same pattern twice.
1285</p>
1286
1287<p>
Rob Pikef76bd4f2011-12-12 19:25:25 -08001288<em>Updating</em>:
Rob Pike5cff0292012-02-24 13:08:11 +11001289Running <code>go</code> <code>fix</code> will update the few programs that are affected except for
Rob Pikef76bd4f2011-12-12 19:25:25 -08001290uses of <code>RawURL</code>, which must be fixed by hand.
1291</p>
1292
Rob Pike2257e762012-01-23 16:11:49 -08001293<h3 id="image">The image package</h3>
1294
1295<p>
1296The <a href="/pkg/image/"><code>image</code></a> package has had a number of
1297minor changes, rearrangements and renamings.
1298</p>
1299
1300<p>
1301Most of the color handling code has been moved into its own package,
1302<a href="/pkg/image/color/"><code>image/color</code></a>.
1303For the elements that moved, a symmetry arises; for instance,
1304each pixel of an
1305<a href="/pkg/image/#RGBA"><code>image.RGBA</code></a>
1306is a
1307<a href="/pkg/image/color/#RGBA"><code>color.RGBA</code></a>.
1308</p>
1309
1310<p>
1311The old <code>image/ycbcr</code> package has been folded, with some
1312renamings, into the
1313<a href="/pkg/image/"><code>image</code></a>
1314and
1315<a href="/pkg/image/color/"><code>image/color</code></a>
1316packages.
1317</p>
1318
1319<p>
1320The old <code>image.ColorImage</code> type is still in the <code>image</code>
1321package but has been renamed
1322<a href="/pkg/image/#Uniform"><code>image.Uniform</code></a>,
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001323while <code>image.Tiled</code> has been removed.
Rob Pike2257e762012-01-23 16:11:49 -08001324</p>
1325
1326<p>
1327This table lists the renamings.
1328</p>
1329
1330<table class="codetable" frame="border" summary="image renames">
1331<colgroup align="left" width="50%"></colgroup>
1332<colgroup align="left" width="50%"></colgroup>
1333<tr>
1334<th align="left">Old</th>
1335<th align="left">New</th>
1336</tr>
1337<tr>
1338<td colspan="2"><hr></td>
1339</tr>
1340<tr><td>image.Color</td> <td>color.Color</td></tr>
1341<tr><td>image.ColorModel</td> <td>color.Model</td></tr>
1342<tr><td>image.ColorModelFunc</td> <td>color.ModelFunc</td></tr>
1343<tr><td>image.PalettedColorModel</td> <td>color.Palette</td></tr>
1344<tr>
1345<td colspan="2"><hr></td>
1346</tr>
1347<tr><td>image.RGBAColor</td> <td>color.RGBA</td></tr>
1348<tr><td>image.RGBA64Color</td> <td>color.RGBA64</td></tr>
1349<tr><td>image.NRGBAColor</td> <td>color.NRGBA</td></tr>
1350<tr><td>image.NRGBA64Color</td> <td>color.NRGBA64</td></tr>
1351<tr><td>image.AlphaColor</td> <td>color.Alpha</td></tr>
1352<tr><td>image.Alpha16Color</td> <td>color.Alpha16</td></tr>
1353<tr><td>image.GrayColor</td> <td>color.Gray</td></tr>
1354<tr><td>image.Gray16Color</td> <td>color.Gray16</td></tr>
1355<tr>
1356<td colspan="2"><hr></td>
1357</tr>
1358<tr><td>image.RGBAColorModel</td> <td>color.RGBAModel</td></tr>
1359<tr><td>image.RGBA64ColorModel</td> <td>color.RGBA64Model</td></tr>
1360<tr><td>image.NRGBAColorModel</td> <td>color.NRGBAModel</td></tr>
1361<tr><td>image.NRGBA64ColorModel</td> <td>color.NRGBA64Model</td></tr>
1362<tr><td>image.AlphaColorModel</td> <td>color.AlphaModel</td></tr>
1363<tr><td>image.Alpha16ColorModel</td> <td>color.Alpha16Model</td></tr>
1364<tr><td>image.GrayColorModel</td> <td>color.GrayModel</td></tr>
1365<tr><td>image.Gray16ColorModel</td> <td>color.Gray16Model</td></tr>
1366<tr>
1367<td colspan="2"><hr></td>
1368</tr>
1369<tr><td>ycbcr.RGBToYCbCr</td> <td>color.RGBToYCbCr</td></tr>
1370<tr><td>ycbcr.YCbCrToRGB</td> <td>color.YCbCrToRGB</td></tr>
1371<tr><td>ycbcr.YCbCrColorModel</td> <td>color.YCbCrModel</td></tr>
1372<tr><td>ycbcr.YCbCrColor</td> <td>color.YCbCr</td></tr>
1373<tr><td>ycbcr.YCbCr</td> <td>image.YCbCr</td></tr>
1374<tr>
1375<td colspan="2"><hr></td>
1376</tr>
1377<tr><td>ycbcr.SubsampleRatio444</td> <td>image.YCbCrSubsampleRatio444</td></tr>
1378<tr><td>ycbcr.SubsampleRatio422</td> <td>image.YCbCrSubsampleRatio422</td></tr>
1379<tr><td>ycbcr.SubsampleRatio420</td> <td>image.YCbCrSubsampleRatio420</td></tr>
1380<tr>
1381<td colspan="2"><hr></td>
1382</tr>
1383<tr><td>image.ColorImage</td> <td>image.Uniform</td></tr>
Rob Pike2257e762012-01-23 16:11:49 -08001384</table>
1385
1386<p>
1387The image package's <code>New</code> functions
1388(<a href="/pkg/image/#NewRGBA"><code>NewRGBA</code></a>,
1389<a href="/pkg/image/#NewRGBA64"><code>NewRGBA64</code></a>, etc.)
1390take an <a href="/pkg/image/#Rectangle"><code>image.Rectangle</code></a> as an argument
1391instead of four integers.
1392</p>
1393
1394<p>
1395Finally, there are new predefined <code>color.Color</code> variables
1396<a href="/pkg/image/color/#Black"><code>color.Black</code></a>,
1397<a href="/pkg/image/color/#White"><code>color.White</code></a>,
1398<a href="/pkg/image/color/#Opaque"><code>color.Opaque</code></a>
1399and
1400<a href="/pkg/image/color/#Transparent"><code>color.Transparent</code></a>.
1401</p>
1402
1403<p>
1404<em>Updating</em>:
Rob Pike5cff0292012-02-24 13:08:11 +11001405Running <code>go</code> <code>fix</code> will update almost all code affected by the change.
Rob Pike2257e762012-01-23 16:11:49 -08001406</p>
1407
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001408<h3 id="log_syslog">The log/syslog package</h3>
1409
1410<p>
Rob Pike1cd272d2012-03-08 17:15:23 +11001411In Go 1, the <a href="/pkg/log/syslog/#NewLogger"><code>syslog.NewLogger</code></a>
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001412function returns an error as well as a <code>log.Logger</code>.
1413</p>
1414
1415<p>
1416<em>Updating</em>:
1417What little code is affected will be caught by the compiler and must be updated by hand.
1418</p>
1419
Rob Pikedd442a52012-01-24 17:02:06 -08001420<h3 id="mime">The mime package</h3>
1421
1422<p>
1423In Go 1, the <a href="/pkg/mime/#FormatMediaType"><code>FormatMediaType</code></a> function
1424of the <code>mime</code> package has been simplified to make it
1425consistent with
Rob Pike1cd272d2012-03-08 17:15:23 +11001426<a href="/pkg/mime/#ParseMediaType"><code>ParseMediaType</code></a>.
Rob Pikedd442a52012-01-24 17:02:06 -08001427It now takes <code>"text/html"</code> rather than <code>"text"</code> and <code>"html"</code>.
1428</p>
1429
1430<p>
1431<em>Updating</em>:
1432What little code is affected will be caught by the compiler and must be updated by hand.
1433</p>
1434
Brad Fitzpatrickb71883e2012-01-18 16:24:06 -08001435<h3 id="net">The net package</h3>
1436
Rob Pike03ea8b12012-01-24 16:36:40 -08001437<p>
1438In Go 1, the various <code>SetTimeout</code>,
Brad Fitzpatrickb71883e2012-01-18 16:24:06 -08001439<code>SetReadTimeout</code>, and <code>SetWriteTimeout</code> methods
Rob Pike1cd272d2012-03-08 17:15:23 +11001440have been replaced with
Rob Pike03ea8b12012-01-24 16:36:40 -08001441<a href="/pkg/net/#IPConn.SetDeadline"><code>SetDeadline</code></a>,
Rob Pike1cd272d2012-03-08 17:15:23 +11001442<a href="/pkg/net/#IPConn.SetReadDeadline"><code>SetReadDeadline</code></a>, and
Rob Pike03ea8b12012-01-24 16:36:40 -08001443<a href="/pkg/net/#IPConn.SetWriteDeadline"><code>SetWriteDeadline</code></a>,
Brad Fitzpatrickb71883e2012-01-18 16:24:06 -08001444respectively. Rather than taking a timeout value in nanoseconds that
1445apply to any activity on the connection, the new methods set an
1446absolute deadline (as a <code>time.Time</code> value) after which
Rob Pike03ea8b12012-01-24 16:36:40 -08001447reads and writes will time out and no longer block.
1448</p>
1449
1450<p>
Mikio Hara2f63afd2012-02-01 01:53:26 +09001451There are also new functions
1452<a href="/pkg/net/#DialTimeout"><code>net.DialTimeout</code></a>
1453to simplify timing out dialing a network address and
1454<a href="/pkg/net/#ListenMulticastUDP"><code>net.ListenMulticastUDP</code></a>
1455to allow multicast UDP to listen concurrently across multiple listeners.
1456The <code>net.ListenMulticastUDP</code> function replaces the old
1457<code>JoinGroup</code> and <code>LeaveGroup</code> methods.
Rob Pike03ea8b12012-01-24 16:36:40 -08001458</p>
1459
1460<p>
1461<em>Updating</em>:
1462Code that uses the old methods will fail to compile and must be updated by hand.
Rob Pike27836912012-02-04 07:49:51 +11001463The semantic change makes it difficult for the fix tool to update automatically.
Rob Pike03ea8b12012-01-24 16:36:40 -08001464</p>
Brad Fitzpatrickb71883e2012-01-18 16:24:06 -08001465
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001466<h3 id="os">The os package</h3>
1467
Rob Pikec3ef1982012-02-19 14:15:26 +11001468<p>
1469The <code>Time</code> function has been removed; callers should use
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001470the <a href="/pkg/time/#Time"><code>Time</code></a> type from the
Rob Pikec3ef1982012-02-19 14:15:26 +11001471<code>time</code> package.
1472</p>
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001473
Rob Pikec3ef1982012-02-19 14:15:26 +11001474<p>
1475The <code>Exec</code> function has been removed; callers should use
1476<code>Exec</code> from the <code>syscall</code> package, where available.
1477</p>
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001478
Rob Pikec3ef1982012-02-19 14:15:26 +11001479<p>
1480The <code>ShellExpand</code> function has been renamed to <a
1481href="/pkg/os/#ExpandEnv"><code>ExpandEnv</code></a>.
1482</p>
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001483
Rob Pikec3ef1982012-02-19 14:15:26 +11001484<p>
1485The <a href="/pkg/os/#NewFile"><code>NewFile</code></a> function
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001486now takes a <code>uintptr</code> fd, instead of an <code>int</code>.
1487The <a href="/pkg/os/#File.Fd"><code>Fd</code></a> method on files now
Rob Pikec3ef1982012-02-19 14:15:26 +11001488also returns a <code>uintptr</code>.
1489</p>
1490
1491<p>
1492There are no longer error constants such as <code>EINVAL</code>
1493in the <code>os</code> package, since the set of values varied with
1494the underlying operating system. There are new portable functions like
1495<a href="/pkg/os/#IsPermission"><code>IsPermission</code></a>
1496to test common error properties, plus a few new error values
1497with more Go-like names, such as
1498<a href="/pkg/os/#ErrPermission"><code>ErrPermission</code></a>
1499and
Brad Fitzpatrick12566a62013-04-18 12:43:23 -07001500<a href="/pkg/os/#ErrNotExist"><code>ErrNotExist</code></a>.
Brad Fitzpatrickefacb2a2012-02-18 21:18:13 -08001501</p>
Rob Pikec3ef1982012-02-19 14:15:26 +11001502
Brad Fitzpatrickefacb2a2012-02-18 21:18:13 -08001503<p>
1504The <code>Getenverror</code> function has been removed. To distinguish
1505between a non-existent environment variable and an empty string,
1506use <a href="/pkg/os/#Environ"><code>os.Environ</code></a> or
1507<a href="/pkg/syscall/#Getenv"><code>syscall.Getenv</code></a>.
1508</p>
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001509
Rob Pikeb5a3bd52012-02-20 15:36:08 +11001510
1511<p>
1512The <a href="/pkg/os/#Process.Wait"><code>Process.Wait</code></a> method has
1513dropped its option argument and the associated constants are gone
1514from the package.
1515Also, the function <code>Wait</code> is gone; only the method of
1516the <code>Process</code> type persists.
1517</p>
1518
Nigel Taoda8f0372012-02-15 14:41:47 +11001519<p>
Rob Pike5cff0292012-02-24 13:08:11 +11001520The <code>Waitmsg</code> type returned by
1521<a href="/pkg/os/#Process.Wait"><code>Process.Wait</code></a>
1522has been replaced with a more portable
1523<a href="/pkg/os/#ProcessState"><code>ProcessState</code></a>
1524type with accessor methods to recover information about the
1525process.
1526Because of changes to <code>Wait</code>, the <code>ProcessState</code>
1527value always describes an exited process.
1528Portability concerns simplified the interface in other ways, but the values returned by the
1529<a href="/pkg/os/#ProcessState.Sys"><code>ProcessState.Sys</code></a> and
1530<a href="/pkg/os/#ProcessState.SysUsage"><code>ProcessState.SysUsage</code></a>
1531methods can be type-asserted to underlying system-specific data structures such as
1532<a href="/pkg/syscall/#WaitStatus"><code>syscall.WaitStatus</code></a> and
1533<a href="/pkg/syscall/#Rusage"><code>syscall.Rusage</code></a> on Unix.
1534</p>
1535
1536<p>
Nigel Taoda8f0372012-02-15 14:41:47 +11001537<em>Updating</em>:
Rob Pike5cff0292012-02-24 13:08:11 +11001538Running <code>go</code> <code>fix</code> will drop a zero argument to <code>Process.Wait</code>.
1539All other changes will be caught by the compiler and must be updated by hand.
Nigel Taoda8f0372012-02-15 14:41:47 +11001540</p>
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001541
1542<h4 id="os_fileinfo">The os.FileInfo type</h4>
Rob Pike0a1376a2012-01-20 14:28:48 -08001543
1544<p>
1545Go 1 redefines the <a href="/pkg/os/#FileInfo"><code>os.FileInfo</code></a> type,
1546changing it from a struct to an interface:
1547</p>
1548
1549<pre>
1550 type FileInfo interface {
1551 Name() string // base name of the file
1552 Size() int64 // length in bytes
1553 Mode() FileMode // file mode bits
1554 ModTime() time.Time // modification time
1555 IsDir() bool // abbreviation for Mode().IsDir()
Rob Pike46dc76f2012-02-12 09:17:57 +11001556 Sys() interface{} // underlying data source (can return nil)
Rob Pike0a1376a2012-01-20 14:28:48 -08001557 }
1558</pre>
1559
1560<p>
1561The file mode information has been moved into a subtype called
1562<a href="/pkg/os/#FileMode"><code>os.FileMode</code></a>,
1563a simple integer type with <code>IsDir</code>, <code>Perm</code>, and <code>String</code>
1564methods.
1565</p>
1566
1567<p>
1568The system-specific details of file modes and properties such as (on Unix)
1569i-number have been removed from <code>FileInfo</code> altogether.
1570Instead, each operating system's <code>os</code> package provides an
Rob Pike6ba77ec2012-02-21 08:03:03 +11001571implementation of the <code>FileInfo</code> interface, which
1572has a <code>Sys</code> method that returns the
Rob Pike0a1376a2012-01-20 14:28:48 -08001573system-specific representation of file metadata.
1574For instance, to discover the i-number of a file on a Unix system, unpack
1575the <code>FileInfo</code> like this:
1576</p>
1577
1578<pre>
1579 fi, err := os.Stat("hello.go")
1580 if err != nil {
1581 log.Fatal(err)
1582 }
Rob Pike46dc76f2012-02-12 09:17:57 +11001583 // Check that it's a Unix file.
1584 unixStat, ok := fi.Sys().(*syscall.Stat_t)
Rob Pike0a1376a2012-01-20 14:28:48 -08001585 if !ok {
1586 log.Fatal("hello.go: not a Unix file")
1587 }
1588 fmt.Printf("file i-number: %d\n", unixStat.Ino)
1589</pre>
1590
1591<p>
1592Assuming (which is unwise) that <code>"hello.go"</code> is a Unix file,
1593the i-number expression could be contracted to
1594</p>
1595
1596<pre>
Rob Pikeaee1c382012-02-13 08:05:53 +11001597 fi.Sys().(*syscall.Stat_t).Ino
Rob Pike0a1376a2012-01-20 14:28:48 -08001598</pre>
1599
1600<p>
1601The vast majority of uses of <code>FileInfo</code> need only the methods
1602of the standard interface.
1603</p>
Rob Pike56069f02012-02-17 10:04:29 +11001604
1605<p>
1606The <code>os</code> package no longer contains wrappers for the POSIX errors
1607such as <code>ENOENT</code>.
1608For the few programs that need to verify particular error conditions, there are
1609now the boolean functions
1610<a href="/pkg/os/#IsExist"><code>IsExist</code></a>,
1611<a href="/pkg/os/#IsNotExist"><code>IsNotExist</code></a>
1612and
1613<a href="/pkg/os/#IsPermission"><code>IsPermission</code></a>.
1614</p>
1615
Russ Coxa40065a2012-03-08 08:39:20 -05001616{{code "/doc/progs/go1.go" `/os\.Open/` `/}/`}}
Rob Pike56069f02012-02-17 10:04:29 +11001617
Rob Pike0a1376a2012-01-20 14:28:48 -08001618<p>
1619<em>Updating</em>:
Rob Pike5cff0292012-02-24 13:08:11 +11001620Running <code>go</code> <code>fix</code> will update code that uses the old equivalent of the current <code>os.FileInfo</code>
Rob Pike0a1376a2012-01-20 14:28:48 -08001621and <code>os.FileMode</code> API.
1622Code that needs system-specific file details will need to be updated by hand.
Rob Pike56069f02012-02-17 10:04:29 +11001623Code that uses the old POSIX error values from the <code>os</code> package
1624will fail to compile and will also need to be updated by hand.
Rob Pike0a1376a2012-01-20 14:28:48 -08001625</p>
1626
Rob Pikecc7e11c2012-02-27 14:34:16 +11001627<h3 id="os_signal">The os/signal package</h3>
1628
1629<p>
1630The <code>os/signal</code> package in Go 1 replaces the
1631<code>Incoming</code> function, which returned a channel
1632that received all incoming signals,
1633with the selective <code>Notify</code> function, which asks
1634for delivery of specific signals on an existing channel.
1635</p>
1636
1637<p>
1638<em>Updating</em>:
1639Code must be updated by hand.
1640A literal translation of
1641</p>
1642<pre>
1643c := signal.Incoming()
1644</pre>
1645<p>
1646is
1647</p>
1648<pre>
1649c := make(chan os.Signal)
1650signal.Notify(c) // ask for all signals
1651</pre>
1652<p>
1653but most code should list the specific signals it wants to handle instead:
1654</p>
1655<pre>
1656c := make(chan os.Signal)
1657signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT)
1658</pre>
1659
Rob Pikedd442a52012-01-24 17:02:06 -08001660<h3 id="path_filepath">The path/filepath package</h3>
1661
1662<p>
1663In Go 1, the <a href="/pkg/path/filepath/#Walk"><code>Walk</code></a> function of the
1664<code>path/filepath</code> package
1665has been changed to take a function value of type
1666<a href="/pkg/path/filepath/#WalkFunc"><code>WalkFunc</code></a>
1667instead of a <code>Visitor</code> interface value.
1668<code>WalkFunc</code> unifies the handling of both files and directories.
1669</p>
1670
1671<pre>
Mike Rosset4af3dda2012-02-24 22:17:21 -08001672 type WalkFunc func(path string, info os.FileInfo, err error) error
Rob Pikedd442a52012-01-24 17:02:06 -08001673</pre>
1674
1675<p>
1676The <code>WalkFunc</code> function will be called even for files or directories that could not be opened;
1677in such cases the error argument will describe the failure.
1678If a directory's contents are to be skipped,
Péter Surányibe7c0f32012-12-29 10:41:39 +11001679the function should return the value <a href="/pkg/path/filepath/#pkg-variables"><code>filepath.SkipDir</code></a>
Rob Pikedd442a52012-01-24 17:02:06 -08001680</p>
1681
Russ Coxa40065a2012-03-08 08:39:20 -05001682{{code "/doc/progs/go1.go" `/STARTWALK/` `/ENDWALK/`}}
Rob Pikedd442a52012-01-24 17:02:06 -08001683
1684<p>
1685<em>Updating</em>:
1686The change simplifies most code but has subtle consequences, so affected programs
1687will need to be updated by hand.
1688The compiler will catch code using the old interface.
1689</p>
1690
Rob Pikecc7e11c2012-02-27 14:34:16 +11001691<h3 id="regexp">The regexp package</h3>
Russ Cox35586f72012-02-13 13:52:37 -05001692
1693<p>
Rob Pikecc7e11c2012-02-27 14:34:16 +11001694The <a href="/pkg/regexp/"><code>regexp</code></a> package has been rewritten.
Rob Pike1cd272d2012-03-08 17:15:23 +11001695It has the same interface but the specification of the regular expressions
Rob Pikecc7e11c2012-02-27 14:34:16 +11001696it supports has changed from the old "egrep" form to that of
Stefan Nilsson4fae9f72012-02-28 09:22:55 +11001697<a href="http://code.google.com/p/re2/">RE2</a>.
Russ Cox35586f72012-02-13 13:52:37 -05001698</p>
1699
1700<p>
1701<em>Updating</em>:
Rob Pikecc7e11c2012-02-27 14:34:16 +11001702Code that uses the package should have its regular expressions checked by hand.
Russ Cox35586f72012-02-13 13:52:37 -05001703</p>
Russ Cox35586f72012-02-13 13:52:37 -05001704
Rob Pike531ded92012-01-20 15:38:03 -08001705<h3 id="runtime">The runtime package</h3>
1706
1707<p>
Russ Cox72f5a912012-02-19 18:04:38 -05001708In Go 1, much of the API exported by package
1709<code>runtime</code> has been removed in favor of
1710functionality provided by other packages.
1711Code using the <code>runtime.Type</code> interface
1712or its specific concrete type implementations should
1713now use package <a href="/pkg/reflect/"><code>reflect</code></a>.
1714Code using <code>runtime.Semacquire</code> or <code>runtime.Semrelease</code>
1715should use channels or the abstractions in package <a href="/pkg/sync/"><code>sync</code></a>.
1716The <code>runtime.Alloc</code>, <code>runtime.Free</code>,
1717and <code>runtime.Lookup</code> functions, an unsafe API created for
1718debugging the memory allocator, have no replacement.
1719</p>
1720
1721<p>
1722Before, <code>runtime.MemStats</code> was a global variable holding
1723statistics about memory allocation, and calls to <code>runtime.UpdateMemStats</code>
1724ensured that it was up to date.
1725In Go 1, <code>runtime.MemStats</code> is a struct type, and code should use
1726<a href="/pkg/runtime/#ReadMemStats"><code>runtime.ReadMemStats</code></a>
1727to obtain the current statistics.
1728</p>
1729
1730<p>
1731The package adds a new function,
Rob Pike531ded92012-01-20 15:38:03 -08001732<a href="/pkg/runtime/#NumCPU"><code>runtime.NumCPU</code></a>, that returns the number of CPUs available
1733for parallel execution, as reported by the operating system kernel.
1734Its value can inform the setting of <code>GOMAXPROCS</code>.
Russ Cox72f5a912012-02-19 18:04:38 -05001735The <code>runtime.Cgocalls</code> and <code>runtime.Goroutines</code> functions
1736have been renamed to <code>runtime.NumCgoCall</code> and <code>runtime.NumGoroutine</code>.
Rob Pike531ded92012-01-20 15:38:03 -08001737</p>
1738
1739<p>
1740<em>Updating</em>:
Rob Pike5cff0292012-02-24 13:08:11 +11001741Running <code>go</code> <code>fix</code> will update code for the function renamings.
Russ Cox72f5a912012-02-19 18:04:38 -05001742Other code will need to be updated by hand.
Rob Pike531ded92012-01-20 15:38:03 -08001743</p>
1744
Rob Pikebab4dec2011-12-07 14:33:37 -08001745<h3 id="strconv">The strconv package</h3>
1746
Rob Pike71ccf732011-12-09 14:12:51 -08001747<p>
1748In Go 1, the
Rob Pikeebdcbf12011-12-12 12:26:56 -08001749<a href="/pkg/strconv/"><code>strconv</code></a>
Rob Pike71ccf732011-12-09 14:12:51 -08001750package has been significantly reworked to make it more Go-like and less C-like,
1751although <code>Atoi</code> lives on (it's similar to
1752<code>int(ParseInt(x, 10, 0))</code>, as does
1753<code>Itoa(x)</code> (<code>FormatInt(int64(x), 10)</code>).
1754There are also new variants of some of the functions that append to byte slices rather than
1755return strings, to allow control over allocation.
1756</p>
1757
1758<p>
1759This table summarizes the renamings; see the
Rob Pikeebdcbf12011-12-12 12:26:56 -08001760<a href="/pkg/strconv/">package documentation</a>
Rob Pike71ccf732011-12-09 14:12:51 -08001761for full details.
1762</p>
1763
1764<table class="codetable" frame="border" summary="strconv renames">
1765<colgroup align="left" width="50%"></colgroup>
1766<colgroup align="left" width="50%"></colgroup>
1767<tr>
1768<th align="left">Old call</th>
1769<th align="left">New call</th>
1770</tr>
1771<tr>
1772<td colspan="2"><hr></td>
1773</tr>
1774<tr><td>Atob(x)</td> <td>ParseBool(x)</td></tr>
1775<tr>
1776<td colspan="2"><hr></td>
1777</tr>
1778<tr><td>Atof32(x)</td> <td>ParseFloat(x, 32)§</td></tr>
1779<tr><td>Atof64(x)</td> <td>ParseFloat(x, 64)</td></tr>
1780<tr><td>AtofN(x, n)</td> <td>ParseFloat(x, n)</td></tr>
1781<tr>
1782<td colspan="2"><hr></td>
1783</tr>
1784<tr><td>Atoi(x)</td> <td>Atoi(x)</td></tr>
1785<tr><td>Atoi(x)</td> <td>ParseInt(x, 10, 0)§</td></tr>
1786<tr><td>Atoi64(x)</td> <td>ParseInt(x, 10, 64)</td></tr>
1787<tr>
1788<td colspan="2"><hr></td>
1789</tr>
1790<tr><td>Atoui(x)</td> <td>ParseUint(x, 10, 0)§</td></tr>
Dave Cheneyd7bc6442012-04-11 10:59:03 +10001791<tr><td>Atoui64(x)</td> <td>ParseUint(x, 10, 64)</td></tr>
Rob Pike71ccf732011-12-09 14:12:51 -08001792<tr>
1793<td colspan="2"><hr></td>
1794</tr>
1795<tr><td>Btoi64(x, b)</td> <td>ParseInt(x, b, 64)</td></tr>
1796<tr><td>Btoui64(x, b)</td> <td>ParseUint(x, b, 64)</td></tr>
1797<tr>
1798<td colspan="2"><hr></td>
1799</tr>
1800<tr><td>Btoa(x)</td> <td>FormatBool(x)</td></tr>
1801<tr>
1802<td colspan="2"><hr></td>
1803</tr>
Marcel van Lohuizen72fb81e2012-02-19 19:26:05 +01001804<tr><td>Ftoa32(x, f, p)</td> <td>FormatFloat(float64(x), f, p, 32)</td></tr>
Rob Pike71ccf732011-12-09 14:12:51 -08001805<tr><td>Ftoa64(x, f, p)</td> <td>FormatFloat(x, f, p, 64)</td></tr>
1806<tr><td>FtoaN(x, f, p, n)</td> <td>FormatFloat(x, f, p, n)</td></tr>
1807<tr>
1808<td colspan="2"><hr></td>
1809</tr>
1810<tr><td>Itoa(x)</td> <td>Itoa(x)</td></tr>
1811<tr><td>Itoa(x)</td> <td>FormatInt(int64(x), 10)</td></tr>
1812<tr><td>Itoa64(x)</td> <td>FormatInt(x, 10)</td></tr>
1813<tr>
1814<td colspan="2"><hr></td>
1815</tr>
1816<tr><td>Itob(x, b)</td> <td>FormatInt(int64(x), b)</td></tr>
1817<tr><td>Itob64(x, b)</td> <td>FormatInt(x, b)</td></tr>
1818<tr>
1819<td colspan="2"><hr></td>
1820</tr>
1821<tr><td>Uitoa(x)</td> <td>FormatUint(uint64(x), 10)</td></tr>
1822<tr><td>Uitoa64(x)</td> <td>FormatUint(x, 10)</td></tr>
1823<tr>
1824<td colspan="2"><hr></td>
1825</tr>
1826<tr><td>Uitob(x, b)</td> <td>FormatUint(uint64(x), b)</td></tr>
1827<tr><td>Uitob64(x, b)</td> <td>FormatUint(x, b)</td></tr>
1828</table>
1829
1830<p>
1831<em>Updating</em>:
Rob Pike5cff0292012-02-24 13:08:11 +11001832Running <code>go</code> <code>fix</code> will update almost all code affected by the change.
Rob Pike71ccf732011-12-09 14:12:51 -08001833<br>
1834§ <code>Atoi</code> persists but <code>Atoui</code> and <code>Atof32</code> do not, so
1835they may require
Rob Pike5cff0292012-02-24 13:08:11 +11001836a cast that must be added by hand; the <code>go</code> <code>fix</code> tool will warn about it.
Rob Pike71ccf732011-12-09 14:12:51 -08001837</p>
1838
Rob Pikebab4dec2011-12-07 14:33:37 -08001839
Rob Pike1cd272d2012-03-08 17:15:23 +11001840<h3 id="templates">The template packages</h3>
1841
1842<p>
1843The <code>template</code> and <code>exp/template/html</code> packages have moved to
1844<a href="/pkg/text/template/"><code>text/template</code></a> and
1845<a href="/pkg/html/template/"><code>html/template</code></a>.
1846More significant, the interface to these packages has been simplified.
1847The template language is the same, but the concept of "template set" is gone
1848and the functions and methods of the packages have changed accordingly,
1849often by elimination.
1850</p>
1851
1852<p>
1853Instead of sets, a <code>Template</code> object
1854may contain multiple named template definitions,
1855in effect constructing
1856name spaces for template invocation.
1857A template can invoke any other template associated with it, but only those
1858templates associated with it.
1859The simplest way to associate templates is to parse them together, something
1860made easier with the new structure of the packages.
1861</p>
1862
1863<p>
1864<em>Updating</em>:
1865The imports will be updated by fix tool.
1866Single-template uses will be otherwise be largely unaffected.
1867Code that uses multiple templates in concert will need to be updated by hand.
Péter Surányibe7c0f32012-12-29 10:41:39 +11001868The <a href="/pkg/text/template/#pkg-examples">examples</a> in
Rob Pike1cd272d2012-03-08 17:15:23 +11001869the documentation for <code>text/template</code> can provide guidance.
1870</p>
1871
Rob Pike531ded92012-01-20 15:38:03 -08001872<h3 id="testing">The testing package</h3>
1873
1874<p>
1875The testing package has a type, <code>B</code>, passed as an argument to benchmark functions.
1876In Go 1, <code>B</code> has new methods, analogous to those of <code>T</code>, enabling
1877logging and failure reporting.
1878</p>
1879
Russ Coxa40065a2012-03-08 08:39:20 -05001880{{code "/doc/progs/go1.go" `/func.*Benchmark/` `/^}/`}}
Rob Pike531ded92012-01-20 15:38:03 -08001881
1882<p>
1883<em>Updating</em>:
1884Existing code is unaffected, although benchmarks that use <code>println</code>
Rob Pike2257e762012-01-23 16:11:49 -08001885or <code>panic</code> should be updated to use the new methods.
Rob Pike531ded92012-01-20 15:38:03 -08001886</p>
1887
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001888<h3 id="testing_script">The testing/script package</h3>
1889
1890<p>
1891The testing/script package has been deleted. It was a dreg.
1892</p>
1893
1894<p>
1895<em>Updating</em>:
1896No code is likely to be affected.
1897</p>
1898
Russ Cox72f5a912012-02-19 18:04:38 -05001899<h3 id="unsafe">The unsafe package</h3>
1900
1901<p>
1902In Go 1, the functions
1903<code>unsafe.Typeof</code>, <code>unsafe.Reflect</code>,
1904<code>unsafe.Unreflect</code>, <code>unsafe.New</code>, and
1905<code>unsafe.NewArray</code> have been removed;
1906they duplicated safer functionality provided by
1907package <a href="/pkg/reflect/"><code>reflect</code></a>.
1908</p>
1909
1910<p>
1911<em>Updating</em>:
1912Code using these functions must be rewritten to use
1913package <a href="/pkg/reflect/"><code>reflect</code></a>.
1914The changes to <a href="http://code.google.com/p/go/source/detail?r=2646dc956207">encoding/gob</a> and the <a href="http://code.google.com/p/goprotobuf/source/detail?r=5340ad310031">protocol buffer library</a>
1915may be helpful as examples.
1916</p>
1917
Gustavo Niemeyer805d6202012-01-25 23:11:25 -02001918<h3 id="url">The url package</h3>
1919
1920<p>
Gustavo Niemeyer7b504852012-01-26 00:59:50 -02001921In 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 -02001922were removed or replaced.
1923</p>
1924
1925<p>
Gustavo Niemeyer7b504852012-01-26 00:59:50 -02001926The <a href="/pkg/net/url/#URL.String"><code>String</code></a> method now
Gustavo Niemeyer805d6202012-01-25 23:11:25 -02001927predictably rebuilds an encoded URL string using all of <code>URL</code>'s
1928fields as necessary. The resulting string will also no longer have
1929passwords escaped.
1930</p>
1931
1932<p>
1933The <code>Raw</code> field has been removed. In most cases the <code>String</code>
1934method may be used in its place.
1935</p>
1936
1937<p>
1938The old <code>RawUserinfo</code> field is replaced by the <code>User</code>
Gustavo Niemeyer7b504852012-01-26 00:59:50 -02001939field, of type <a href="/pkg/net/url/#Userinfo"><code>*net.Userinfo</code></a>.
1940Values of this type may be created using the new <a href="/pkg/net/url/#User"><code>net.User</code></a>
1941and <a href="/pkg/net/url/#UserPassword"><code>net.UserPassword</code></a>
Gustavo Niemeyer805d6202012-01-25 23:11:25 -02001942functions. The <code>EscapeUserinfo</code> and <code>UnescapeUserinfo</code>
1943functions are also gone.
1944</p>
1945
1946<p>
1947The <code>RawAuthority</code> field has been removed. The same information is
1948available in the <code>Host</code> and <code>User</code> fields.
1949</p>
1950
1951<p>
1952The <code>RawPath</code> field and the <code>EncodedPath</code> method have
1953been removed. The path information in rooted URLs (with a slash following the
1954schema) is now available only in decoded form in the <code>Path</code> field.
1955Occasionally, the encoded data may be required to obtain information that
1956was lost in the decoding process. These cases must be handled by accessing
1957the data the URL was built from.
1958</p>
1959
1960<p>
1961URLs with non-rooted paths, such as <code>"mailto:dev@golang.org?subject=Hi"</code>,
1962are also handled differently. The <code>OpaquePath</code> boolean field has been
1963removed and a new <code>Opaque</code> string field introduced to hold the encoded
1964path for such URLs. In Go 1, the cited URL parses as:
1965</p>
1966
1967<pre>
1968 URL{
1969 Scheme: "mailto",
1970 Opaque: "dev@golang.org",
1971 RawQuery: "subject=Hi",
1972 }
1973</pre>
1974
1975<p>
Gustavo Niemeyer7b504852012-01-26 00:59:50 -02001976A new <a href="/pkg/net/url/#URL.RequestURI"><code>RequestURI</code></a> method was
Gustavo Niemeyer805d6202012-01-25 23:11:25 -02001977added to <code>URL</code>.
1978</p>
1979
1980<p>
David Symonds83427932012-02-16 15:56:03 +11001981The <code>ParseWithReference</code> function has been renamed to <code>ParseWithFragment</code>.
1982</p>
1983
1984<p>
Gustavo Niemeyer805d6202012-01-25 23:11:25 -02001985<em>Updating</em>:
1986Code that uses the old fields will fail to compile and must be updated by hand.
Rob Pike27836912012-02-04 07:49:51 +11001987The semantic changes make it difficult for the fix tool to update automatically.
Gustavo Niemeyer805d6202012-01-25 23:11:25 -02001988</p>
1989
Russ Cox1a0c8fe2012-02-19 13:32:55 -05001990<h2 id="cmd_go">The go command</h2>
1991
1992<p>
Andrew Gerrand70db2372012-03-08 16:09:49 +11001993Go 1 introduces the <a href="/cmd/go/">go command</a>, a tool for fetching,
1994building, and installing Go packages and commands. The <code>go</code> command
1995does away with makefiles, instead using Go source code to find dependencies and
1996determine build conditions. Most existing Go programs will no longer require
1997makefiles to be built.
1998</p>
1999
2000<p>
2001See <a href="/doc/code.html">How to Write Go Code</a> for a primer on the
2002<code>go</code> command and the <a href="/cmd/go/">go command documentation</a>
2003for the full details.
2004</p>
2005
2006<p>
2007<em>Updating</em>:
2008Projects that depend on the Go project's old makefile-based build
2009infrastructure (<code>Make.pkg</code>, <code>Make.cmd</code>, and so on) should
2010switch to using the <code>go</code> command for building Go code and, if
2011necessary, rewrite their makefiles to perform any auxiliary build tasks.
Russ Cox1a0c8fe2012-02-19 13:32:55 -05002012</p>
2013
2014<h2 id="cmd_cgo">The cgo command</h2>
2015
2016<p>
2017In Go 1, the <a href="/cmd/cgo">cgo command</a>
2018uses a different <code>_cgo_export.h</code>
2019file, which is generated for packages containing <code>//export</code> lines.
2020The <code>_cgo_export.h</code> file now begins with the C preamble comment,
2021so that exported function definitions can use types defined there.
2022This has the effect of compiling the preamble multiple times, so a
2023package using <code>//export</code> must not put function definitions
2024or variable initializations in the C preamble.
Rob Pikeb5a3bd52012-02-20 15:36:08 +11002025</p>
Rob Pikebab4dec2011-12-07 14:33:37 -08002026
2027<h2 id="releases">Packaged releases</h2>
2028
Rob Pikec5f695e2012-03-24 10:14:07 +11002029<p>
2030One of the most significant changes associated with Go 1 is the availability
2031of prepackaged, downloadable distributions.
2032They are available for many combinations of architecture and operating system
2033(including Windows) and the list will grow.
2034Installation details are described on the
2035<a href="/doc/install">Getting Started</a> page, while
2036the distributions themselves are listed on the
2037<a href="http://code.google.com/p/go/downloads/list">downloads page</a>.