blob: 1665d74e955d66688f95392ef5673b610eaf357e [file] [log] [blame]
Andrew Gerrand7cb21a72012-01-19 11:24:54 +11001<!--{
Russ Coxa40065a2012-03-08 08:39:20 -05002 "Title": "Go 1 Release Notes",
Andrew Gerrand5dd74172013-09-16 15:47:13 +10003 "Path": "/doc/go1",
Russ Coxa40065a2012-03-08 08:39:20 -05004 "Template": true
Andrew Gerrand7cb21a72012-01-19 11:24:54 +11005}-->
Rob Pikebab4dec2011-12-07 14:33:37 -08006
7<h2 id="introduction">Introduction to Go 1</h2>
8
9<p>
Rob Pikeb36d25f2012-02-25 08:02:35 +110010Go version 1, Go 1 for short, defines a language and a set of core libraries
11that provide a stable foundation for creating reliable products, projects, and
12publications.
Rob Pikebab4dec2011-12-07 14:33:37 -080013</p>
14
15<p>
Rob Pikeb36d25f2012-02-25 08:02:35 +110016The driving motivation for Go 1 is stability for its users. People should be able to
17write Go programs and expect that they will continue to compile and run without
18change, on a time scale of years, including in production environments such as
19Google App Engine. Similarly, people should be able to write books about Go, be
20able to say which version of Go the book is describing, and have that version
21number still be meaningful much later.
Rob Pikebab4dec2011-12-07 14:33:37 -080022</p>
23
24<p>
Rob Pikeb36d25f2012-02-25 08:02:35 +110025Code that compiles in Go 1 should, with few exceptions, continue to compile and
26run throughout the lifetime of that version, even as we issue updates and bug
27fixes such as Go version 1.1, 1.2, and so on. Other than critical fixes, changes
28made to the language and library for subsequent releases of Go 1 may
29add functionality but will not break existing Go 1 programs.
30<a href="go1compat.html">The Go 1 compatibility document</a>
31explains the compatibility guidelines in more detail.
32</p>
33
34<p>
35Go 1 is a representation of Go as it used today, not a wholesale rethinking of
36the language. We avoided designing new features and instead focused on cleaning
37up problems and inconsistencies and improving portability. There are a number
38changes to the Go language and packages that we had considered for some time and
39prototyped but not released primarily because they are significant and
40backwards-incompatible. Go 1 was an opportunity to get them out, which is
41helpful for the long term, but also means that Go 1 introduces incompatibilities
42for old programs. Fortunately, the <code>go</code> <code>fix</code> tool can
43automate much of the work needed to bring programs up to the Go 1 standard.
44</p>
45
46<p>
47This document outlines the major changes in Go 1 that will affect programmers
48updating existing code; its reference point is the prior release, r60 (tagged as
49r60.3). It also explains how to update code from r60 to run under Go 1.
Rob Pike136c04f2011-12-08 16:39:05 -080050</p>
Rob Pikebab4dec2011-12-07 14:33:37 -080051
52<h2 id="language">Changes to the language</h2>
53
54<h3 id="append">Append</h3>
55
Rob Pike136c04f2011-12-08 16:39:05 -080056<p>
Rob Pike68c7e8a2012-02-27 07:31:34 +110057The <code>append</code> predeclared variadic function makes it easy to grow a slice
58by adding elements to the end.
59A common use is to add bytes to the end of a byte slice when generating output.
60However, <code>append</code> did not provide a way to append a string to a <code>[]byte</code>,
61which is another common case.
Rob Pike136c04f2011-12-08 16:39:05 -080062</p>
63
Russ Coxa40065a2012-03-08 08:39:20 -050064{{code "/doc/progs/go1.go" `/greeting := ..byte/` `/append.*hello/`}}
Rob Pike136c04f2011-12-08 16:39:05 -080065
66<p>
67By analogy with the similar property of <code>copy</code>, Go 1
68permits a string to be appended (byte-wise) directly to a byte
Rob Pike68c7e8a2012-02-27 07:31:34 +110069slice, reducing the friction between strings and byte slices.
70The conversion is no longer necessary:
Rob Pike136c04f2011-12-08 16:39:05 -080071</p>
72
Russ Coxa40065a2012-03-08 08:39:20 -050073{{code "/doc/progs/go1.go" `/append.*world/`}}
Rob Pike136c04f2011-12-08 16:39:05 -080074
75<p>
76<em>Updating</em>:
77This is a new feature, so existing code needs no changes.
78</p>
79
Rob Pikebab4dec2011-12-07 14:33:37 -080080<h3 id="close">Close</h3>
81
Rob Pike136c04f2011-12-08 16:39:05 -080082<p>
Rob Pike68c7e8a2012-02-27 07:31:34 +110083The <code>close</code> predeclared function provides a mechanism
84for a sender to signal that no more values will be sent.
85It is important to the implementation of <code>for</code> <code>range</code>
86loops over channels and is helpful in other situations.
87Partly by design and partly because of race conditions that can occur otherwise,
88it is intended for use only by the goroutine sending on the channel,
89not by the goroutine receiving data.
90However, before Go 1 there was no compile-time checking that <code>close</code>
91was being used correctly.
92</p>
93
94<p>
95To close this gap, at least in part, Go 1 disallows <code>close</code> on receive-only channels.
96Attempting to close such a channel is a compile-time error.
Rob Pike136c04f2011-12-08 16:39:05 -080097</p>
98
99<pre>
100 var c chan int
Robert Hencke7c9ee5f2012-01-25 21:09:46 -0800101 var csend chan&lt;- int = c
102 var crecv &lt;-chan int = c
Rob Pike136c04f2011-12-08 16:39:05 -0800103 close(c) // legal
104 close(csend) // legal
105 close(crecv) // illegal
106</pre>
107
108<p>
109<em>Updating</em>:
110Existing code that attempts to close a receive-only channel was
111erroneous even before Go 1 and should be fixed. The compiler will
112now reject such code.
113</p>
114
Rob Pike9d59c402011-12-08 11:35:28 -0800115<h3 id="literals">Composite literals</h3>
Rob Pikebab4dec2011-12-07 14:33:37 -0800116
Rob Pike2e338fa2011-12-09 08:31:57 -0800117<p>
118In Go 1, a composite literal of array, slice, or map type can elide the
119type specification for the elements' initializers if they are of pointer type.
120All four of the initializations in this example are legal; the last one was illegal before Go 1.
121</p>
122
Russ Coxa40065a2012-03-08 08:39:20 -0500123{{code "/doc/progs/go1.go" `/type Date struct/` `/STOP/`}}
Rob Pike2e338fa2011-12-09 08:31:57 -0800124
125<p>
126<em>Updating</em>:
127This change has no effect on existing code, but the command
128<code>gofmt</code> <code>-s</code> applied to existing source
129will, among other things, elide explicit element types wherever permitted.
130</p>
131
132
Rob Pike9d59c402011-12-08 11:35:28 -0800133<h3 id="init">Goroutines during init</h3>
Rob Pikebab4dec2011-12-07 14:33:37 -0800134
Rob Pike136c04f2011-12-08 16:39:05 -0800135<p>
Rob Pike68c7e8a2012-02-27 07:31:34 +1100136The 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.
137This introduced clumsiness in many places and, in effect, limited the utility
138of the <code>init</code> construct:
139if it was possible for another package to use the library during initialization, the library
140was forced to avoid goroutines.
141This design was done for reasons of simplicity and safety but,
142as our confidence in the language grew, it seemed unnecessary.
143Running goroutines during initialization is no more complex or unsafe than running them during normal execution.
144</p>
145
146<p>
147In Go 1, code that uses goroutines can be called from
Rob Pike136c04f2011-12-08 16:39:05 -0800148<code>init</code> routines and global initialization expressions
149without introducing a deadlock.
150</p>
151
Russ Coxa40065a2012-03-08 08:39:20 -0500152{{code "/doc/progs/go1.go" `/PackageGlobal/` `/^}/`}}
Rob Pike136c04f2011-12-08 16:39:05 -0800153
154<p>
155<em>Updating</em>:
156This is a new feature, so existing code needs no changes,
157although it's possible that code that depends on goroutines not starting before <code>main</code> will break.
158There was no such code in the standard repository.
159</p>
160
Rob Pikebab4dec2011-12-07 14:33:37 -0800161<h3 id="rune">The rune type</h3>
162
Rob Pike2e338fa2011-12-09 08:31:57 -0800163<p>
Rob Pike68c7e8a2012-02-27 07:31:34 +1100164The 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.
165It would be preferable to have <code>int</code> be 64 bits on 64-bit platforms.
166(There are important consequences for indexing large slices.)
167However, this change would waste space when processing Unicode characters with
168the 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.
169</p>
170
171<p>
172To make changing to 64-bit <code>int</code> feasible,
173Go 1 introduces a new basic type, <code>rune</code>, to represent
Rob Pike2e338fa2011-12-09 08:31:57 -0800174individual Unicode code points.
175It is an alias for <code>int32</code>, analogous to <code>byte</code>
176as an alias for <code>uint8</code>.
177</p>
178
179<p>
180Character literals such as <code>'a'</code>, <code>'語'</code>, and <code>'\u0345'</code>
181now have default type <code>rune</code>,
182analogous to <code>1.0</code> having default type <code>float64</code>.
183A variable initialized to a character constant will therefore
184have type <code>rune</code> unless otherwise specified.
185</p>
186
187<p>
188Libraries have been updated to use <code>rune</code> rather than <code>int</code>
189when appropriate. For instance, the functions <code>unicode.ToLower</code> and
190relatives now take and return a <code>rune</code>.
191</p>
192
Russ Coxa40065a2012-03-08 08:39:20 -0500193{{code "/doc/progs/go1.go" `/STARTRUNE/` `/ENDRUNE/`}}
Rob Pike2e338fa2011-12-09 08:31:57 -0800194
195<p>
196<em>Updating</em>:
197Most source code will be unaffected by this because the type inference from
198<code>:=</code> initializers introduces the new type silently, and it propagates
199from there.
200Some code may get type errors that a trivial conversion will resolve.
201</p>
202
203<h3 id="error">The error type</h3>
204
205<p>
206Go 1 introduces a new built-in type, <code>error</code>, which has the following definition:
207</p>
208
209<pre>
210 type error interface {
211 Error() string
212 }
213</pre>
214
215<p>
216Since the consequences of this type are all in the package library,
Rob Pikeebdcbf12011-12-12 12:26:56 -0800217it is discussed <a href="#errors">below</a>.
Rob Pike2e338fa2011-12-09 08:31:57 -0800218</p>
219
Rob Pike9d59c402011-12-08 11:35:28 -0800220<h3 id="delete">Deleting from maps</h3>
Rob Pike2fa987b2011-12-07 16:11:17 -0800221
222<p>
Rob Pike68c7e8a2012-02-27 07:31:34 +1100223In 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 -0800224</p>
225
226<pre>
Rob Pike68c7e8a2012-02-27 07:31:34 +1100227 m[k] = value, false
Rob Pike2fa987b2011-12-07 16:11:17 -0800228</pre>
229
230<p>
Rob Pike68c7e8a2012-02-27 07:31:34 +1100231This syntax was a peculiar special case, the only two-to-one assignment.
232It required passing a value (usually ignored) that is evaluated but discarded,
233plus a boolean that was nearly always the constant <code>false</code>.
234It did the job but was odd and a point of contention.
235</p>
236
237<p>
Rob Pike9d59c402011-12-08 11:35:28 -0800238In Go 1, that syntax has gone; instead there is a new built-in
Rob Pike2fa987b2011-12-07 16:11:17 -0800239function, <code>delete</code>. The call
240</p>
241
Russ Coxa40065a2012-03-08 08:39:20 -0500242{{code "/doc/progs/go1.go" `/delete\(m, k\)/`}}
Rob Pike2fa987b2011-12-07 16:11:17 -0800243
244<p>
245will delete the map entry retrieved by the expression <code>m[k]</code>.
246There is no return value. Deleting a non-existent entry is a no-op.
247</p>
248
249<p>
250<em>Updating</em>:
Rob Pike68c7e8a2012-02-27 07:31:34 +1100251Running <code>go</code> <code>fix</code> will convert expressions of the form <code>m[k] = value,
Rob Pike2fa987b2011-12-07 16:11:17 -0800252false</code> into <code>delete(m, k)</code> when it is clear that
253the ignored value can be safely discarded from the program and
Rob Pike27836912012-02-04 07:49:51 +1100254<code>false</code> refers to the predefined boolean constant.
255The fix tool
Rob Pike2fa987b2011-12-07 16:11:17 -0800256will flag other uses of the syntax for inspection by the programmer.
257</p>
258
Rob Pike136c04f2011-12-08 16:39:05 -0800259<h3 id="iteration">Iterating in maps</h3>
260
261<p>
Rob Pike68c7e8a2012-02-27 07:31:34 +1100262The old language specification did not define the order of iteration for maps,
263and in practice it differed across hardware platforms.
264This caused tests that iterated over maps to be fragile and non-portable, with the
265unpleasant property that a test might always pass on one machine but break on another.
266</p>
267
268<p>
Rob Pike136c04f2011-12-08 16:39:05 -0800269In Go 1, the order in which elements are visited when iterating
270over a map using a <code>for</code> <code>range</code> statement
271is defined to be unpredictable, even if the same loop is run multiple
272times with the same map.
273Code should not assume that the elements are visited in any particular order.
274</p>
275
Rob Pike68c7e8a2012-02-27 07:31:34 +1100276<p>
277This change means that code that depends on iteration order is very likely to break early and be fixed long before it becomes a problem.
278Just 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.
279</p>
280
Russ Coxa40065a2012-03-08 08:39:20 -0500281{{code "/doc/progs/go1.go" `/Sunday/` `/^ }/`}}
Rob Pike136c04f2011-12-08 16:39:05 -0800282
283<p>
284<em>Updating</em>:
285This is one change where tools cannot help. Most existing code
286will be unaffected, but some programs may break or misbehave; we
287recommend manual checking of all range statements over maps to
288verify they do not depend on iteration order. There were a few such
289examples in the standard repository; they have been fixed.
290Note that it was already incorrect to depend on the iteration order, which
291was unspecified. This change codifies the unpredictability.
292</p>
Rob Pikebab4dec2011-12-07 14:33:37 -0800293
294<h3 id="multiple_assignment">Multiple assignment</h3>
295
Rob Pike136c04f2011-12-08 16:39:05 -0800296<p>
Rob Pike9e7e6d92012-02-29 11:29:33 +1100297The language specification has long guaranteed that in assignments
Rob Pike68c7e8a2012-02-27 07:31:34 +1100298the right-hand-side expressions are all evaluated before any left-hand-side expressions are assigned.
299To guarantee predictable behavior,
300Go 1 refines the specification further.
301</p>
302
303<p>
304If the left-hand side of the assignment
Rob Pike136c04f2011-12-08 16:39:05 -0800305statement contains expressions that require evaluation, such as
306function calls or array indexing operations, these will all be done
307using the usual left-to-right rule before any variables are assigned
308their value. Once everything is evaluated, the actual assignments
309proceed in left-to-right order.
310</p>
311
312<p>
313These examples illustrate the behavior.
314</p>
315
Russ Coxa40065a2012-03-08 08:39:20 -0500316{{code "/doc/progs/go1.go" `/sa :=/` `/then sc.0. = 2/`}}
Rob Pike136c04f2011-12-08 16:39:05 -0800317
Rob Pike2e338fa2011-12-09 08:31:57 -0800318<p>
Rob Pike136c04f2011-12-08 16:39:05 -0800319<em>Updating</em>:
320This is one change where tools cannot help, but breakage is unlikely.
321No code in the standard repository was broken by this change, and code
322that depended on the previous unspecified behavior was already incorrect.
323</p>
324
Rob Pikebab4dec2011-12-07 14:33:37 -0800325<h3 id="shadowing">Returns and shadowed variables</h3>
326
Rob Pike136c04f2011-12-08 16:39:05 -0800327<p>
Rob Pike68c7e8a2012-02-27 07:31:34 +1100328A 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.
329This situation is called <em>shadowing</em>: the result variable has been shadowed by another variable with the same name declared in an inner scope.
330</p>
331
332<p>
Rob Pike136c04f2011-12-08 16:39:05 -0800333In functions with named return values,
334the Go 1 compilers disallow return statements without arguments if any of the named return values is shadowed at the point of the return statement.
335(It isn't part of the specification, because this is one area we are still exploring;
336the situation is analogous to the compilers rejecting functions that do not end with an explicit return statement.)
337</p>
338
339<p>
340This function implicitly returns a shadowed return value and will be rejected by the compiler:
341</p>
342
343<pre>
344 func Bug() (i, j, k int) {
Robert Hencke7c9ee5f2012-01-25 21:09:46 -0800345 for i = 0; i &lt; 5; i++ {
346 for j := 0; j &lt; 5; j++ { // Redeclares j.
Rob Pike136c04f2011-12-08 16:39:05 -0800347 k += i*j
348 if k > 100 {
349 return // Rejected: j is shadowed here.
350 }
351 }
352 }
353 return // OK: j is not shadowed here.
354 }
355</pre>
356
357<p>
358<em>Updating</em>:
359Code that shadows return values in this way will be rejected by the compiler and will need to be fixed by hand.
360The few cases that arose in the standard repository were mostly bugs.
361</p>
362
363<h3 id="unexported">Copying structs with unexported fields</h3>
364
Rob Pike2e338fa2011-12-09 08:31:57 -0800365<p>
Rob Pike68c7e8a2012-02-27 07:31:34 +1100366The old language did not allow a package to make a copy of a struct value containing unexported fields belonging to a different package.
367There was, however, a required exception for a method receiver;
368also, the implementations of <code>copy</code> and <code>append</code> have never honored the restriction.
369</p>
370
371<p>
372Go 1 will allow packages to copy struct values containing unexported fields from other packages.
373Besides resolving the inconsistency,
374this change admits a new kind of API: a package can return an opaque value without resorting to a pointer or interface.
375The new implementations of <code>time.Time</code> and
376<code>reflect.Value</code> are examples of types taking advantage of this new property.
Rob Pike2e338fa2011-12-09 08:31:57 -0800377</p>
378
379<p>
380As an example, if package <code>p</code> includes the definitions,
381</p>
382
383<pre>
384 type Struct struct {
385 Public int
386 secret int
387 }
388 func NewStruct(a int) Struct { // Note: not a pointer.
389 return Struct{a, f(a)}
390 }
391 func (s Struct) String() string {
392 return fmt.Sprintf("{%d (secret %d)}", s.Public, s.secret)
393 }
394</pre>
395
396<p>
397a package that imports <code>p</code> can assign and copy values of type
398<code>p.Struct</code> at will.
399Behind the scenes the unexported fields will be assigned and copied just
400as if they were exported,
401but the client code will never be aware of them. The code
402</p>
403
404<pre>
405 import "p"
406
407 myStruct := p.NewStruct(23)
408 copyOfMyStruct := myStruct
409 fmt.Println(myStruct, copyOfMyStruct)
410</pre>
411
412<p>
413will show that the secret field of the struct has been copied to the new value.
414</p>
415
416<p>
417<em>Updating</em>:
418This is a new feature, so existing code needs no changes.
419</p>
420
Rob Pike68c7e8a2012-02-27 07:31:34 +1100421<h3 id="equality">Equality</h3>
Rob Pikebab4dec2011-12-07 14:33:37 -0800422
Rob Pike136c04f2011-12-08 16:39:05 -0800423<p>
Rob Pike68c7e8a2012-02-27 07:31:34 +1100424Before Go 1, the language did not define equality on struct and array values.
425This meant,
426among other things, that structs and arrays could not be used as map keys.
427On the other hand, Go did define equality on function and map values.
428Function equality was problematic in the presence of closures
429(when are two closures equal?)
430while map equality compared pointers, not the maps' content, which was usually
431not what the user would want.
Rob Pike136c04f2011-12-08 16:39:05 -0800432</p>
433
434<p>
Rob Pike68c7e8a2012-02-27 07:31:34 +1100435Go 1 addressed these issues.
436First, structs and arrays can be compared for equality and inequality
437(<code>==</code> and <code>!=</code>),
438and therefore be used as map keys,
439provided they are composed from elements for which equality is also defined,
440using element-wise comparison.
Rob Pike136c04f2011-12-08 16:39:05 -0800441</p>
442
Russ Coxa40065a2012-03-08 08:39:20 -0500443{{code "/doc/progs/go1.go" `/type Day struct/` `/Printf/`}}
Rob Pike136c04f2011-12-08 16:39:05 -0800444
445<p>
Rob Pike68c7e8a2012-02-27 07:31:34 +1100446Second, Go 1 removes the definition of equality for function values,
447except for comparison with <code>nil</code>.
Rob Pike9e7e6d92012-02-29 11:29:33 +1100448Finally, map equality is gone too, also except for comparison with <code>nil</code>.
Rob Pike68c7e8a2012-02-27 07:31:34 +1100449</p>
450
451<p>
Rob Pike136c04f2011-12-08 16:39:05 -0800452Note that equality is still undefined for slices, for which the
453calculation is in general infeasible. Also note that the ordered
454comparison operators (<code>&lt;</code> <code>&lt;=</code>
455<code>&gt;</code> <code>&gt;=</code>) are still undefined for
456structs and arrays.
457
458<p>
459<em>Updating</em>:
Rob Pike68c7e8a2012-02-27 07:31:34 +1100460Struct and array equality is a new feature, so existing code needs no changes.
Rob Pike136c04f2011-12-08 16:39:05 -0800461Existing code that depends on function or map equality will be
462rejected by the compiler and will need to be fixed by hand.
463Few programs will be affected, but the fix may require some
464redesign.
465</p>
466
Rob Pike0a1376a2012-01-20 14:28:48 -0800467<h2 id="packages">The package hierarchy</h2>
468
469<p>
Rob Pike68c7e8a2012-02-27 07:31:34 +1100470Go 1 addresses many deficiencies in the old standard library and
471cleans up a number of packages, making them more internally consistent
472and portable.
473</p>
474
475<p>
Rob Pike0a1376a2012-01-20 14:28:48 -0800476This section describes how the packages have been rearranged in Go 1.
477Some have moved, some have been renamed, some have been deleted.
478New packages are described in later sections.
479</p>
Rob Pikebab4dec2011-12-07 14:33:37 -0800480
Rob Pike9d59c402011-12-08 11:35:28 -0800481<h3 id="hierarchy">The package hierarchy</h3>
482
483<p>
484Go 1 has a rearranged package hierarchy that groups related items
485into subdirectories. For instance, <code>utf8</code> and
486<code>utf16</code> now occupy subdirectories of <code>unicode</code>.
487Also, <a href="#subrepo">some packages</a> have moved into
488subrepositories of
Andrew Gerrand43ad89d2014-07-25 10:28:39 +1000489<a href="//code.google.com/p/go"><code>code.google.com/p/go</code></a>
Rob Pike9d59c402011-12-08 11:35:28 -0800490while <a href="#deleted">others</a> have been deleted outright.
491</p>
492
493<table class="codetable" frame="border" summary="Moved packages">
494<colgroup align="left" width="60%"></colgroup>
495<colgroup align="left" width="40%"></colgroup>
496<tr>
497<th align="left">Old path</th>
498<th align="left">New path</th>
499</tr>
Rob Pike71ccf732011-12-09 14:12:51 -0800500<tr>
501<td colspan="2"><hr></td>
502</tr>
Rob Pike136c04f2011-12-08 16:39:05 -0800503<tr><td>asn1</td> <td>encoding/asn1</td></tr>
Rob Pike9d59c402011-12-08 11:35:28 -0800504<tr><td>csv</td> <td>encoding/csv</td></tr>
505<tr><td>gob</td> <td>encoding/gob</td></tr>
506<tr><td>json</td> <td>encoding/json</td></tr>
507<tr><td>xml</td> <td>encoding/xml</td></tr>
508<tr>
509<td colspan="2"><hr></td>
510</tr>
511<tr><td>exp/template/html</td> <td>html/template</td></tr>
512<tr>
513<td colspan="2"><hr></td>
514</tr>
515<tr><td>big</td> <td>math/big</td></tr>
516<tr><td>cmath</td> <td>math/cmplx</td></tr>
517<tr><td>rand</td> <td>math/rand</td></tr>
518<tr>
519<td colspan="2"><hr></td>
520</tr>
521<tr><td>http</td> <td>net/http</td></tr>
522<tr><td>http/cgi</td> <td>net/http/cgi</td></tr>
523<tr><td>http/fcgi</td> <td>net/http/fcgi</td></tr>
524<tr><td>http/httptest</td> <td>net/http/httptest</td></tr>
525<tr><td>http/pprof</td> <td>net/http/pprof</td></tr>
526<tr><td>mail</td> <td>net/mail</td></tr>
527<tr><td>rpc</td> <td>net/rpc</td></tr>
528<tr><td>rpc/jsonrpc</td> <td>net/rpc/jsonrpc</td></tr>
529<tr><td>smtp</td> <td>net/smtp</td></tr>
530<tr><td>url</td> <td>net/url</td></tr>
531<tr>
532<td colspan="2"><hr></td>
533</tr>
534<tr><td>exec</td> <td>os/exec</td></tr>
535<tr>
536<td colspan="2"><hr></td>
537</tr>
538<tr><td>scanner</td> <td>text/scanner</td></tr>
539<tr><td>tabwriter</td> <td>text/tabwriter</td></tr>
540<tr><td>template</td> <td>text/template</td></tr>
541<tr><td>template/parse</td> <td>text/template/parse</td></tr>
542<tr>
543<td colspan="2"><hr></td>
544</tr>
545<tr><td>utf8</td> <td>unicode/utf8</td></tr>
546<tr><td>utf16</td> <td>unicode/utf16</td></tr>
547</table>
548
549<p>
550Note that the package names for the old <code>cmath</code> and
551<code>exp/template/html</code> packages have changed to <code>cmplx</code>
552and <code>template</code>.
553</p>
554
555<p>
556<em>Updating</em>:
Rob Pike5cff0292012-02-24 13:08:11 +1100557Running <code>go</code> <code>fix</code> will update all imports and package renames for packages that
Rob Pike9d59c402011-12-08 11:35:28 -0800558remain inside the standard repository. Programs that import packages
559that are no longer in the standard repository will need to be edited
560by hand.
Rob Pike9d59c402011-12-08 11:35:28 -0800561</p>
Rob Pikebab4dec2011-12-07 14:33:37 -0800562
Rob Pike0a1376a2012-01-20 14:28:48 -0800563<h3 id="exp">The package tree exp</h3>
564
565<p>
566Because they are not standardized, the packages under the <code>exp</code> directory will not be available in the
567standard Go 1 release distributions, although they will be available in source code form
Andrew Gerrand43ad89d2014-07-25 10:28:39 +1000568in <a href="//code.google.com/p/go/">the repository</a> for
Rob Pike0a1376a2012-01-20 14:28:48 -0800569developers who wish to use them.
570</p>
571
572<p>
573Several packages have moved under <code>exp</code> at the time of Go 1's release:
574</p>
575
576<ul>
577<li><code>ebnf</code></li>
Shenghou Ma6a005cb2012-03-03 00:47:11 +0800578<li><code>html</code><sup>&#8224;</sup></li>
Rob Pike0a1376a2012-01-20 14:28:48 -0800579<li><code>go/types</code></li>
Rob Pike0a1376a2012-01-20 14:28:48 -0800580</ul>
581
582<p>
Shenghou Ma6a005cb2012-03-03 00:47:11 +0800583(<sup>&#8224;</sup>The <code>EscapeString</code> and <code>UnescapeString</code> types remain
Andrew Gerrand47d614e2012-03-02 11:52:46 +1100584in package <code>html</code>.)
585</p>
586
587<p>
Rob Pike531ded92012-01-20 15:38:03 -0800588All these packages are available under the same names, with the prefix <code>exp/</code>: <code>exp/ebnf</code> etc.
589</p>
590
591<p>
Rob Pike0a1376a2012-01-20 14:28:48 -0800592Also, the <code>utf8.String</code> type has been moved to its own package, <code>exp/utf8string</code>.
593</p>
594
595<p>
Rob Pike531ded92012-01-20 15:38:03 -0800596Finally, the <code>gotype</code> command now resides in <code>exp/gotype</code>, while
Rob Pike27836912012-02-04 07:49:51 +1100597<code>ebnflint</code> is now in <code>exp/ebnflint</code>.
598If they are installed, they now reside in <code>$GOROOT/bin/tool</code>.
Rob Pike0a1376a2012-01-20 14:28:48 -0800599</p>
600
601<p>
602<em>Updating</em>:
603Code that uses packages in <code>exp</code> will need to be updated by hand,
604or else compiled from an installation that has <code>exp</code> available.
Rob Pike5cff0292012-02-24 13:08:11 +1100605The <code>go</code> <code>fix</code> tool or the compiler will complain about such uses.
Rob Pike0a1376a2012-01-20 14:28:48 -0800606</p>
607
608<h3 id="old">The package tree old</h3>
609
610<p>
611Because they are deprecated, the packages under the <code>old</code> directory will not be available in the
612standard Go 1 release distributions, although they will be available in source code form for
613developers who wish to use them.
614</p>
615
616<p>
617The packages in their new locations are:
618</p>
619
620<ul>
621<li><code>old/netchan</code></li>
Rob Pike0a1376a2012-01-20 14:28:48 -0800622</ul>
623
624<p>
625<em>Updating</em>:
626Code that uses packages now in <code>old</code> will need to be updated by hand,
627or else compiled from an installation that has <code>old</code> available.
Rob Pike5cff0292012-02-24 13:08:11 +1100628The <code>go</code> <code>fix</code> tool will warn about such uses.
Rob Pike0a1376a2012-01-20 14:28:48 -0800629</p>
630
631<h3 id="deleted">Deleted packages</h3>
632
633<p>
634Go 1 deletes several packages outright:
635</p>
636
637<ul>
638<li><code>container/vector</code></li>
639<li><code>exp/datafmt</code></li>
640<li><code>go/typechecker</code></li>
David Symonds9ce770a2012-04-27 15:12:24 +1000641<li><code>old/regexp</code></li>
642<li><code>old/template</code></li>
Rob Pike0a1376a2012-01-20 14:28:48 -0800643<li><code>try</code></li>
644</ul>
645
646<p>
647and also the command <code>gotry</code>.
648</p>
649
650<p>
651<em>Updating</em>:
652Code that uses <code>container/vector</code> should be updated to use
653slices directly. See
Andrew Gerrand43ad89d2014-07-25 10:28:39 +1000654<a href="//code.google.com/p/go-wiki/wiki/SliceTricks">the Go
Rob Pike0a1376a2012-01-20 14:28:48 -0800655Language Community Wiki</a> for some suggestions.
656Code that uses the other packages (there should be almost zero) will need to be rethought.
Rob Pike0a1376a2012-01-20 14:28:48 -0800657</p>
658
659<h3 id="subrepo">Packages moving to subrepositories</h3>
660
Rob Pike7eaad5e2012-01-25 13:29:25 -0800661<p>
Alex Brainmana93047a2012-03-08 10:01:15 +1100662Go 1 has moved a number of packages into other repositories, usually sub-repositories of
Andrew Gerrand43ad89d2014-07-25 10:28:39 +1000663<a href="//code.google.com/p/go/">the main Go repository</a>.
Rob Pike7eaad5e2012-01-25 13:29:25 -0800664This table lists the old and new import paths:
665
666<table class="codetable" frame="border" summary="Sub-repositories">
667<colgroup align="left" width="40%"></colgroup>
668<colgroup align="left" width="60%"></colgroup>
669<tr>
670<th align="left">Old</th>
671<th align="left">New</th>
672</tr>
673<tr>
674<td colspan="2"><hr></td>
675</tr>
676<tr><td>crypto/bcrypt</td> <td>code.google.com/p/go.crypto/bcrypt</tr>
677<tr><td>crypto/blowfish</td> <td>code.google.com/p/go.crypto/blowfish</tr>
678<tr><td>crypto/cast5</td> <td>code.google.com/p/go.crypto/cast5</tr>
679<tr><td>crypto/md4</td> <td>code.google.com/p/go.crypto/md4</tr>
680<tr><td>crypto/ocsp</td> <td>code.google.com/p/go.crypto/ocsp</tr>
681<tr><td>crypto/openpgp</td> <td>code.google.com/p/go.crypto/openpgp</tr>
682<tr><td>crypto/openpgp/armor</td> <td>code.google.com/p/go.crypto/openpgp/armor</tr>
683<tr><td>crypto/openpgp/elgamal</td> <td>code.google.com/p/go.crypto/openpgp/elgamal</tr>
684<tr><td>crypto/openpgp/errors</td> <td>code.google.com/p/go.crypto/openpgp/errors</tr>
685<tr><td>crypto/openpgp/packet</td> <td>code.google.com/p/go.crypto/openpgp/packet</tr>
686<tr><td>crypto/openpgp/s2k</td> <td>code.google.com/p/go.crypto/openpgp/s2k</tr>
687<tr><td>crypto/ripemd160</td> <td>code.google.com/p/go.crypto/ripemd160</tr>
688<tr><td>crypto/twofish</td> <td>code.google.com/p/go.crypto/twofish</tr>
689<tr><td>crypto/xtea</td> <td>code.google.com/p/go.crypto/xtea</tr>
690<tr><td>exp/ssh</td> <td>code.google.com/p/go.crypto/ssh</tr>
691<tr>
692<td colspan="2"><hr></td>
693</tr>
Nigel Taoceb1ca62012-01-31 12:29:00 +1100694<tr><td>image/bmp</td> <td>code.google.com/p/go.image/bmp</tr>
695<tr><td>image/tiff</td> <td>code.google.com/p/go.image/tiff</tr>
696<tr>
697<td colspan="2"><hr></td>
698</tr>
Rob Pike7eaad5e2012-01-25 13:29:25 -0800699<tr><td>net/dict</td> <td>code.google.com/p/go.net/dict</tr>
700<tr><td>net/websocket</td> <td>code.google.com/p/go.net/websocket</tr>
701<tr><td>exp/spdy</td> <td>code.google.com/p/go.net/spdy</tr>
702<tr>
703<td colspan="2"><hr></td>
704</tr>
705<tr><td>encoding/git85</td> <td>code.google.com/p/go.codereview/git85</tr>
706<tr><td>patch</td> <td>code.google.com/p/go.codereview/patch</tr>
Alex Brainman5aee1f32012-03-07 17:48:09 +1100707<tr>
708<td colspan="2"><hr></td>
709</tr>
710<tr><td>exp/wingui</td> <td>code.google.com/p/gowingui</tr>
Rob Pike7eaad5e2012-01-25 13:29:25 -0800711</table>
712
713<p>
714<em>Updating</em>:
Rob Pike5cff0292012-02-24 13:08:11 +1100715Running <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 -0800716Installations that depend on these packages will need to install them using
Rob Pikec5f695e2012-03-24 10:14:07 +1100717a <code>go get</code> command.
Rob Pike7eaad5e2012-01-25 13:29:25 -0800718</p>
Rob Pike0a1376a2012-01-20 14:28:48 -0800719
720<h2 id="major">Major changes to the library</h2>
721
722<p>
723This section describes significant changes to the core libraries, the ones that
724affect the most programs.
725</p>
726
Rob Pike71ccf732011-12-09 14:12:51 -0800727<h3 id="errors">The error type and errors package</h3>
Rob Pikebab4dec2011-12-07 14:33:37 -0800728
Rob Pikeebdcbf12011-12-12 12:26:56 -0800729<p>
Rob Pike68c7e8a2012-02-27 07:31:34 +1100730The 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.
731Since 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>.
732Also, having <code>Error</code> in <code>os</code> introduces many dependencies on <code>os</code> that would otherwise not exist.
733</p>
734
735<p>
736Go 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.
737It replaces <code>os.NewError</code> with
738<a href="/pkg/errors/#New"><code>errors.New</code></a>,
739giving errors a more central place in the environment.
740</p>
741
742<p>
Rob Pikeebdcbf12011-12-12 12:26:56 -0800743So the widely-used <code>String</code> method does not cause accidental satisfaction
744of the <code>error</code> interface, the <code>error</code> interface uses instead
745the name <code>Error</code> for that method:
746</p>
747
748<pre>
749 type error interface {
750 Error() string
751 }
752</pre>
753
754<p>
755The <code>fmt</code> library automatically invokes <code>Error</code>, as it already
756does for <code>String</code>, for easy printing of error values.
757</p>
758
Russ Coxa40065a2012-03-08 08:39:20 -0500759{{code "/doc/progs/go1.go" `/START ERROR EXAMPLE/` `/END ERROR EXAMPLE/`}}
Rob Pikeebdcbf12011-12-12 12:26:56 -0800760
761<p>
762All standard packages have been updated to use the new interface; the old <code>os.Error</code> is gone.
763</p>
764
765<p>
766A new package, <a href="/pkg/errors/"><code>errors</code></a>, contains the function
767</p>
768
769<pre>
770func New(text string) error
771</pre>
772
773<p>
774to turn a string into an error. It replaces the old <code>os.NewError</code>.
775</p>
776
Russ Coxa40065a2012-03-08 08:39:20 -0500777{{code "/doc/progs/go1.go" `/ErrSyntax/`}}
Rob Pikeebdcbf12011-12-12 12:26:56 -0800778
779<p>
780<em>Updating</em>:
Rob Pike5cff0292012-02-24 13:08:11 +1100781Running <code>go</code> <code>fix</code> will update almost all code affected by the change.
Rob Pikeebdcbf12011-12-12 12:26:56 -0800782Code that defines error types with a <code>String</code> method will need to be updated
783by hand to rename the methods to <code>Error</code>.
784</p>
785
Rob Pike9d59c402011-12-08 11:35:28 -0800786<h3 id="errno">System call errors</h3>
Rob Pikebab4dec2011-12-07 14:33:37 -0800787
Rob Pike71ccf732011-12-09 14:12:51 -0800788<p>
Rob Pike68c7e8a2012-02-27 07:31:34 +1100789The old <code>syscall</code> package, which predated <code>os.Error</code>
790(and just about everything else),
791returned errors as <code>int</code> values.
792In turn, the <code>os</code> package forwarded many of these errors, such
793as <code>EINVAL</code>, but using a different set of errors on each platform.
794This behavior was unpleasant and unportable.
795</p>
796
797<p>
Rob Pike71ccf732011-12-09 14:12:51 -0800798In Go 1, the
Rob Pikeebdcbf12011-12-12 12:26:56 -0800799<a href="/pkg/syscall/"><code>syscall</code></a>
Rob Pike68c7e8a2012-02-27 07:31:34 +1100800package instead returns an <code>error</code> for system call errors.
Rob Pike1cd272d2012-03-08 17:15:23 +1100801On Unix, the implementation is done by a
Rob Pikeebdcbf12011-12-12 12:26:56 -0800802<a href="/pkg/syscall/#Errno"><code>syscall.Errno</code></a> type
Rob Pike71ccf732011-12-09 14:12:51 -0800803that satisfies <code>error</code> and replaces the old <code>os.Errno</code>.
804</p>
805
806<p>
Rob Pike68c7e8a2012-02-27 07:31:34 +1100807The changes affecting <code>os.EINVAL</code> and relatives are
808described <a href="#os">elsewhere</a>.
809
810<p>
Rob Pike71ccf732011-12-09 14:12:51 -0800811<em>Updating</em>:
Rob Pike5cff0292012-02-24 13:08:11 +1100812Running <code>go</code> <code>fix</code> will update almost all code affected by the change.
Rob Pike71ccf732011-12-09 14:12:51 -0800813Regardless, most code should use the <code>os</code> package
814rather than <code>syscall</code> and so will be unaffected.
815</p>
816
Rob Pikebab4dec2011-12-07 14:33:37 -0800817<h3 id="time">Time</h3>
818
Rob Pike5fa18e12011-12-12 21:08:03 -0800819<p>
Rob Pike68c7e8a2012-02-27 07:31:34 +1100820Time is always a challenge to support well in a programming language.
821The old Go <code>time</code> package had <code>int64</code> units, no
822real type safety,
823and no distinction between absolute times and durations.
824</p>
825
826<p>
827One of the most sweeping changes in the Go 1 library is therefore a
Rob Pike1cd272d2012-03-08 17:15:23 +1100828complete redesign of the
Rob Pike5fa18e12011-12-12 21:08:03 -0800829<a href="/pkg/time/"><code>time</code></a> package.
830Instead of an integer number of nanoseconds as an <code>int64</code>,
831and a separate <code>*time.Time</code> type to deal with human
832units such as hours and years,
833there are now two fundamental types:
834<a href="/pkg/time/#Time"><code>time.Time</code></a>
835(a value, so the <code>*</code> is gone), which represents a moment in time;
836and <a href="/pkg/time/#Duration"><code>time.Duration</code></a>,
837which represents an interval.
838Both have nanosecond resolution.
839A <code>Time</code> can represent any time into the ancient
840past and remote future, while a <code>Duration</code> can
841span plus or minus only about 290 years.
842There are methods on these types, plus a number of helpful
843predefined constant durations such as <code>time.Second</code>.
844</p>
845
846<p>
847Among the new methods are things like
848<a href="/pkg/time/#Time.Add"><code>Time.Add</code></a>,
849which adds a <code>Duration</code> to a <code>Time</code>, and
850<a href="/pkg/time/#Time.Sub"><code>Time.Sub</code></a>,
851which subtracts two <code>Times</code> to yield a <code>Duration</code>.
852</p>
853
854<p>
855The most important semantic change is that the Unix epoch (Jan 1, 1970) is now
856relevant only for those functions and methods that mention Unix:
857<a href="/pkg/time/#Unix"><code>time.Unix</code></a>
858and the <a href="/pkg/time/#Time.Unix"><code>Unix</code></a>
859and <a href="/pkg/time/#Time.UnixNano"><code>UnixNano</code></a> methods
860of the <code>Time</code> type.
861In particular,
862<a href="/pkg/time/#Now"><code>time.Now</code></a>
863returns a <code>time.Time</code> value rather than, in the old
864API, an integer nanosecond count since the Unix epoch.
865</p>
866
Russ Coxa40065a2012-03-08 08:39:20 -0500867{{code "/doc/progs/go1.go" `/sleepUntil/` `/^}/`}}
Rob Pike5fa18e12011-12-12 21:08:03 -0800868
869<p>
870The new types, methods, and constants have been propagated through
871all the standard packages that use time, such as <code>os</code> and
872its representation of file time stamps.
873</p>
874
875<p>
876<em>Updating</em>:
Rob Pike5cff0292012-02-24 13:08:11 +1100877The <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 -0800878types and methods, although it does not replace values such as <code>1e9</code>
879representing nanoseconds per second.
880Also, because of type changes in some of the values that arise,
Rob Pike27836912012-02-04 07:49:51 +1100881some of the expressions rewritten by the fix tool may require
Rob Pike5fa18e12011-12-12 21:08:03 -0800882further hand editing; in such cases the rewrite will include
883the correct function or method for the old functionality, but
884may have the wrong type or require further analysis.
885</p>
886
Rob Pike0a1376a2012-01-20 14:28:48 -0800887<h2 id="minor">Minor changes to the library</h2>
888
889<p>
890This section describes smaller changes, such as those to less commonly
891used packages or that affect
Rob Pike5cff0292012-02-24 13:08:11 +1100892few programs beyond the need to run <code>go</code> <code>fix</code>.
Rob Pike0a1376a2012-01-20 14:28:48 -0800893This category includes packages that are new in Go 1.
Rob Pike68c7e8a2012-02-27 07:31:34 +1100894Collectively they improve portability, regularize behavior, and
895make the interfaces more modern and Go-like.
Rob Pike0a1376a2012-01-20 14:28:48 -0800896</p>
897
Andrew Gerrand04868b22012-02-14 10:47:48 +1100898<h3 id="archive_zip">The archive/zip package</h3>
899
900<p>
901In Go 1, <a href="/pkg/archive/zip/#Writer"><code>*zip.Writer</code></a> no
902longer has a <code>Write</code> method. Its presence was a mistake.
903</p>
904
905<p>
Nigel Taoda8f0372012-02-15 14:41:47 +1100906<em>Updating</em>:
907What little code is affected will be caught by the compiler and must be updated by hand.
Andrew Gerrand04868b22012-02-14 10:47:48 +1100908</p>
909
Adam Langleyc2e58dc2012-02-14 07:13:57 -0500910<h3 id="bufio">The bufio package</h3>
911
912<p>
913In Go 1, <a href="/pkg/bufio/#NewReaderSize"><code>bufio.NewReaderSize</code></a>
914and
915<a href="/pkg/bufio/#NewWriterSize"><code>bufio.NewWriterSize</code></a>
916functions no longer return an error for invalid sizes.
917If the argument size is too small or invalid, it is adjusted.
918</p>
919
920<p>
921<em>Updating</em>:
Rob Pike5cff0292012-02-24 13:08:11 +1100922Running <code>go</code> <code>fix</code> will update calls that assign the error to _.
Nigel Taoda8f0372012-02-15 14:41:47 +1100923Calls that aren't fixed will be caught by the compiler and must be updated by hand.
Adam Langleyc2e58dc2012-02-14 07:13:57 -0500924</p>
925
Rob Pikec3ef1982012-02-19 14:15:26 +1100926<h3 id="compress">The compress/flate, compress/gzip and compress/zlib packages</h3>
Adam Langleyc2e58dc2012-02-14 07:13:57 -0500927
928<p>
929In Go 1, the <code>NewWriterXxx</code> functions in
930<a href="/pkg/compress/flate"><code>compress/flate</code></a>,
931<a href="/pkg/compress/gzip"><code>compress/gzip</code></a> and
932<a href="/pkg/compress/zlib"><code>compress/zlib</code></a>
933all return <code>(*Writer, error)</code> if they take a compression level,
934and <code>*Writer</code> otherwise. Package <code>gzip</code>'s
935<code>Compressor</code> and <code>Decompressor</code> types have been renamed
936to <code>Writer</code> and <code>Reader</code>. Package <code>flate</code>'s
937<code>WrongValueError</code> type has been removed.
938</p>
939
940<p>
941<em>Updating</em>
Rob Pike5cff0292012-02-24 13:08:11 +1100942Running <code>go</code> <code>fix</code> will update old names and calls that assign the error to _.
Nigel Taoda8f0372012-02-15 14:41:47 +1100943Calls that aren't fixed will be caught by the compiler and must be updated by hand.
Adam Langleyc2e58dc2012-02-14 07:13:57 -0500944</p>
945
Adam Langleycdd7e022012-02-13 12:38:45 -0500946<h3 id="crypto_aes_des">The crypto/aes and crypto/des packages</h3>
Rob Pikebb7b1a12012-02-08 13:07:13 +1100947
948<p>
Adam Langleycdd7e022012-02-13 12:38:45 -0500949In Go 1, the <code>Reset</code> method has been removed. Go does not guarantee
950that memory is not copied and therefore this method was misleading.
951</p>
952
953<p>
954The cipher-specific types <code>*aes.Cipher</code>, <code>*des.Cipher</code>,
955and <code>*des.TripleDESCipher</code> have been removed in favor of
956<code>cipher.Block</code>.
Rob Pikebb7b1a12012-02-08 13:07:13 +1100957</p>
958
959<p>
960<em>Updating</em>:
Adam Langleycdd7e022012-02-13 12:38:45 -0500961Remove the calls to Reset. Replace uses of the specific cipher types with
962cipher.Block.
Nigel Taocc9ed442012-02-10 18:49:19 +1100963</p>
964
Rob Pike0a1376a2012-01-20 14:28:48 -0800965<h3 id="crypto_elliptic">The crypto/elliptic package</h3>
966
967<p>
968In Go 1, <a href="/pkg/crypto/elliptic/#Curve"><code>elliptic.Curve</code></a>
969has been made an interface to permit alternative implementations. The curve
970parameters have been moved to the
971<a href="/pkg/crypto/elliptic/#CurveParams"><code>elliptic.CurveParams</code></a>
972structure.
973</p>
974
975<p>
976<em>Updating</em>:
977Existing users of <code>*elliptic.Curve</code> will need to change to
978simply <code>elliptic.Curve</code>. Calls to <code>Marshal</code>,
979<code>Unmarshal</code> and <code>GenerateKey</code> are now functions
980in <code>crypto/elliptic</code> that take an <code>elliptic.Curve</code>
981as their first argument.
982</p>
983
Rob Pike27836912012-02-04 07:49:51 +1100984<h3 id="crypto_hmac">The crypto/hmac package</h3>
Adam Langley68aff952012-01-27 10:12:27 -0800985
986<p>
987In Go 1, the hash-specific functions, such as <code>hmac.NewMD5</code>, have
988been removed from <code>crypto/hmac</code>. Instead, <code>hmac.New</code> takes
989a function that returns a <code>hash.Hash</code>, such as <code>md5.New</code>.
990</p>
991
992<p>
993<em>Updating</em>:
Rob Pike5cff0292012-02-24 13:08:11 +1100994Running <code>go</code> <code>fix</code> will perform the needed changes.
Adam Langley68aff952012-01-27 10:12:27 -0800995</p>
996
Rob Pike0a1376a2012-01-20 14:28:48 -0800997<h3 id="crypto_x509">The crypto/x509 package</h3>
998
999<p>
1000In Go 1, the
1001<a href="/pkg/crypto/x509/#CreateCertificate"><code>CreateCertificate</code></a>
Brad Fitzpatrick12566a62013-04-18 12:43:23 -07001002function and
1003<a href="/pkg/crypto/x509/#Certificate.CreateCRL"><code>CreateCRL</code></a>
1004method in <code>crypto/x509</code> have been altered to take an
Rob Pike0a1376a2012-01-20 14:28:48 -08001005<code>interface{}</code> where they previously took a <code>*rsa.PublicKey</code>
1006or <code>*rsa.PrivateKey</code>. This will allow other public key algorithms
1007to be implemented in the future.
1008</p>
1009
1010<p>
1011<em>Updating</em>:
1012No changes will be needed.
1013</p>
1014
Rob Pike1cd272d2012-03-08 17:15:23 +11001015<h3 id="encoding_binary">The encoding/binary package</h3>
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001016
1017<p>
1018In Go 1, the <code>binary.TotalSize</code> function has been replaced by
1019<a href="/pkg/encoding/binary/#Size"><code>Size</code></a>,
1020which takes an <code>interface{}</code> argument rather than
1021a <code>reflect.Value</code>.
1022</p>
1023
1024<p>
1025<em>Updating</em>:
1026What little code is affected will be caught by the compiler and must be updated by hand.
1027</p>
1028
1029<h3 id="encoding_xml">The encoding/xml package</h3>
1030
1031<p>
1032In Go 1, the <a href="/pkg/encoding/xml/"><code>xml</code></a> package
1033has been brought closer in design to the other marshaling packages such
1034as <a href="/pkg/encoding/gob/"><code>encoding/gob</code></a>.
1035</p>
1036
1037<p>
1038The old <code>Parser</code> type is renamed
1039<a href="/pkg/encoding/xml/#Decoder"><code>Decoder</code></a> and has a new
1040<a href="/pkg/encoding/xml/#Decoder.Decode"><code>Decode</code></a> method. An
Rob Pike9e7e6d92012-02-29 11:29:33 +11001041<a href="/pkg/encoding/xml/#Encoder"><code>Encoder</code></a> type was also introduced.
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001042</p>
1043
1044<p>
1045The functions <a href="/pkg/encoding/xml/#Marshal"><code>Marshal</code></a>
1046and <a href="/pkg/encoding/xml/#Unmarshal"><code>Unmarshal</code></a>
1047work with <code>[]byte</code> values now. To work with streams,
1048use the new <a href="/pkg/encoding/xml/#Encoder"><code>Encoder</code></a>
1049and <a href="/pkg/encoding/xml/#Decoder"><code>Decoder</code></a> types.
1050</p>
1051
1052<p>
1053When marshaling or unmarshaling values, the format of supported flags in
1054field tags has changed to be closer to the
1055<a href="/pkg/encoding/json"><code>json</code></a> package
1056(<code>`xml:"name,flag"`</code>). The matching done between field tags, field
1057names, and the XML attribute and element names is now case-sensitive.
1058The <code>XMLName</code> field tag, if present, must also match the name
1059of the XML element being marshaled.
1060</p>
1061
1062<p>
1063<em>Updating</em>:
Rob Pike5cff0292012-02-24 13:08:11 +11001064Running <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 -05001065<code>Unmarshal</code>. Special care must be taken with field tags,
1066since the fix tool will not update them and if not fixed by hand they will
1067misbehave silently in some cases. For example, the old
1068<code>"attr"</code> is now written <code>",attr"</code> while plain
1069<code>"attr"</code> remains valid but with a different meaning.
1070</p>
1071
David Symonds715588f2012-02-04 14:32:05 +11001072<h3 id="expvar">The expvar package</h3>
1073
1074<p>
1075In Go 1, the <code>RemoveAll</code> function has been removed.
1076The <code>Iter</code> function and Iter method on <code>*Map</code> have
1077been replaced by
1078<a href="/pkg/expvar/#Do"><code>Do</code></a>
1079and
1080<a href="/pkg/expvar/#Map.Do"><code>(*Map).Do</code></a>.
1081</p>
1082
1083<p>
1084<em>Updating</em>:
1085Most code using <code>expvar</code> will not need changing. The rare code that used
David Symonds2943ca6b2012-02-04 21:55:38 +11001086<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 +11001087</p>
1088
Rob Pike531ded92012-01-20 15:38:03 -08001089<h3 id="flag">The flag package</h3>
1090
1091<p>
1092In Go 1, the interface <a href="/pkg/flag/#Value"><code>flag.Value</code></a> has changed slightly.
1093The <code>Set</code> method now returns an <code>error</code> instead of
1094a <code>bool</code> to indicate success or failure.
1095</p>
1096
1097<p>
1098There is also a new kind of flag, <code>Duration</code>, to support argument
1099values specifying time intervals.
1100Values for such flags must be given units, just as <code>time.Duration</code>
1101formats them: <code>10s</code>, <code>1h30m</code>, etc.
1102</p>
1103
Russ Coxa40065a2012-03-08 08:39:20 -05001104{{code "/doc/progs/go1.go" `/timeout/`}}
Rob Pike531ded92012-01-20 15:38:03 -08001105
1106<p>
1107<em>Updating</em>:
1108Programs that implement their own flags will need minor manual fixes to update their
1109<code>Set</code> methods.
1110The <code>Duration</code> flag is new and affects no existing code.
1111</p>
1112
1113
Rob Pike0a1376a2012-01-20 14:28:48 -08001114<h3 id="go">The go/* packages</h3>
1115
1116<p>
1117Several packages under <code>go</code> have slightly revised APIs.
1118</p>
1119
1120<p>
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001121A concrete <code>Mode</code> type was introduced for configuration mode flags
1122in the packages
1123<a href="/pkg/go/scanner/"><code>go/scanner</code></a>,
1124<a href="/pkg/go/parser/"><code>go/parser</code></a>,
1125<a href="/pkg/go/printer/"><code>go/printer</code></a>, and
1126<a href="/pkg/go/doc/"><code>go/doc</code></a>.
1127</p>
1128
1129<p>
Rob Pike0a1376a2012-01-20 14:28:48 -08001130The modes <code>AllowIllegalChars</code> and <code>InsertSemis</code> have been removed
1131from the <a href="/pkg/go/scanner/"><code>go/scanner</code></a> package. They were mostly
1132useful for scanning text other then Go source files. Instead, the
1133<a href="/pkg/text/scanner/"><code>text/scanner</code></a> package should be used
1134for that purpose.
1135</p>
1136
1137<p>
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001138The <a href="/pkg/go/scanner/#ErrorHandler"><code>ErrorHandler</code></a> provided
1139to the scanner's <a href="/pkg/go/scanner/#Scanner.Init"><code>Init</code></a> method is
1140now simply a function rather than an interface. The <code>ErrorVector</code> type has
1141been removed in favor of the (existing) <a href="/pkg/go/scanner/#ErrorList"><code>ErrorList</code></a>
1142type, and the <code>ErrorVector</code> methods have been migrated. Instead of embedding
1143an <code>ErrorVector</code> in a client of the scanner, now a client should maintain
1144an <code>ErrorList</code>.
1145</p>
1146
1147<p>
Rob Pike0a1376a2012-01-20 14:28:48 -08001148The set of parse functions provided by the <a href="/pkg/go/parser/"><code>go/parser</code></a>
1149package has been reduced to the primary parse function
Gustavo Niemeyer75e9d242012-01-25 23:42:36 -02001150<a href="/pkg/go/parser/#ParseFile"><code>ParseFile</code></a>, and a couple of
1151convenience functions <a href="/pkg/go/parser/#ParseDir"><code>ParseDir</code></a>
1152and <a href="/pkg/go/parser/#ParseExpr"><code>ParseExpr</code></a>.
Rob Pike0a1376a2012-01-20 14:28:48 -08001153</p>
1154
1155<p>
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001156The <a href="/pkg/go/printer/"><code>go/printer</code></a> package supports an additional
1157configuration mode <a href="/pkg/go/printer/#Mode"><code>SourcePos</code></a>;
1158if set, the printer will emit <code>//line</code> comments such that the generated
1159output contains the original source code position information. The new type
Rob Pike1cd272d2012-03-08 17:15:23 +11001160<a href="/pkg/go/printer/#CommentedNode"><code>CommentedNode</code></a> can be
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001161used to provide comments associated with an arbitrary
1162<a href="/pkg/go/ast/#Node"><code>ast.Node</code></a> (until now only
1163<a href="/pkg/go/ast/#File"><code>ast.File</code></a> carried comment information).
1164</p>
1165
1166<p>
Gustavo Niemeyer75e9d242012-01-25 23:42:36 -02001167The type names of the <a href="/pkg/go/doc/"><code>go/doc</code></a> package have been
Rob Pike0a1376a2012-01-20 14:28:48 -08001168streamlined by removing the <code>Doc</code> suffix: <code>PackageDoc</code>
1169is now <code>Package</code>, <code>ValueDoc</code> is <code>Value</code>, etc.
1170Also, all types now consistently have a <code>Name</code> field (or <code>Names</code>,
Robert Griesemerd571c5c2012-01-25 16:48:06 -08001171in the case of type <code>Value</code>) and <code>Type.Factories</code> has become
1172<code>Type.Funcs</code>.
Rob Pike0a1376a2012-01-20 14:28:48 -08001173Instead of calling <code>doc.NewPackageDoc(pkg, importpath)</code>,
1174documentation for a package is created with:
1175</p>
1176
1177<pre>
1178 doc.New(pkg, importpath, mode)
1179</pre>
1180
1181<p>
1182where the new <code>mode</code> parameter specifies the operation mode:
Gustavo Niemeyer75e9d242012-01-25 23:42:36 -02001183if set to <a href="/pkg/go/doc/#AllDecls"><code>AllDecls</code></a>, all declarations
Rob Pike0a1376a2012-01-20 14:28:48 -08001184(not just exported ones) are considered.
1185The function <code>NewFileDoc</code> was removed, and the function
1186<code>CommentText</code> has become the method
Brad Fitzpatrick12566a62013-04-18 12:43:23 -07001187<a href="/pkg/go/ast/#CommentGroup.Text"><code>Text</code></a> of
Gustavo Niemeyer75e9d242012-01-25 23:42:36 -02001188<a href="/pkg/go/ast/#CommentGroup"><code>ast.CommentGroup</code></a>.
Rob Pike0a1376a2012-01-20 14:28:48 -08001189</p>
1190
1191<p>
Gustavo Niemeyer75e9d242012-01-25 23:42:36 -02001192In package <a href="/pkg/go/token/"><code>go/token</code></a>, the
1193<a href="/pkg/go/token/#FileSet"><code>token.FileSet</code></a> method <code>Files</code>
Rob Pike0a1376a2012-01-20 14:28:48 -08001194(which originally returned a channel of <code>*token.File</code>s) has been replaced
Gustavo Niemeyer75e9d242012-01-25 23:42:36 -02001195with the iterator <a href="/pkg/go/token/#FileSet.Iterate"><code>Iterate</code></a> that
Rob Pike0a1376a2012-01-20 14:28:48 -08001196accepts a function argument instead.
1197</p>
1198
1199<p>
Russ Cox9996f7f2012-03-01 18:17:28 -05001200In package <a href="/pkg/go/build/"><code>go/build</code></a>, the API
1201has been nearly completely replaced.
1202The package still computes Go package information
1203but it does not run the build: the <code>Cmd</code> and <code>Script</code>
1204types are gone.
1205(To build code, use the new
1206<a href="/cmd/go/"><code>go</code></a> command instead.)
1207The <code>DirInfo</code> type is now named
1208<a href="/pkg/go/build/#Package"><code>Package</code></a>.
1209<code>FindTree</code> and <code>ScanDir</code> are replaced by
1210<a href="/pkg/go/build/#Import"><code>Import</code></a>
1211and
1212<a href="/pkg/go/build/#ImportDir"><code>ImportDir</code></a>.
1213</p>
1214
1215<p>
Rob Pike0a1376a2012-01-20 14:28:48 -08001216<em>Updating</em>:
1217Code that uses packages in <code>go</code> will have to be updated by hand; the
Rob Pike68c7e8a2012-02-27 07:31:34 +11001218compiler will reject incorrect uses. Templates used in conjunction with any of the
Rob Pike0a1376a2012-01-20 14:28:48 -08001219<code>go/doc</code> types may need manual fixes; the renamed fields will lead
1220to run-time errors.
1221</p>
1222
Russ Cox1f1c9ba2012-01-18 10:36:43 -05001223<h3 id="hash">The hash package</h3>
1224
1225<p>
1226In Go 1, the definition of <a href="/pkg/hash/#Hash"><code>hash.Hash</code></a> includes
Rob Pike1cd272d2012-03-08 17:15:23 +11001227a new method, <code>BlockSize</code>. This new method is used primarily in the
Russ Cox1f1c9ba2012-01-18 10:36:43 -05001228cryptographic libraries.
1229</p>
1230
1231<p>
Rob Pike03ea8b12012-01-24 16:36:40 -08001232The <code>Sum</code> method of the
1233<a href="/pkg/hash/#Hash"><code>hash.Hash</code></a> interface now takes a
1234<code>[]byte</code> argument, to which the hash value will be appended.
1235The previous behavior can be recreated by adding a <code>nil</code> argument to the call.
1236</p>
1237
1238<p>
Russ Cox1f1c9ba2012-01-18 10:36:43 -05001239<em>Updating</em>:
1240Existing implementations of <code>hash.Hash</code> will need to add a
1241<code>BlockSize</code> method. Hashes that process the input one byte at
1242a time can implement <code>BlockSize</code> to return 1.
Rob Pike5cff0292012-02-24 13:08:11 +11001243Running <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 -08001244implementations of <code>hash.Hash</code>.
Rob Pikef76bd4f2011-12-12 19:25:25 -08001245</p>
1246
1247<p>
1248<em>Updating</em>:
1249Since the package's functionality is new, no updating is necessary.
1250</p>
1251
Rob Pikebab4dec2011-12-07 14:33:37 -08001252<h3 id="http">The http package</h3>
1253
Rob Pikef76bd4f2011-12-12 19:25:25 -08001254<p>
Jongmin Kim343098e2012-01-17 09:47:34 -08001255In Go 1 the <a href="/pkg/net/http/"><code>http</code></a> package is refactored,
Rob Pikef76bd4f2011-12-12 19:25:25 -08001256putting some of the utilities into a
Shenghou Mac80a32b2012-03-30 14:06:12 +08001257<a href="/pkg/net/http/httputil/"><code>httputil</code></a> subdirectory.
Rob Pikef76bd4f2011-12-12 19:25:25 -08001258These pieces are only rarely needed by HTTP clients.
1259The affected items are:
1260</p>
1261
1262<ul>
1263<li>ClientConn</li>
1264<li>DumpRequest</li>
Rob Pikef76bd4f2011-12-12 19:25:25 -08001265<li>DumpRequestOut</li>
1266<li>DumpResponse</li>
1267<li>NewChunkedReader</li>
1268<li>NewChunkedWriter</li>
1269<li>NewClientConn</li>
1270<li>NewProxyClientConn</li>
1271<li>NewServerConn</li>
1272<li>NewSingleHostReverseProxy</li>
1273<li>ReverseProxy</li>
1274<li>ServerConn</li>
1275</ul>
1276
1277<p>
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001278The <code>Request.RawURL</code> field has been removed; it was a
Rob Pikef76bd4f2011-12-12 19:25:25 -08001279historical artifact.
1280</p>
1281
1282<p>
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001283The <code>Handle</code> and <code>HandleFunc</code>
1284functions, and the similarly-named methods of <code>ServeMux</code>,
1285now panic if an attempt is made to register the same pattern twice.
1286</p>
1287
1288<p>
Rob Pikef76bd4f2011-12-12 19:25:25 -08001289<em>Updating</em>:
Rob Pike5cff0292012-02-24 13:08:11 +11001290Running <code>go</code> <code>fix</code> will update the few programs that are affected except for
Rob Pikef76bd4f2011-12-12 19:25:25 -08001291uses of <code>RawURL</code>, which must be fixed by hand.
1292</p>
1293
Rob Pike2257e762012-01-23 16:11:49 -08001294<h3 id="image">The image package</h3>
1295
1296<p>
1297The <a href="/pkg/image/"><code>image</code></a> package has had a number of
1298minor changes, rearrangements and renamings.
1299</p>
1300
1301<p>
1302Most of the color handling code has been moved into its own package,
1303<a href="/pkg/image/color/"><code>image/color</code></a>.
1304For the elements that moved, a symmetry arises; for instance,
1305each pixel of an
1306<a href="/pkg/image/#RGBA"><code>image.RGBA</code></a>
1307is a
1308<a href="/pkg/image/color/#RGBA"><code>color.RGBA</code></a>.
1309</p>
1310
1311<p>
1312The old <code>image/ycbcr</code> package has been folded, with some
1313renamings, into the
1314<a href="/pkg/image/"><code>image</code></a>
1315and
1316<a href="/pkg/image/color/"><code>image/color</code></a>
1317packages.
1318</p>
1319
1320<p>
1321The old <code>image.ColorImage</code> type is still in the <code>image</code>
1322package but has been renamed
1323<a href="/pkg/image/#Uniform"><code>image.Uniform</code></a>,
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001324while <code>image.Tiled</code> has been removed.
Rob Pike2257e762012-01-23 16:11:49 -08001325</p>
1326
1327<p>
1328This table lists the renamings.
1329</p>
1330
1331<table class="codetable" frame="border" summary="image renames">
1332<colgroup align="left" width="50%"></colgroup>
1333<colgroup align="left" width="50%"></colgroup>
1334<tr>
1335<th align="left">Old</th>
1336<th align="left">New</th>
1337</tr>
1338<tr>
1339<td colspan="2"><hr></td>
1340</tr>
1341<tr><td>image.Color</td> <td>color.Color</td></tr>
1342<tr><td>image.ColorModel</td> <td>color.Model</td></tr>
1343<tr><td>image.ColorModelFunc</td> <td>color.ModelFunc</td></tr>
1344<tr><td>image.PalettedColorModel</td> <td>color.Palette</td></tr>
1345<tr>
1346<td colspan="2"><hr></td>
1347</tr>
1348<tr><td>image.RGBAColor</td> <td>color.RGBA</td></tr>
1349<tr><td>image.RGBA64Color</td> <td>color.RGBA64</td></tr>
1350<tr><td>image.NRGBAColor</td> <td>color.NRGBA</td></tr>
1351<tr><td>image.NRGBA64Color</td> <td>color.NRGBA64</td></tr>
1352<tr><td>image.AlphaColor</td> <td>color.Alpha</td></tr>
1353<tr><td>image.Alpha16Color</td> <td>color.Alpha16</td></tr>
1354<tr><td>image.GrayColor</td> <td>color.Gray</td></tr>
1355<tr><td>image.Gray16Color</td> <td>color.Gray16</td></tr>
1356<tr>
1357<td colspan="2"><hr></td>
1358</tr>
1359<tr><td>image.RGBAColorModel</td> <td>color.RGBAModel</td></tr>
1360<tr><td>image.RGBA64ColorModel</td> <td>color.RGBA64Model</td></tr>
1361<tr><td>image.NRGBAColorModel</td> <td>color.NRGBAModel</td></tr>
1362<tr><td>image.NRGBA64ColorModel</td> <td>color.NRGBA64Model</td></tr>
1363<tr><td>image.AlphaColorModel</td> <td>color.AlphaModel</td></tr>
1364<tr><td>image.Alpha16ColorModel</td> <td>color.Alpha16Model</td></tr>
1365<tr><td>image.GrayColorModel</td> <td>color.GrayModel</td></tr>
1366<tr><td>image.Gray16ColorModel</td> <td>color.Gray16Model</td></tr>
1367<tr>
1368<td colspan="2"><hr></td>
1369</tr>
1370<tr><td>ycbcr.RGBToYCbCr</td> <td>color.RGBToYCbCr</td></tr>
1371<tr><td>ycbcr.YCbCrToRGB</td> <td>color.YCbCrToRGB</td></tr>
1372<tr><td>ycbcr.YCbCrColorModel</td> <td>color.YCbCrModel</td></tr>
1373<tr><td>ycbcr.YCbCrColor</td> <td>color.YCbCr</td></tr>
1374<tr><td>ycbcr.YCbCr</td> <td>image.YCbCr</td></tr>
1375<tr>
1376<td colspan="2"><hr></td>
1377</tr>
1378<tr><td>ycbcr.SubsampleRatio444</td> <td>image.YCbCrSubsampleRatio444</td></tr>
1379<tr><td>ycbcr.SubsampleRatio422</td> <td>image.YCbCrSubsampleRatio422</td></tr>
1380<tr><td>ycbcr.SubsampleRatio420</td> <td>image.YCbCrSubsampleRatio420</td></tr>
1381<tr>
1382<td colspan="2"><hr></td>
1383</tr>
1384<tr><td>image.ColorImage</td> <td>image.Uniform</td></tr>
Rob Pike2257e762012-01-23 16:11:49 -08001385</table>
1386
1387<p>
1388The image package's <code>New</code> functions
1389(<a href="/pkg/image/#NewRGBA"><code>NewRGBA</code></a>,
1390<a href="/pkg/image/#NewRGBA64"><code>NewRGBA64</code></a>, etc.)
1391take an <a href="/pkg/image/#Rectangle"><code>image.Rectangle</code></a> as an argument
1392instead of four integers.
1393</p>
1394
1395<p>
1396Finally, there are new predefined <code>color.Color</code> variables
1397<a href="/pkg/image/color/#Black"><code>color.Black</code></a>,
1398<a href="/pkg/image/color/#White"><code>color.White</code></a>,
1399<a href="/pkg/image/color/#Opaque"><code>color.Opaque</code></a>
1400and
1401<a href="/pkg/image/color/#Transparent"><code>color.Transparent</code></a>.
1402</p>
1403
1404<p>
1405<em>Updating</em>:
Rob Pike5cff0292012-02-24 13:08:11 +11001406Running <code>go</code> <code>fix</code> will update almost all code affected by the change.
Rob Pike2257e762012-01-23 16:11:49 -08001407</p>
1408
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001409<h3 id="log_syslog">The log/syslog package</h3>
1410
1411<p>
Rob Pike1cd272d2012-03-08 17:15:23 +11001412In Go 1, the <a href="/pkg/log/syslog/#NewLogger"><code>syslog.NewLogger</code></a>
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001413function returns an error as well as a <code>log.Logger</code>.
1414</p>
1415
1416<p>
1417<em>Updating</em>:
1418What little code is affected will be caught by the compiler and must be updated by hand.
1419</p>
1420
Rob Pikedd442a52012-01-24 17:02:06 -08001421<h3 id="mime">The mime package</h3>
1422
1423<p>
1424In Go 1, the <a href="/pkg/mime/#FormatMediaType"><code>FormatMediaType</code></a> function
1425of the <code>mime</code> package has been simplified to make it
1426consistent with
Rob Pike1cd272d2012-03-08 17:15:23 +11001427<a href="/pkg/mime/#ParseMediaType"><code>ParseMediaType</code></a>.
Rob Pikedd442a52012-01-24 17:02:06 -08001428It now takes <code>"text/html"</code> rather than <code>"text"</code> and <code>"html"</code>.
1429</p>
1430
1431<p>
1432<em>Updating</em>:
1433What little code is affected will be caught by the compiler and must be updated by hand.
1434</p>
1435
Brad Fitzpatrickb71883e2012-01-18 16:24:06 -08001436<h3 id="net">The net package</h3>
1437
Rob Pike03ea8b12012-01-24 16:36:40 -08001438<p>
1439In Go 1, the various <code>SetTimeout</code>,
Brad Fitzpatrickb71883e2012-01-18 16:24:06 -08001440<code>SetReadTimeout</code>, and <code>SetWriteTimeout</code> methods
Rob Pike1cd272d2012-03-08 17:15:23 +11001441have been replaced with
Rob Pike03ea8b12012-01-24 16:36:40 -08001442<a href="/pkg/net/#IPConn.SetDeadline"><code>SetDeadline</code></a>,
Rob Pike1cd272d2012-03-08 17:15:23 +11001443<a href="/pkg/net/#IPConn.SetReadDeadline"><code>SetReadDeadline</code></a>, and
Rob Pike03ea8b12012-01-24 16:36:40 -08001444<a href="/pkg/net/#IPConn.SetWriteDeadline"><code>SetWriteDeadline</code></a>,
Brad Fitzpatrickb71883e2012-01-18 16:24:06 -08001445respectively. Rather than taking a timeout value in nanoseconds that
1446apply to any activity on the connection, the new methods set an
1447absolute deadline (as a <code>time.Time</code> value) after which
Rob Pike03ea8b12012-01-24 16:36:40 -08001448reads and writes will time out and no longer block.
1449</p>
1450
1451<p>
Mikio Hara2f63afd2012-02-01 01:53:26 +09001452There are also new functions
1453<a href="/pkg/net/#DialTimeout"><code>net.DialTimeout</code></a>
1454to simplify timing out dialing a network address and
1455<a href="/pkg/net/#ListenMulticastUDP"><code>net.ListenMulticastUDP</code></a>
1456to allow multicast UDP to listen concurrently across multiple listeners.
1457The <code>net.ListenMulticastUDP</code> function replaces the old
1458<code>JoinGroup</code> and <code>LeaveGroup</code> methods.
Rob Pike03ea8b12012-01-24 16:36:40 -08001459</p>
1460
1461<p>
1462<em>Updating</em>:
1463Code that uses the old methods will fail to compile and must be updated by hand.
Rob Pike27836912012-02-04 07:49:51 +11001464The semantic change makes it difficult for the fix tool to update automatically.
Rob Pike03ea8b12012-01-24 16:36:40 -08001465</p>
Brad Fitzpatrickb71883e2012-01-18 16:24:06 -08001466
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001467<h3 id="os">The os package</h3>
1468
Rob Pikec3ef1982012-02-19 14:15:26 +11001469<p>
1470The <code>Time</code> function has been removed; callers should use
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001471the <a href="/pkg/time/#Time"><code>Time</code></a> type from the
Rob Pikec3ef1982012-02-19 14:15:26 +11001472<code>time</code> package.
1473</p>
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001474
Rob Pikec3ef1982012-02-19 14:15:26 +11001475<p>
1476The <code>Exec</code> function has been removed; callers should use
1477<code>Exec</code> from the <code>syscall</code> package, where available.
1478</p>
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001479
Rob Pikec3ef1982012-02-19 14:15:26 +11001480<p>
1481The <code>ShellExpand</code> function has been renamed to <a
1482href="/pkg/os/#ExpandEnv"><code>ExpandEnv</code></a>.
1483</p>
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001484
Rob Pikec3ef1982012-02-19 14:15:26 +11001485<p>
1486The <a href="/pkg/os/#NewFile"><code>NewFile</code></a> function
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001487now takes a <code>uintptr</code> fd, instead of an <code>int</code>.
1488The <a href="/pkg/os/#File.Fd"><code>Fd</code></a> method on files now
Rob Pikec3ef1982012-02-19 14:15:26 +11001489also returns a <code>uintptr</code>.
1490</p>
1491
1492<p>
1493There are no longer error constants such as <code>EINVAL</code>
1494in the <code>os</code> package, since the set of values varied with
1495the underlying operating system. There are new portable functions like
1496<a href="/pkg/os/#IsPermission"><code>IsPermission</code></a>
1497to test common error properties, plus a few new error values
1498with more Go-like names, such as
1499<a href="/pkg/os/#ErrPermission"><code>ErrPermission</code></a>
1500and
Brad Fitzpatrick12566a62013-04-18 12:43:23 -07001501<a href="/pkg/os/#ErrNotExist"><code>ErrNotExist</code></a>.
Brad Fitzpatrickefacb2a2012-02-18 21:18:13 -08001502</p>
Rob Pikec3ef1982012-02-19 14:15:26 +11001503
Brad Fitzpatrickefacb2a2012-02-18 21:18:13 -08001504<p>
1505The <code>Getenverror</code> function has been removed. To distinguish
1506between a non-existent environment variable and an empty string,
1507use <a href="/pkg/os/#Environ"><code>os.Environ</code></a> or
1508<a href="/pkg/syscall/#Getenv"><code>syscall.Getenv</code></a>.
1509</p>
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001510
Rob Pikeb5a3bd52012-02-20 15:36:08 +11001511
1512<p>
1513The <a href="/pkg/os/#Process.Wait"><code>Process.Wait</code></a> method has
1514dropped its option argument and the associated constants are gone
1515from the package.
1516Also, the function <code>Wait</code> is gone; only the method of
1517the <code>Process</code> type persists.
1518</p>
1519
Nigel Taoda8f0372012-02-15 14:41:47 +11001520<p>
Rob Pike5cff0292012-02-24 13:08:11 +11001521The <code>Waitmsg</code> type returned by
1522<a href="/pkg/os/#Process.Wait"><code>Process.Wait</code></a>
1523has been replaced with a more portable
1524<a href="/pkg/os/#ProcessState"><code>ProcessState</code></a>
1525type with accessor methods to recover information about the
1526process.
1527Because of changes to <code>Wait</code>, the <code>ProcessState</code>
1528value always describes an exited process.
1529Portability concerns simplified the interface in other ways, but the values returned by the
1530<a href="/pkg/os/#ProcessState.Sys"><code>ProcessState.Sys</code></a> and
1531<a href="/pkg/os/#ProcessState.SysUsage"><code>ProcessState.SysUsage</code></a>
1532methods can be type-asserted to underlying system-specific data structures such as
1533<a href="/pkg/syscall/#WaitStatus"><code>syscall.WaitStatus</code></a> and
1534<a href="/pkg/syscall/#Rusage"><code>syscall.Rusage</code></a> on Unix.
1535</p>
1536
1537<p>
Nigel Taoda8f0372012-02-15 14:41:47 +11001538<em>Updating</em>:
Rob Pike5cff0292012-02-24 13:08:11 +11001539Running <code>go</code> <code>fix</code> will drop a zero argument to <code>Process.Wait</code>.
1540All other changes will be caught by the compiler and must be updated by hand.
Nigel Taoda8f0372012-02-15 14:41:47 +11001541</p>
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001542
1543<h4 id="os_fileinfo">The os.FileInfo type</h4>
Rob Pike0a1376a2012-01-20 14:28:48 -08001544
1545<p>
1546Go 1 redefines the <a href="/pkg/os/#FileInfo"><code>os.FileInfo</code></a> type,
1547changing it from a struct to an interface:
1548</p>
1549
1550<pre>
1551 type FileInfo interface {
1552 Name() string // base name of the file
1553 Size() int64 // length in bytes
1554 Mode() FileMode // file mode bits
1555 ModTime() time.Time // modification time
1556 IsDir() bool // abbreviation for Mode().IsDir()
Rob Pike46dc76f2012-02-12 09:17:57 +11001557 Sys() interface{} // underlying data source (can return nil)
Rob Pike0a1376a2012-01-20 14:28:48 -08001558 }
1559</pre>
1560
1561<p>
1562The file mode information has been moved into a subtype called
1563<a href="/pkg/os/#FileMode"><code>os.FileMode</code></a>,
1564a simple integer type with <code>IsDir</code>, <code>Perm</code>, and <code>String</code>
1565methods.
1566</p>
1567
1568<p>
1569The system-specific details of file modes and properties such as (on Unix)
1570i-number have been removed from <code>FileInfo</code> altogether.
1571Instead, each operating system's <code>os</code> package provides an
Rob Pike6ba77ec2012-02-21 08:03:03 +11001572implementation of the <code>FileInfo</code> interface, which
1573has a <code>Sys</code> method that returns the
Rob Pike0a1376a2012-01-20 14:28:48 -08001574system-specific representation of file metadata.
1575For instance, to discover the i-number of a file on a Unix system, unpack
1576the <code>FileInfo</code> like this:
1577</p>
1578
1579<pre>
1580 fi, err := os.Stat("hello.go")
1581 if err != nil {
1582 log.Fatal(err)
1583 }
Rob Pike46dc76f2012-02-12 09:17:57 +11001584 // Check that it's a Unix file.
1585 unixStat, ok := fi.Sys().(*syscall.Stat_t)
Rob Pike0a1376a2012-01-20 14:28:48 -08001586 if !ok {
1587 log.Fatal("hello.go: not a Unix file")
1588 }
1589 fmt.Printf("file i-number: %d\n", unixStat.Ino)
1590</pre>
1591
1592<p>
1593Assuming (which is unwise) that <code>"hello.go"</code> is a Unix file,
1594the i-number expression could be contracted to
1595</p>
1596
1597<pre>
Rob Pikeaee1c382012-02-13 08:05:53 +11001598 fi.Sys().(*syscall.Stat_t).Ino
Rob Pike0a1376a2012-01-20 14:28:48 -08001599</pre>
1600
1601<p>
1602The vast majority of uses of <code>FileInfo</code> need only the methods
1603of the standard interface.
1604</p>
Rob Pike56069f02012-02-17 10:04:29 +11001605
1606<p>
1607The <code>os</code> package no longer contains wrappers for the POSIX errors
1608such as <code>ENOENT</code>.
1609For the few programs that need to verify particular error conditions, there are
1610now the boolean functions
1611<a href="/pkg/os/#IsExist"><code>IsExist</code></a>,
1612<a href="/pkg/os/#IsNotExist"><code>IsNotExist</code></a>
1613and
1614<a href="/pkg/os/#IsPermission"><code>IsPermission</code></a>.
1615</p>
1616
Russ Coxa40065a2012-03-08 08:39:20 -05001617{{code "/doc/progs/go1.go" `/os\.Open/` `/}/`}}
Rob Pike56069f02012-02-17 10:04:29 +11001618
Rob Pike0a1376a2012-01-20 14:28:48 -08001619<p>
1620<em>Updating</em>:
Rob Pike5cff0292012-02-24 13:08:11 +11001621Running <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 -08001622and <code>os.FileMode</code> API.
1623Code that needs system-specific file details will need to be updated by hand.
Rob Pike56069f02012-02-17 10:04:29 +11001624Code that uses the old POSIX error values from the <code>os</code> package
1625will fail to compile and will also need to be updated by hand.
Rob Pike0a1376a2012-01-20 14:28:48 -08001626</p>
1627
Rob Pikecc7e11c2012-02-27 14:34:16 +11001628<h3 id="os_signal">The os/signal package</h3>
1629
1630<p>
1631The <code>os/signal</code> package in Go 1 replaces the
1632<code>Incoming</code> function, which returned a channel
1633that received all incoming signals,
1634with the selective <code>Notify</code> function, which asks
1635for delivery of specific signals on an existing channel.
1636</p>
1637
1638<p>
1639<em>Updating</em>:
1640Code must be updated by hand.
1641A literal translation of
1642</p>
1643<pre>
1644c := signal.Incoming()
1645</pre>
1646<p>
1647is
1648</p>
1649<pre>
1650c := make(chan os.Signal)
1651signal.Notify(c) // ask for all signals
1652</pre>
1653<p>
1654but most code should list the specific signals it wants to handle instead:
1655</p>
1656<pre>
1657c := make(chan os.Signal)
1658signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT)
1659</pre>
1660
Rob Pikedd442a52012-01-24 17:02:06 -08001661<h3 id="path_filepath">The path/filepath package</h3>
1662
1663<p>
1664In Go 1, the <a href="/pkg/path/filepath/#Walk"><code>Walk</code></a> function of the
1665<code>path/filepath</code> package
1666has been changed to take a function value of type
1667<a href="/pkg/path/filepath/#WalkFunc"><code>WalkFunc</code></a>
1668instead of a <code>Visitor</code> interface value.
1669<code>WalkFunc</code> unifies the handling of both files and directories.
1670</p>
1671
1672<pre>
Mike Rosset4af3dda2012-02-24 22:17:21 -08001673 type WalkFunc func(path string, info os.FileInfo, err error) error
Rob Pikedd442a52012-01-24 17:02:06 -08001674</pre>
1675
1676<p>
1677The <code>WalkFunc</code> function will be called even for files or directories that could not be opened;
1678in such cases the error argument will describe the failure.
1679If a directory's contents are to be skipped,
Péter Surányibe7c0f32012-12-29 10:41:39 +11001680the function should return the value <a href="/pkg/path/filepath/#pkg-variables"><code>filepath.SkipDir</code></a>
Rob Pikedd442a52012-01-24 17:02:06 -08001681</p>
1682
Russ Coxa40065a2012-03-08 08:39:20 -05001683{{code "/doc/progs/go1.go" `/STARTWALK/` `/ENDWALK/`}}
Rob Pikedd442a52012-01-24 17:02:06 -08001684
1685<p>
1686<em>Updating</em>:
1687The change simplifies most code but has subtle consequences, so affected programs
1688will need to be updated by hand.
1689The compiler will catch code using the old interface.
1690</p>
1691
Rob Pikecc7e11c2012-02-27 14:34:16 +11001692<h3 id="regexp">The regexp package</h3>
Russ Cox35586f72012-02-13 13:52:37 -05001693
1694<p>
Rob Pikecc7e11c2012-02-27 14:34:16 +11001695The <a href="/pkg/regexp/"><code>regexp</code></a> package has been rewritten.
Rob Pike1cd272d2012-03-08 17:15:23 +11001696It has the same interface but the specification of the regular expressions
Rob Pikecc7e11c2012-02-27 14:34:16 +11001697it supports has changed from the old "egrep" form to that of
Andrew Gerrand43ad89d2014-07-25 10:28:39 +10001698<a href="//code.google.com/p/re2/">RE2</a>.
Russ Cox35586f72012-02-13 13:52:37 -05001699</p>
1700
1701<p>
1702<em>Updating</em>:
Rob Pikecc7e11c2012-02-27 14:34:16 +11001703Code that uses the package should have its regular expressions checked by hand.
Russ Cox35586f72012-02-13 13:52:37 -05001704</p>
Russ Cox35586f72012-02-13 13:52:37 -05001705
Rob Pike531ded92012-01-20 15:38:03 -08001706<h3 id="runtime">The runtime package</h3>
1707
1708<p>
Russ Cox72f5a912012-02-19 18:04:38 -05001709In Go 1, much of the API exported by package
1710<code>runtime</code> has been removed in favor of
1711functionality provided by other packages.
1712Code using the <code>runtime.Type</code> interface
1713or its specific concrete type implementations should
1714now use package <a href="/pkg/reflect/"><code>reflect</code></a>.
1715Code using <code>runtime.Semacquire</code> or <code>runtime.Semrelease</code>
1716should use channels or the abstractions in package <a href="/pkg/sync/"><code>sync</code></a>.
1717The <code>runtime.Alloc</code>, <code>runtime.Free</code>,
1718and <code>runtime.Lookup</code> functions, an unsafe API created for
1719debugging the memory allocator, have no replacement.
1720</p>
1721
1722<p>
1723Before, <code>runtime.MemStats</code> was a global variable holding
1724statistics about memory allocation, and calls to <code>runtime.UpdateMemStats</code>
1725ensured that it was up to date.
1726In Go 1, <code>runtime.MemStats</code> is a struct type, and code should use
1727<a href="/pkg/runtime/#ReadMemStats"><code>runtime.ReadMemStats</code></a>
1728to obtain the current statistics.
1729</p>
1730
1731<p>
1732The package adds a new function,
Rob Pike531ded92012-01-20 15:38:03 -08001733<a href="/pkg/runtime/#NumCPU"><code>runtime.NumCPU</code></a>, that returns the number of CPUs available
1734for parallel execution, as reported by the operating system kernel.
1735Its value can inform the setting of <code>GOMAXPROCS</code>.
Russ Cox72f5a912012-02-19 18:04:38 -05001736The <code>runtime.Cgocalls</code> and <code>runtime.Goroutines</code> functions
1737have been renamed to <code>runtime.NumCgoCall</code> and <code>runtime.NumGoroutine</code>.
Rob Pike531ded92012-01-20 15:38:03 -08001738</p>
1739
1740<p>
1741<em>Updating</em>:
Rob Pike5cff0292012-02-24 13:08:11 +11001742Running <code>go</code> <code>fix</code> will update code for the function renamings.
Russ Cox72f5a912012-02-19 18:04:38 -05001743Other code will need to be updated by hand.
Rob Pike531ded92012-01-20 15:38:03 -08001744</p>
1745
Rob Pikebab4dec2011-12-07 14:33:37 -08001746<h3 id="strconv">The strconv package</h3>
1747
Rob Pike71ccf732011-12-09 14:12:51 -08001748<p>
1749In Go 1, the
Rob Pikeebdcbf12011-12-12 12:26:56 -08001750<a href="/pkg/strconv/"><code>strconv</code></a>
Rob Pike71ccf732011-12-09 14:12:51 -08001751package has been significantly reworked to make it more Go-like and less C-like,
1752although <code>Atoi</code> lives on (it's similar to
1753<code>int(ParseInt(x, 10, 0))</code>, as does
1754<code>Itoa(x)</code> (<code>FormatInt(int64(x), 10)</code>).
1755There are also new variants of some of the functions that append to byte slices rather than
1756return strings, to allow control over allocation.
1757</p>
1758
1759<p>
1760This table summarizes the renamings; see the
Rob Pikeebdcbf12011-12-12 12:26:56 -08001761<a href="/pkg/strconv/">package documentation</a>
Rob Pike71ccf732011-12-09 14:12:51 -08001762for full details.
1763</p>
1764
1765<table class="codetable" frame="border" summary="strconv renames">
1766<colgroup align="left" width="50%"></colgroup>
1767<colgroup align="left" width="50%"></colgroup>
1768<tr>
1769<th align="left">Old call</th>
1770<th align="left">New call</th>
1771</tr>
1772<tr>
1773<td colspan="2"><hr></td>
1774</tr>
1775<tr><td>Atob(x)</td> <td>ParseBool(x)</td></tr>
1776<tr>
1777<td colspan="2"><hr></td>
1778</tr>
1779<tr><td>Atof32(x)</td> <td>ParseFloat(x, 32)§</td></tr>
1780<tr><td>Atof64(x)</td> <td>ParseFloat(x, 64)</td></tr>
1781<tr><td>AtofN(x, n)</td> <td>ParseFloat(x, n)</td></tr>
1782<tr>
1783<td colspan="2"><hr></td>
1784</tr>
1785<tr><td>Atoi(x)</td> <td>Atoi(x)</td></tr>
1786<tr><td>Atoi(x)</td> <td>ParseInt(x, 10, 0)§</td></tr>
1787<tr><td>Atoi64(x)</td> <td>ParseInt(x, 10, 64)</td></tr>
1788<tr>
1789<td colspan="2"><hr></td>
1790</tr>
1791<tr><td>Atoui(x)</td> <td>ParseUint(x, 10, 0)§</td></tr>
Dave Cheneyd7bc6442012-04-11 10:59:03 +10001792<tr><td>Atoui64(x)</td> <td>ParseUint(x, 10, 64)</td></tr>
Rob Pike71ccf732011-12-09 14:12:51 -08001793<tr>
1794<td colspan="2"><hr></td>
1795</tr>
1796<tr><td>Btoi64(x, b)</td> <td>ParseInt(x, b, 64)</td></tr>
1797<tr><td>Btoui64(x, b)</td> <td>ParseUint(x, b, 64)</td></tr>
1798<tr>
1799<td colspan="2"><hr></td>
1800</tr>
1801<tr><td>Btoa(x)</td> <td>FormatBool(x)</td></tr>
1802<tr>
1803<td colspan="2"><hr></td>
1804</tr>
Marcel van Lohuizen72fb81e2012-02-19 19:26:05 +01001805<tr><td>Ftoa32(x, f, p)</td> <td>FormatFloat(float64(x), f, p, 32)</td></tr>
Rob Pike71ccf732011-12-09 14:12:51 -08001806<tr><td>Ftoa64(x, f, p)</td> <td>FormatFloat(x, f, p, 64)</td></tr>
1807<tr><td>FtoaN(x, f, p, n)</td> <td>FormatFloat(x, f, p, n)</td></tr>
1808<tr>
1809<td colspan="2"><hr></td>
1810</tr>
1811<tr><td>Itoa(x)</td> <td>Itoa(x)</td></tr>
1812<tr><td>Itoa(x)</td> <td>FormatInt(int64(x), 10)</td></tr>
1813<tr><td>Itoa64(x)</td> <td>FormatInt(x, 10)</td></tr>
1814<tr>
1815<td colspan="2"><hr></td>
1816</tr>
1817<tr><td>Itob(x, b)</td> <td>FormatInt(int64(x), b)</td></tr>
1818<tr><td>Itob64(x, b)</td> <td>FormatInt(x, b)</td></tr>
1819<tr>
1820<td colspan="2"><hr></td>
1821</tr>
1822<tr><td>Uitoa(x)</td> <td>FormatUint(uint64(x), 10)</td></tr>
1823<tr><td>Uitoa64(x)</td> <td>FormatUint(x, 10)</td></tr>
1824<tr>
1825<td colspan="2"><hr></td>
1826</tr>
1827<tr><td>Uitob(x, b)</td> <td>FormatUint(uint64(x), b)</td></tr>
1828<tr><td>Uitob64(x, b)</td> <td>FormatUint(x, b)</td></tr>
1829</table>
1830
1831<p>
1832<em>Updating</em>:
Rob Pike5cff0292012-02-24 13:08:11 +11001833Running <code>go</code> <code>fix</code> will update almost all code affected by the change.
Rob Pike71ccf732011-12-09 14:12:51 -08001834<br>
1835§ <code>Atoi</code> persists but <code>Atoui</code> and <code>Atof32</code> do not, so
1836they may require
Rob Pike5cff0292012-02-24 13:08:11 +11001837a 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 -08001838</p>
1839
Rob Pikebab4dec2011-12-07 14:33:37 -08001840
Rob Pike1cd272d2012-03-08 17:15:23 +11001841<h3 id="templates">The template packages</h3>
1842
1843<p>
1844The <code>template</code> and <code>exp/template/html</code> packages have moved to
1845<a href="/pkg/text/template/"><code>text/template</code></a> and
1846<a href="/pkg/html/template/"><code>html/template</code></a>.
1847More significant, the interface to these packages has been simplified.
1848The template language is the same, but the concept of "template set" is gone
1849and the functions and methods of the packages have changed accordingly,
1850often by elimination.
1851</p>
1852
1853<p>
1854Instead of sets, a <code>Template</code> object
1855may contain multiple named template definitions,
1856in effect constructing
1857name spaces for template invocation.
1858A template can invoke any other template associated with it, but only those
1859templates associated with it.
1860The simplest way to associate templates is to parse them together, something
1861made easier with the new structure of the packages.
1862</p>
1863
1864<p>
1865<em>Updating</em>:
1866The imports will be updated by fix tool.
1867Single-template uses will be otherwise be largely unaffected.
1868Code that uses multiple templates in concert will need to be updated by hand.
Péter Surányibe7c0f32012-12-29 10:41:39 +11001869The <a href="/pkg/text/template/#pkg-examples">examples</a> in
Rob Pike1cd272d2012-03-08 17:15:23 +11001870the documentation for <code>text/template</code> can provide guidance.
1871</p>
1872
Rob Pike531ded92012-01-20 15:38:03 -08001873<h3 id="testing">The testing package</h3>
1874
1875<p>
1876The testing package has a type, <code>B</code>, passed as an argument to benchmark functions.
1877In Go 1, <code>B</code> has new methods, analogous to those of <code>T</code>, enabling
1878logging and failure reporting.
1879</p>
1880
Russ Coxa40065a2012-03-08 08:39:20 -05001881{{code "/doc/progs/go1.go" `/func.*Benchmark/` `/^}/`}}
Rob Pike531ded92012-01-20 15:38:03 -08001882
1883<p>
1884<em>Updating</em>:
1885Existing code is unaffected, although benchmarks that use <code>println</code>
Rob Pike2257e762012-01-23 16:11:49 -08001886or <code>panic</code> should be updated to use the new methods.
Rob Pike531ded92012-01-20 15:38:03 -08001887</p>
1888
Adam Langleyc2e58dc2012-02-14 07:13:57 -05001889<h3 id="testing_script">The testing/script package</h3>
1890
1891<p>
1892The testing/script package has been deleted. It was a dreg.
1893</p>
1894
1895<p>
1896<em>Updating</em>:
1897No code is likely to be affected.
1898</p>
1899
Russ Cox72f5a912012-02-19 18:04:38 -05001900<h3 id="unsafe">The unsafe package</h3>
1901
1902<p>
1903In Go 1, the functions
1904<code>unsafe.Typeof</code>, <code>unsafe.Reflect</code>,
1905<code>unsafe.Unreflect</code>, <code>unsafe.New</code>, and
1906<code>unsafe.NewArray</code> have been removed;
1907they duplicated safer functionality provided by
1908package <a href="/pkg/reflect/"><code>reflect</code></a>.
1909</p>
1910
1911<p>
1912<em>Updating</em>:
1913Code using these functions must be rewritten to use
1914package <a href="/pkg/reflect/"><code>reflect</code></a>.
Andrew Gerrand43ad89d2014-07-25 10:28:39 +10001915The changes to <a href="//golang.org/change/2646dc956207">encoding/gob</a> and the <a href="//code.google.com/p/goprotobuf/source/detail?r=5340ad310031">protocol buffer library</a>
Russ Cox72f5a912012-02-19 18:04:38 -05001916may be helpful as examples.
1917</p>
1918
Gustavo Niemeyer805d6202012-01-25 23:11:25 -02001919<h3 id="url">The url package</h3>
1920
1921<p>
Gustavo Niemeyer7b504852012-01-26 00:59:50 -02001922In 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 -02001923were removed or replaced.
1924</p>
1925
1926<p>
Gustavo Niemeyer7b504852012-01-26 00:59:50 -02001927The <a href="/pkg/net/url/#URL.String"><code>String</code></a> method now
Gustavo Niemeyer805d6202012-01-25 23:11:25 -02001928predictably rebuilds an encoded URL string using all of <code>URL</code>'s
1929fields as necessary. The resulting string will also no longer have
1930passwords escaped.
1931</p>
1932
1933<p>
1934The <code>Raw</code> field has been removed. In most cases the <code>String</code>
1935method may be used in its place.
1936</p>
1937
1938<p>
1939The old <code>RawUserinfo</code> field is replaced by the <code>User</code>
Gustavo Niemeyer7b504852012-01-26 00:59:50 -02001940field, of type <a href="/pkg/net/url/#Userinfo"><code>*net.Userinfo</code></a>.
1941Values of this type may be created using the new <a href="/pkg/net/url/#User"><code>net.User</code></a>
1942and <a href="/pkg/net/url/#UserPassword"><code>net.UserPassword</code></a>
Gustavo Niemeyer805d6202012-01-25 23:11:25 -02001943functions. The <code>EscapeUserinfo</code> and <code>UnescapeUserinfo</code>
1944functions are also gone.
1945</p>
1946
1947<p>
1948The <code>RawAuthority</code> field has been removed. The same information is
1949available in the <code>Host</code> and <code>User</code> fields.
1950</p>
1951
1952<p>
1953The <code>RawPath</code> field and the <code>EncodedPath</code> method have
1954been removed. The path information in rooted URLs (with a slash following the
1955schema) is now available only in decoded form in the <code>Path</code> field.
1956Occasionally, the encoded data may be required to obtain information that
1957was lost in the decoding process. These cases must be handled by accessing
1958the data the URL was built from.
1959</p>
1960
1961<p>
1962URLs with non-rooted paths, such as <code>"mailto:dev@golang.org?subject=Hi"</code>,
1963are also handled differently. The <code>OpaquePath</code> boolean field has been
1964removed and a new <code>Opaque</code> string field introduced to hold the encoded
1965path for such URLs. In Go 1, the cited URL parses as:
1966</p>
1967
1968<pre>
1969 URL{
1970 Scheme: "mailto",
1971 Opaque: "dev@golang.org",
1972 RawQuery: "subject=Hi",
1973 }
1974</pre>
1975
1976<p>
Gustavo Niemeyer7b504852012-01-26 00:59:50 -02001977A new <a href="/pkg/net/url/#URL.RequestURI"><code>RequestURI</code></a> method was
Gustavo Niemeyer805d6202012-01-25 23:11:25 -02001978added to <code>URL</code>.
1979</p>
1980
1981<p>
David Symonds83427932012-02-16 15:56:03 +11001982The <code>ParseWithReference</code> function has been renamed to <code>ParseWithFragment</code>.
1983</p>
1984
1985<p>
Gustavo Niemeyer805d6202012-01-25 23:11:25 -02001986<em>Updating</em>:
1987Code that uses the old fields will fail to compile and must be updated by hand.
Rob Pike27836912012-02-04 07:49:51 +11001988The semantic changes make it difficult for the fix tool to update automatically.
Gustavo Niemeyer805d6202012-01-25 23:11:25 -02001989</p>
1990
Russ Cox1a0c8fe2012-02-19 13:32:55 -05001991<h2 id="cmd_go">The go command</h2>
1992
1993<p>
Andrew Gerrand70db2372012-03-08 16:09:49 +11001994Go 1 introduces the <a href="/cmd/go/">go command</a>, a tool for fetching,
1995building, and installing Go packages and commands. The <code>go</code> command
1996does away with makefiles, instead using Go source code to find dependencies and
1997determine build conditions. Most existing Go programs will no longer require
1998makefiles to be built.
1999</p>
2000
2001<p>
2002See <a href="/doc/code.html">How to Write Go Code</a> for a primer on the
2003<code>go</code> command and the <a href="/cmd/go/">go command documentation</a>
2004for the full details.
2005</p>
2006
2007<p>
2008<em>Updating</em>:
2009Projects that depend on the Go project's old makefile-based build
2010infrastructure (<code>Make.pkg</code>, <code>Make.cmd</code>, and so on) should
2011switch to using the <code>go</code> command for building Go code and, if
2012necessary, rewrite their makefiles to perform any auxiliary build tasks.
Russ Cox1a0c8fe2012-02-19 13:32:55 -05002013</p>
2014
2015<h2 id="cmd_cgo">The cgo command</h2>
2016
2017<p>
2018In Go 1, the <a href="/cmd/cgo">cgo command</a>
2019uses a different <code>_cgo_export.h</code>
2020file, which is generated for packages containing <code>//export</code> lines.
2021The <code>_cgo_export.h</code> file now begins with the C preamble comment,
2022so that exported function definitions can use types defined there.
2023This has the effect of compiling the preamble multiple times, so a
2024package using <code>//export</code> must not put function definitions
2025or variable initializations in the C preamble.
Rob Pikeb5a3bd52012-02-20 15:36:08 +11002026</p>
Rob Pikebab4dec2011-12-07 14:33:37 -08002027
2028<h2 id="releases">Packaged releases</h2>
2029
Rob Pikec5f695e2012-03-24 10:14:07 +11002030<p>
2031One of the most significant changes associated with Go 1 is the availability
2032of prepackaged, downloadable distributions.
2033They are available for many combinations of architecture and operating system
2034(including Windows) and the list will grow.
2035Installation details are described on the
2036<a href="/doc/install">Getting Started</a> page, while
2037the distributions themselves are listed on the
Matthew Dempsky6e55f7a2014-09-12 09:15:58 +10002038<a href="https://golang.org/dl/">downloads page</a>.