Rob Pike | bab4dec | 2011-12-07 14:33:37 -0800 | [diff] [blame] | 1 | <!-- Go 1 Release Notes --> |
Rob Pike | 9d59c40 | 2011-12-08 11:35:28 -0800 | [diff] [blame] | 2 | <!-- |
| 3 | DO NOT EDIT: created by |
| 4 | tmpltohtml go1.tmpl |
| 5 | --> |
| 6 | |
Rob Pike | bab4dec | 2011-12-07 14:33:37 -0800 | [diff] [blame] | 7 | |
| 8 | <h2 id="introduction">Introduction to Go 1</h2> |
| 9 | |
| 10 | <p> |
| 11 | For a full explanation of the motivation and design of Go 1, see XXX. |
| 12 | Here follows a summary. |
| 13 | </p> |
| 14 | |
| 15 | <p> |
Rob Pike | 2fa987b | 2011-12-07 16:11:17 -0800 | [diff] [blame] | 16 | Go 1 is intended to be a stable language and core library set that |
| 17 | will form a reliable foundation for people and organizations that |
| 18 | want to make a long-term commitment to developing in the Go programming |
| 19 | language. Go will continue to develop, but in a way that guarantees |
| 20 | code written to the Go 1 specification will continue to work. For |
| 21 | instance, Go 1 will be a supported platform on Google App Engine |
| 22 | for the next few years. Incompatible changes to the environment, |
| 23 | should they arise, will be done in a distinct version. |
Rob Pike | bab4dec | 2011-12-07 14:33:37 -0800 | [diff] [blame] | 24 | </p> |
| 25 | |
| 26 | <p> |
Rob Pike | 2fa987b | 2011-12-07 16:11:17 -0800 | [diff] [blame] | 27 | This document describes the changes in the language and libraries |
| 28 | in Go 1, relative to the previous release, r60 (at the time of |
| 29 | writing, tagged as r60.3). It also explains how to update code at |
| 30 | r60 to compile and run under Go 1. Finally, it outlines the new |
| 31 | <code>go</code> command for building Go programs and the new binary |
| 32 | release process being introduced. Most of these topics have more |
| 33 | thorough presentations elsewhere; such documents are linked below. |
Rob Pike | 136c04f | 2011-12-08 16:39:05 -0800 | [diff] [blame] | 34 | </p> |
Rob Pike | bab4dec | 2011-12-07 14:33:37 -0800 | [diff] [blame] | 35 | |
| 36 | <h2 id="language">Changes to the language</h2> |
| 37 | |
| 38 | <h3 id="append">Append</h3> |
| 39 | |
Rob Pike | 136c04f | 2011-12-08 16:39:05 -0800 | [diff] [blame] | 40 | <p> |
| 41 | The <code>append</code> built-in function is variadic, so one can |
| 42 | append to a byte slice using the <code>...</code> syntax in the |
| 43 | call. |
| 44 | </p> |
| 45 | |
| 46 | <pre><!--{{code "progs/go1.go" `/greeting := ..byte/` `/append.*hello/`}} |
| 47 | --> greeting := []byte{} |
| 48 | greeting = append(greeting, []byte("hello ")...) |
| 49 | </pre> |
| 50 | |
| 51 | <p> |
| 52 | By analogy with the similar property of <code>copy</code>, Go 1 |
| 53 | permits a string to be appended (byte-wise) directly to a byte |
| 54 | slice; the conversion is no longer necessary: |
| 55 | </p> |
| 56 | |
| 57 | <pre><!--{{code "progs/go1.go" `/append.*world/`}} |
| 58 | --> greeting = append(greeting, "world"...) |
| 59 | </pre> |
| 60 | |
| 61 | <p> |
| 62 | <em>Updating</em>: |
| 63 | This is a new feature, so existing code needs no changes. |
| 64 | </p> |
| 65 | |
Rob Pike | bab4dec | 2011-12-07 14:33:37 -0800 | [diff] [blame] | 66 | <h3 id="close">Close</h3> |
| 67 | |
Rob Pike | 136c04f | 2011-12-08 16:39:05 -0800 | [diff] [blame] | 68 | <p> |
| 69 | The <code>close</code> built-in function lets a sender tell a receiver |
| 70 | that no more data will be transmitted on the channel. In Go 1 the |
| 71 | type system enforces the directionality when possible: it is illegal |
| 72 | to call <code>close</code> on a receive-only channel: |
| 73 | </p> |
| 74 | |
| 75 | <pre> |
| 76 | var c chan int |
| 77 | var csend chan<- int = c |
| 78 | var crecv <-chan int = c |
| 79 | close(c) // legal |
| 80 | close(csend) // legal |
| 81 | close(crecv) // illegal |
| 82 | </pre> |
| 83 | |
| 84 | <p> |
| 85 | <em>Updating</em>: |
| 86 | Existing code that attempts to close a receive-only channel was |
| 87 | erroneous even before Go 1 and should be fixed. The compiler will |
| 88 | now reject such code. |
| 89 | </p> |
| 90 | |
Rob Pike | 9d59c40 | 2011-12-08 11:35:28 -0800 | [diff] [blame] | 91 | <h3 id="literals">Composite literals</h3> |
Rob Pike | bab4dec | 2011-12-07 14:33:37 -0800 | [diff] [blame] | 92 | |
Rob Pike | 2e338fa | 2011-12-09 08:31:57 -0800 | [diff] [blame] | 93 | <p> |
| 94 | In Go 1, a composite literal of array, slice, or map type can elide the |
| 95 | type specification for the elements' initializers if they are of pointer type. |
| 96 | All four of the initializations in this example are legal; the last one was illegal before Go 1. |
| 97 | </p> |
| 98 | |
| 99 | <pre><!--{{code "progs/go1.go" `/type Date struct/` `/STOP/`}} |
| 100 | --> type Date struct { |
| 101 | month string |
| 102 | day int |
| 103 | } |
| 104 | // Struct values, fully qualified; always legal. |
| 105 | holiday1 := []Date{ |
| 106 | Date{"Feb", 14}, |
| 107 | Date{"Nov", 11}, |
| 108 | Date{"Dec", 25}, |
| 109 | } |
| 110 | // Struct values, type name elided; always legal. |
| 111 | holiday2 := []Date{ |
| 112 | {"Feb", 14}, |
| 113 | {"Nov", 11}, |
| 114 | {"Dec", 25}, |
| 115 | } |
| 116 | // Pointers, fully qualified, always legal. |
| 117 | holiday3 := []*Date{ |
| 118 | &Date{"Feb", 14}, |
| 119 | &Date{"Nov", 11}, |
| 120 | &Date{"Dec", 25}, |
| 121 | } |
| 122 | // Pointers, type name elided; legal in Go 1. |
| 123 | holiday4 := []*Date{ |
| 124 | {"Feb", 14}, |
| 125 | {"Nov", 11}, |
| 126 | {"Dec", 25}, |
| 127 | } |
| 128 | </pre> |
| 129 | |
| 130 | <p> |
| 131 | <em>Updating</em>: |
| 132 | This change has no effect on existing code, but the command |
| 133 | <code>gofmt</code> <code>-s</code> applied to existing source |
| 134 | will, among other things, elide explicit element types wherever permitted. |
| 135 | </p> |
| 136 | |
| 137 | |
Rob Pike | 9d59c40 | 2011-12-08 11:35:28 -0800 | [diff] [blame] | 138 | <h3 id="init">Goroutines during init</h3> |
Rob Pike | bab4dec | 2011-12-07 14:33:37 -0800 | [diff] [blame] | 139 | |
Rob Pike | 136c04f | 2011-12-08 16:39:05 -0800 | [diff] [blame] | 140 | <p> |
| 141 | Go 1 allows goroutines to be created and run during initialization. |
| 142 | (They used to be created but were not run until after initialization |
| 143 | completed.) Code that uses goroutines can now be called from |
| 144 | <code>init</code> routines and global initialization expressions |
| 145 | without introducing a deadlock. |
| 146 | </p> |
| 147 | |
| 148 | <pre><!--{{code "progs/go1.go" `/PackageGlobal/` `/^}/`}} |
| 149 | -->var PackageGlobal int |
| 150 | |
| 151 | func init() { |
| 152 | c := make(chan int) |
| 153 | go initializationFunction(c) |
| 154 | PackageGlobal = <-c |
| 155 | } |
| 156 | </pre> |
| 157 | |
| 158 | <p> |
| 159 | <em>Updating</em>: |
| 160 | This is a new feature, so existing code needs no changes, |
| 161 | although it's possible that code that depends on goroutines not starting before <code>main</code> will break. |
| 162 | There was no such code in the standard repository. |
| 163 | </p> |
| 164 | |
Rob Pike | bab4dec | 2011-12-07 14:33:37 -0800 | [diff] [blame] | 165 | <h3 id="rune">The rune type</h3> |
| 166 | |
Rob Pike | 2e338fa | 2011-12-09 08:31:57 -0800 | [diff] [blame] | 167 | <p> |
| 168 | Go 1 introduces a new basic type, <code>rune</code>, to be used to represent |
| 169 | individual Unicode code points. |
| 170 | It is an alias for <code>int32</code>, analogous to <code>byte</code> |
| 171 | as an alias for <code>uint8</code>. |
| 172 | </p> |
| 173 | |
| 174 | <p> |
| 175 | Character literals such as <code>'a'</code>, <code>'語'</code>, and <code>'\u0345'</code> |
| 176 | now have default type <code>rune</code>, |
| 177 | analogous to <code>1.0</code> having default type <code>float64</code>. |
| 178 | A variable initialized to a character constant will therefore |
| 179 | have type <code>rune</code> unless otherwise specified. |
| 180 | </p> |
| 181 | |
| 182 | <p> |
| 183 | Libraries have been updated to use <code>rune</code> rather than <code>int</code> |
| 184 | when appropriate. For instance, the functions <code>unicode.ToLower</code> and |
| 185 | relatives now take and return a <code>rune</code>. |
| 186 | </p> |
| 187 | |
| 188 | <pre><!--{{code "progs/go1.go" `/STARTRUNE/` `/ENDRUNE/`}} |
| 189 | --> delta := 'δ' // delta has type rune. |
| 190 | var DELTA rune |
| 191 | DELTA = unicode.ToUpper(delta) |
| 192 | epsilon := unicode.ToLower(DELTA + 1) |
| 193 | if epsilon != 'δ'+1 { |
| 194 | log.Fatal("inconsistent casing for Greek") |
| 195 | } |
| 196 | </pre> |
| 197 | |
| 198 | <p> |
| 199 | <em>Updating</em>: |
| 200 | Most source code will be unaffected by this because the type inference from |
| 201 | <code>:=</code> initializers introduces the new type silently, and it propagates |
| 202 | from there. |
| 203 | Some code may get type errors that a trivial conversion will resolve. |
| 204 | </p> |
| 205 | |
| 206 | <h3 id="error">The error type</h3> |
| 207 | |
| 208 | <p> |
| 209 | Go 1 introduces a new built-in type, <code>error</code>, which has the following definition: |
| 210 | </p> |
| 211 | |
| 212 | <pre> |
| 213 | type error interface { |
| 214 | Error() string |
| 215 | } |
| 216 | </pre> |
| 217 | |
| 218 | <p> |
| 219 | Since the consequences of this type are all in the package library, |
| 220 | it is discussed <a href="errors">below</a>. |
| 221 | </p> |
| 222 | |
Rob Pike | 9d59c40 | 2011-12-08 11:35:28 -0800 | [diff] [blame] | 223 | <h3 id="delete">Deleting from maps</h3> |
Rob Pike | 2fa987b | 2011-12-07 16:11:17 -0800 | [diff] [blame] | 224 | |
| 225 | <p> |
| 226 | The original syntax for deleting an element in a map was: |
| 227 | </p> |
| 228 | |
| 229 | <pre> |
Rob Pike | 2e338fa | 2011-12-09 08:31:57 -0800 | [diff] [blame] | 230 | m[k] = ignored, false |
Rob Pike | 2fa987b | 2011-12-07 16:11:17 -0800 | [diff] [blame] | 231 | </pre> |
| 232 | |
| 233 | <p> |
Rob Pike | 9d59c40 | 2011-12-08 11:35:28 -0800 | [diff] [blame] | 234 | In Go 1, that syntax has gone; instead there is a new built-in |
Rob Pike | 2fa987b | 2011-12-07 16:11:17 -0800 | [diff] [blame] | 235 | function, <code>delete</code>. The call |
| 236 | </p> |
| 237 | |
| 238 | <pre><!--{{code "progs/go1.go" `/delete\(m, k\)/`}} |
| 239 | --> delete(m, k) |
| 240 | </pre> |
| 241 | |
| 242 | <p> |
| 243 | will delete the map entry retrieved by the expression <code>m[k]</code>. |
| 244 | There is no return value. Deleting a non-existent entry is a no-op. |
| 245 | </p> |
| 246 | |
| 247 | <p> |
| 248 | <em>Updating</em>: |
| 249 | Gofix will convert expressions of the form <code>m[k] = ignored, |
| 250 | false</code> into <code>delete(m, k)</code> when it is clear that |
| 251 | the ignored value can be safely discarded from the program and |
| 252 | <code>false</code> refers to the predefined boolean constant. Gofix |
| 253 | will flag other uses of the syntax for inspection by the programmer. |
| 254 | </p> |
| 255 | |
Rob Pike | 136c04f | 2011-12-08 16:39:05 -0800 | [diff] [blame] | 256 | <h3 id="iteration">Iterating in maps</h3> |
| 257 | |
| 258 | <p> |
| 259 | In Go 1, the order in which elements are visited when iterating |
| 260 | over a map using a <code>for</code> <code>range</code> statement |
| 261 | is defined to be unpredictable, even if the same loop is run multiple |
| 262 | times with the same map. |
| 263 | Code should not assume that the elements are visited in any particular order. |
| 264 | </p> |
| 265 | |
| 266 | <pre><!--{{code "progs/go1.go" `/Sunday/` `/^ }/`}} |
| 267 | --> m := map[string]int{"Sunday": 0, "Monday": 1} |
| 268 | for name, value := range m { |
| 269 | // This loop should not assume Sunday will be visited first. |
| 270 | f(name, value) |
| 271 | } |
| 272 | </pre> |
| 273 | |
| 274 | <p> |
| 275 | <em>Updating</em>: |
| 276 | This is one change where tools cannot help. Most existing code |
| 277 | will be unaffected, but some programs may break or misbehave; we |
| 278 | recommend manual checking of all range statements over maps to |
| 279 | verify they do not depend on iteration order. There were a few such |
| 280 | examples in the standard repository; they have been fixed. |
| 281 | Note that it was already incorrect to depend on the iteration order, which |
| 282 | was unspecified. This change codifies the unpredictability. |
| 283 | </p> |
Rob Pike | bab4dec | 2011-12-07 14:33:37 -0800 | [diff] [blame] | 284 | |
| 285 | <h3 id="multiple_assignment">Multiple assignment</h3> |
| 286 | |
Rob Pike | 136c04f | 2011-12-08 16:39:05 -0800 | [diff] [blame] | 287 | <p> |
| 288 | Go 1 fully specifies the evaluation order in multiple assignment |
| 289 | statements. In particular, if the left-hand side of the assignment |
| 290 | statement contains expressions that require evaluation, such as |
| 291 | function calls or array indexing operations, these will all be done |
| 292 | using the usual left-to-right rule before any variables are assigned |
| 293 | their value. Once everything is evaluated, the actual assignments |
| 294 | proceed in left-to-right order. |
| 295 | </p> |
| 296 | |
| 297 | <p> |
| 298 | These examples illustrate the behavior. |
| 299 | </p> |
| 300 | |
| 301 | <pre><!--{{code "progs/go1.go" `/sa :=/` `/then sc.0. = 2/`}} |
| 302 | --> sa := []int{1, 2, 3} |
| 303 | i := 0 |
| 304 | i, sa[i] = 1, 2 // sets i = 1, sa[0] = 2 |
| 305 | |
| 306 | sb := []int{1, 2, 3} |
| 307 | j := 0 |
| 308 | sb[j], j = 2, 1 // sets sb[0] = 2, j = 1 |
| 309 | |
| 310 | sc := []int{1, 2, 3} |
| 311 | sc[0], sc[0] = 1, 2 // sets sc[0] = 1, then sc[0] = 2 (so sc[0] = 2 at end) |
| 312 | </pre> |
| 313 | |
Rob Pike | 2e338fa | 2011-12-09 08:31:57 -0800 | [diff] [blame] | 314 | <p> |
Rob Pike | 136c04f | 2011-12-08 16:39:05 -0800 | [diff] [blame] | 315 | <em>Updating</em>: |
| 316 | This is one change where tools cannot help, but breakage is unlikely. |
| 317 | No code in the standard repository was broken by this change, and code |
| 318 | that depended on the previous unspecified behavior was already incorrect. |
| 319 | </p> |
| 320 | |
Rob Pike | bab4dec | 2011-12-07 14:33:37 -0800 | [diff] [blame] | 321 | <h3 id="shadowing">Returns and shadowed variables</h3> |
| 322 | |
Rob Pike | 136c04f | 2011-12-08 16:39:05 -0800 | [diff] [blame] | 323 | <p> |
| 324 | A shadowed variable is one that has the same name as another variable in an inner scope. |
| 325 | In functions with named return values, |
| 326 | the Go 1 compilers disallow return statements without arguments if any of the named return values is shadowed at the point of the return statement. |
| 327 | (It isn't part of the specification, because this is one area we are still exploring; |
| 328 | the situation is analogous to the compilers rejecting functions that do not end with an explicit return statement.) |
| 329 | </p> |
| 330 | |
| 331 | <p> |
| 332 | This function implicitly returns a shadowed return value and will be rejected by the compiler: |
| 333 | </p> |
| 334 | |
| 335 | <pre> |
| 336 | func Bug() (i, j, k int) { |
| 337 | for i = 0; i < 5; i++ { |
| 338 | for j := 0; j < 5; j++ { // Redeclares j. |
| 339 | k += i*j |
| 340 | if k > 100 { |
| 341 | return // Rejected: j is shadowed here. |
| 342 | } |
| 343 | } |
| 344 | } |
| 345 | return // OK: j is not shadowed here. |
| 346 | } |
| 347 | </pre> |
| 348 | |
| 349 | <p> |
| 350 | <em>Updating</em>: |
| 351 | Code that shadows return values in this way will be rejected by the compiler and will need to be fixed by hand. |
| 352 | The few cases that arose in the standard repository were mostly bugs. |
| 353 | </p> |
| 354 | |
| 355 | <h3 id="unexported">Copying structs with unexported fields</h3> |
| 356 | |
Rob Pike | 2e338fa | 2011-12-09 08:31:57 -0800 | [diff] [blame] | 357 | <p> |
| 358 | Go 1 relaxes the rules about accessing structs with unexported (lower-case) fields, |
| 359 | permitting a client package to assign (and therefore copy) such a struct. |
| 360 | Of course, the client package still cannot access such fields individually. |
| 361 | </p> |
| 362 | |
| 363 | <p> |
| 364 | As an example, if package <code>p</code> includes the definitions, |
| 365 | </p> |
| 366 | |
| 367 | <pre> |
| 368 | type Struct struct { |
| 369 | Public int |
| 370 | secret int |
| 371 | } |
| 372 | func NewStruct(a int) Struct { // Note: not a pointer. |
| 373 | return Struct{a, f(a)} |
| 374 | } |
| 375 | func (s Struct) String() string { |
| 376 | return fmt.Sprintf("{%d (secret %d)}", s.Public, s.secret) |
| 377 | } |
| 378 | </pre> |
| 379 | |
| 380 | <p> |
| 381 | a package that imports <code>p</code> can assign and copy values of type |
| 382 | <code>p.Struct</code> at will. |
| 383 | Behind the scenes the unexported fields will be assigned and copied just |
| 384 | as if they were exported, |
| 385 | but the client code will never be aware of them. The code |
| 386 | </p> |
| 387 | |
| 388 | <pre> |
| 389 | import "p" |
| 390 | |
| 391 | myStruct := p.NewStruct(23) |
| 392 | copyOfMyStruct := myStruct |
| 393 | fmt.Println(myStruct, copyOfMyStruct) |
| 394 | </pre> |
| 395 | |
| 396 | <p> |
| 397 | will show that the secret field of the struct has been copied to the new value. |
| 398 | </p> |
| 399 | |
| 400 | <p> |
| 401 | <em>Updating</em>: |
| 402 | This is a new feature, so existing code needs no changes. |
| 403 | </p> |
| 404 | |
Rob Pike | 9d59c40 | 2011-12-08 11:35:28 -0800 | [diff] [blame] | 405 | <h3 id="equality">Equality of structs and arrays</h3> |
Rob Pike | bab4dec | 2011-12-07 14:33:37 -0800 | [diff] [blame] | 406 | |
Rob Pike | 136c04f | 2011-12-08 16:39:05 -0800 | [diff] [blame] | 407 | <p> |
| 408 | Go 1 defines equality and inequality (<code>==</code> and |
| 409 | <code>!=</code>) for struct and array values, respectively, provided |
| 410 | the elements of the data structures can themselves be compared. |
| 411 | That is, if equality is defined for all the fields of a struct (or |
| 412 | an array element), then it is defined for the struct (or array). |
| 413 | </p> |
| 414 | |
| 415 | <p> |
| 416 | As a result, structs and arrays can now be used as map keys: |
| 417 | </p> |
| 418 | |
| 419 | <pre><!--{{code "progs/go1.go" `/type Day struct/` `/Printf/`}} |
| 420 | --> // type Day struct { |
| 421 | // long string |
| 422 | // short string |
| 423 | // } |
| 424 | // Christmas := Day{"Christmas", "XMas"} |
| 425 | // Thanksgiving := Day{"Thanksgiving", "Turkey"} |
| 426 | // holiday := map[Day]bool { |
| 427 | // Christmas: true, |
| 428 | // Thanksgiving: true, |
| 429 | // } |
| 430 | // fmt.Printf("Christmas is a holiday: %t\n", holiday[Christmas]) |
| 431 | </pre> |
| 432 | |
| 433 | <p> |
| 434 | Note that equality is still undefined for slices, for which the |
| 435 | calculation is in general infeasible. Also note that the ordered |
| 436 | comparison operators (<code><</code> <code><=</code> |
| 437 | <code>></code> <code>>=</code>) are still undefined for |
| 438 | structs and arrays. |
| 439 | |
| 440 | <p> |
| 441 | <em>Updating</em>: |
| 442 | This is a new feature, so existing code needs no changes. |
| 443 | </p> |
| 444 | |
| 445 | <h3 id="funcs">Function and map equality</h3> |
| 446 | |
| 447 | <p> |
| 448 | Go 1 disallows checking for equality of functions and maps, |
| 449 | respectively, except to compare them directly to <code>nil</code>. |
| 450 | </p> |
| 451 | |
| 452 | <p> |
| 453 | <em>Updating</em>: |
| 454 | Existing code that depends on function or map equality will be |
| 455 | rejected by the compiler and will need to be fixed by hand. |
| 456 | Few programs will be affected, but the fix may require some |
| 457 | redesign. |
| 458 | </p> |
| 459 | |
Rob Pike | bab4dec | 2011-12-07 14:33:37 -0800 | [diff] [blame] | 460 | <h2 id="library">Changes to the library</h2> |
| 461 | |
Rob Pike | 9d59c40 | 2011-12-08 11:35:28 -0800 | [diff] [blame] | 462 | <h3 id="hierarchy">The package hierarchy</h3> |
| 463 | |
| 464 | <p> |
| 465 | Go 1 has a rearranged package hierarchy that groups related items |
| 466 | into subdirectories. For instance, <code>utf8</code> and |
| 467 | <code>utf16</code> now occupy subdirectories of <code>unicode</code>. |
| 468 | Also, <a href="#subrepo">some packages</a> have moved into |
| 469 | subrepositories of |
| 470 | <a href="http://code.google.com/p/go"><code>code.google.com/p/go</code></a> |
| 471 | while <a href="#deleted">others</a> have been deleted outright. |
| 472 | </p> |
| 473 | |
| 474 | <table class="codetable" frame="border" summary="Moved packages"> |
| 475 | <colgroup align="left" width="60%"></colgroup> |
| 476 | <colgroup align="left" width="40%"></colgroup> |
| 477 | <tr> |
| 478 | <th align="left">Old path</th> |
| 479 | <th align="left">New path</th> |
| 480 | </tr> |
Rob Pike | 71ccf73 | 2011-12-09 14:12:51 -0800 | [diff] [blame] | 481 | <tr> |
| 482 | <td colspan="2"><hr></td> |
| 483 | </tr> |
Rob Pike | 136c04f | 2011-12-08 16:39:05 -0800 | [diff] [blame] | 484 | <tr><td>asn1</td> <td>encoding/asn1</td></tr> |
Rob Pike | 9d59c40 | 2011-12-08 11:35:28 -0800 | [diff] [blame] | 485 | <tr><td>csv</td> <td>encoding/csv</td></tr> |
| 486 | <tr><td>gob</td> <td>encoding/gob</td></tr> |
| 487 | <tr><td>json</td> <td>encoding/json</td></tr> |
| 488 | <tr><td>xml</td> <td>encoding/xml</td></tr> |
| 489 | <tr> |
| 490 | <td colspan="2"><hr></td> |
| 491 | </tr> |
| 492 | <tr><td>exp/template/html</td> <td>html/template</td></tr> |
| 493 | <tr> |
| 494 | <td colspan="2"><hr></td> |
| 495 | </tr> |
| 496 | <tr><td>big</td> <td>math/big</td></tr> |
| 497 | <tr><td>cmath</td> <td>math/cmplx</td></tr> |
| 498 | <tr><td>rand</td> <td>math/rand</td></tr> |
| 499 | <tr> |
| 500 | <td colspan="2"><hr></td> |
| 501 | </tr> |
| 502 | <tr><td>http</td> <td>net/http</td></tr> |
| 503 | <tr><td>http/cgi</td> <td>net/http/cgi</td></tr> |
| 504 | <tr><td>http/fcgi</td> <td>net/http/fcgi</td></tr> |
| 505 | <tr><td>http/httptest</td> <td>net/http/httptest</td></tr> |
| 506 | <tr><td>http/pprof</td> <td>net/http/pprof</td></tr> |
| 507 | <tr><td>mail</td> <td>net/mail</td></tr> |
| 508 | <tr><td>rpc</td> <td>net/rpc</td></tr> |
| 509 | <tr><td>rpc/jsonrpc</td> <td>net/rpc/jsonrpc</td></tr> |
| 510 | <tr><td>smtp</td> <td>net/smtp</td></tr> |
| 511 | <tr><td>url</td> <td>net/url</td></tr> |
| 512 | <tr> |
| 513 | <td colspan="2"><hr></td> |
| 514 | </tr> |
| 515 | <tr><td>exec</td> <td>os/exec</td></tr> |
| 516 | <tr> |
| 517 | <td colspan="2"><hr></td> |
| 518 | </tr> |
| 519 | <tr><td>scanner</td> <td>text/scanner</td></tr> |
| 520 | <tr><td>tabwriter</td> <td>text/tabwriter</td></tr> |
| 521 | <tr><td>template</td> <td>text/template</td></tr> |
| 522 | <tr><td>template/parse</td> <td>text/template/parse</td></tr> |
| 523 | <tr> |
| 524 | <td colspan="2"><hr></td> |
| 525 | </tr> |
| 526 | <tr><td>utf8</td> <td>unicode/utf8</td></tr> |
| 527 | <tr><td>utf16</td> <td>unicode/utf16</td></tr> |
| 528 | </table> |
| 529 | |
| 530 | <p> |
| 531 | Note that the package names for the old <code>cmath</code> and |
| 532 | <code>exp/template/html</code> packages have changed to <code>cmplx</code> |
| 533 | and <code>template</code>. |
| 534 | </p> |
| 535 | |
| 536 | <p> |
| 537 | <em>Updating</em>: |
| 538 | Gofix will update all imports and package renames for packages that |
| 539 | remain inside the standard repository. Programs that import packages |
| 540 | that are no longer in the standard repository will need to be edited |
| 541 | by hand. |
Rob Pike | 71ccf73 | 2011-12-09 14:12:51 -0800 | [diff] [blame] | 542 | <br> |
| 543 | <font color="red">TODO: gofix should warn about deletions.</font> |
| 544 | <br> |
| 545 | <font color="red">TODO: gofix should also handle packages that move to subrepos.</font> |
Rob Pike | 9d59c40 | 2011-12-08 11:35:28 -0800 | [diff] [blame] | 546 | </p> |
Rob Pike | bab4dec | 2011-12-07 14:33:37 -0800 | [diff] [blame] | 547 | |
Rob Pike | 71ccf73 | 2011-12-09 14:12:51 -0800 | [diff] [blame] | 548 | <h3 id="errors">The error type and errors package</h3> |
Rob Pike | bab4dec | 2011-12-07 14:33:37 -0800 | [diff] [blame] | 549 | |
Rob Pike | 9d59c40 | 2011-12-08 11:35:28 -0800 | [diff] [blame] | 550 | <h3 id="errno">System call errors</h3> |
Rob Pike | bab4dec | 2011-12-07 14:33:37 -0800 | [diff] [blame] | 551 | |
Rob Pike | 71ccf73 | 2011-12-09 14:12:51 -0800 | [diff] [blame] | 552 | <p> |
| 553 | In Go 1, the |
| 554 | <a href="http://golang.org/pkg/syscall"><code>syscall</code></a> |
| 555 | package returns an <code>error</code> for system call errors, |
| 556 | rather than plain integer <code>errno</code> values. |
| 557 | On Unix, the implementation is done by a |
| 558 | <a href="http://golang.org/pkg/syscall/#Errno"><code>syscall.Errno</code></a> type |
| 559 | that satisfies <code>error</code> and replaces the old <code>os.Errno</code>. |
| 560 | </p> |
| 561 | |
| 562 | <p> |
| 563 | <em>Updating</em>: |
| 564 | Gofix will update almost all code affected by the change. |
| 565 | Regardless, most code should use the <code>os</code> package |
| 566 | rather than <code>syscall</code> and so will be unaffected. |
| 567 | </p> |
| 568 | |
Rob Pike | bab4dec | 2011-12-07 14:33:37 -0800 | [diff] [blame] | 569 | <h3 id="time">Time</h3> |
| 570 | |
| 571 | <h3 id="html">The html package</h3> |
| 572 | |
| 573 | <h3 id="http">The http package</h3> |
| 574 | |
| 575 | <h3 id="strconv">The strconv package</h3> |
| 576 | |
Rob Pike | 71ccf73 | 2011-12-09 14:12:51 -0800 | [diff] [blame] | 577 | <p> |
| 578 | In Go 1, the |
| 579 | <a href="http://golang.org/pkg/syscall"><code>strconv</code></a> |
| 580 | package has been significantly reworked to make it more Go-like and less C-like, |
| 581 | although <code>Atoi</code> lives on (it's similar to |
| 582 | <code>int(ParseInt(x, 10, 0))</code>, as does |
| 583 | <code>Itoa(x)</code> (<code>FormatInt(int64(x), 10)</code>). |
| 584 | There are also new variants of some of the functions that append to byte slices rather than |
| 585 | return strings, to allow control over allocation. |
| 586 | </p> |
| 587 | |
| 588 | <p> |
| 589 | This table summarizes the renamings; see the |
| 590 | <a href="/pkg/strconv">package documentation</a> |
| 591 | for full details. |
| 592 | </p> |
| 593 | |
| 594 | <table class="codetable" frame="border" summary="strconv renames"> |
| 595 | <colgroup align="left" width="50%"></colgroup> |
| 596 | <colgroup align="left" width="50%"></colgroup> |
| 597 | <tr> |
| 598 | <th align="left">Old call</th> |
| 599 | <th align="left">New call</th> |
| 600 | </tr> |
| 601 | <tr> |
| 602 | <td colspan="2"><hr></td> |
| 603 | </tr> |
| 604 | <tr><td>Atob(x)</td> <td>ParseBool(x)</td></tr> |
| 605 | <tr> |
| 606 | <td colspan="2"><hr></td> |
| 607 | </tr> |
| 608 | <tr><td>Atof32(x)</td> <td>ParseFloat(x, 32)§</td></tr> |
| 609 | <tr><td>Atof64(x)</td> <td>ParseFloat(x, 64)</td></tr> |
| 610 | <tr><td>AtofN(x, n)</td> <td>ParseFloat(x, n)</td></tr> |
| 611 | <tr> |
| 612 | <td colspan="2"><hr></td> |
| 613 | </tr> |
| 614 | <tr><td>Atoi(x)</td> <td>Atoi(x)</td></tr> |
| 615 | <tr><td>Atoi(x)</td> <td>ParseInt(x, 10, 0)§</td></tr> |
| 616 | <tr><td>Atoi64(x)</td> <td>ParseInt(x, 10, 64)</td></tr> |
| 617 | <tr> |
| 618 | <td colspan="2"><hr></td> |
| 619 | </tr> |
| 620 | <tr><td>Atoui(x)</td> <td>ParseUint(x, 10, 0)§</td></tr> |
| 621 | <tr><td>Atoi64(x)</td> <td>ParseInt(x, 10, 64)</td></tr> |
| 622 | <tr> |
| 623 | <td colspan="2"><hr></td> |
| 624 | </tr> |
| 625 | <tr><td>Btoi64(x, b)</td> <td>ParseInt(x, b, 64)</td></tr> |
| 626 | <tr><td>Btoui64(x, b)</td> <td>ParseUint(x, b, 64)</td></tr> |
| 627 | <tr> |
| 628 | <td colspan="2"><hr></td> |
| 629 | </tr> |
| 630 | <tr><td>Btoa(x)</td> <td>FormatBool(x)</td></tr> |
| 631 | <tr> |
| 632 | <td colspan="2"><hr></td> |
| 633 | </tr> |
| 634 | <tr><td>Ftoa32(x, f, p)</td> <td>FormatFloat(x, float64(f), p, 32)</td></tr> |
| 635 | <tr><td>Ftoa64(x, f, p)</td> <td>FormatFloat(x, f, p, 64)</td></tr> |
| 636 | <tr><td>FtoaN(x, f, p, n)</td> <td>FormatFloat(x, f, p, n)</td></tr> |
| 637 | <tr> |
| 638 | <td colspan="2"><hr></td> |
| 639 | </tr> |
| 640 | <tr><td>Itoa(x)</td> <td>Itoa(x)</td></tr> |
| 641 | <tr><td>Itoa(x)</td> <td>FormatInt(int64(x), 10)</td></tr> |
| 642 | <tr><td>Itoa64(x)</td> <td>FormatInt(x, 10)</td></tr> |
| 643 | <tr> |
| 644 | <td colspan="2"><hr></td> |
| 645 | </tr> |
| 646 | <tr><td>Itob(x, b)</td> <td>FormatInt(int64(x), b)</td></tr> |
| 647 | <tr><td>Itob64(x, b)</td> <td>FormatInt(x, b)</td></tr> |
| 648 | <tr> |
| 649 | <td colspan="2"><hr></td> |
| 650 | </tr> |
| 651 | <tr><td>Uitoa(x)</td> <td>FormatUint(uint64(x), 10)</td></tr> |
| 652 | <tr><td>Uitoa64(x)</td> <td>FormatUint(x, 10)</td></tr> |
| 653 | <tr> |
| 654 | <td colspan="2"><hr></td> |
| 655 | </tr> |
| 656 | <tr><td>Uitob(x, b)</td> <td>FormatUint(uint64(x), b)</td></tr> |
| 657 | <tr><td>Uitob64(x, b)</td> <td>FormatUint(x, b)</td></tr> |
| 658 | </table> |
| 659 | |
| 660 | <p> |
| 661 | <em>Updating</em>: |
| 662 | Gofix will update almost all code affected by the change. |
| 663 | <br> |
| 664 | § <code>Atoi</code> persists but <code>Atoui</code> and <code>Atof32</code> do not, so |
| 665 | they may require |
| 666 | a cast that must be added by hand; gofix will warn about it. |
| 667 | </p> |
| 668 | |
Rob Pike | bab4dec | 2011-12-07 14:33:37 -0800 | [diff] [blame] | 669 | <h3 id="exp">The package tree exp</h3> |
| 670 | |
| 671 | <h3 id="old">The package tree old</h3> |
| 672 | |
Rob Pike | 9d59c40 | 2011-12-08 11:35:28 -0800 | [diff] [blame] | 673 | <h3 id="deleted">Deleted packages</h3> |
Rob Pike | bab4dec | 2011-12-07 14:33:37 -0800 | [diff] [blame] | 674 | |
| 675 | <!-- |
Rob Pike | 9d59c40 | 2011-12-08 11:35:28 -0800 | [diff] [blame] | 676 | |
| 677 | moving to exp/* (and thus not in Go 1): |
| 678 | ebnf, command ebnflint |
| 679 | go/types, command gotype |
| 680 | http/spdy |
| 681 | |
| 682 | deleted: |
| 683 | container/vector |
| 684 | exp/datafmt |
| 685 | go/typechecker |
| 686 | try, command gotry |
| 687 | |
Rob Pike | bab4dec | 2011-12-07 14:33:37 -0800 | [diff] [blame] | 688 | go/typechecker |
| 689 | go/types |
| 690 | ebnf (and cmd/ebnflint) |
| 691 | container/vector |
| 692 | try (and gotry) |
| 693 | exp/datafmt |
| 694 | netchan |
| 695 | --> |
| 696 | |
Rob Pike | 9d59c40 | 2011-12-08 11:35:28 -0800 | [diff] [blame] | 697 | <h3 id="subrepo">Packages moving to subrepositories</h3> |
Rob Pike | bab4dec | 2011-12-07 14:33:37 -0800 | [diff] [blame] | 698 | |
| 699 | <!-- |
| 700 | crypto/openpgp to XXX |
| 701 | maybe exp/ssh? |
| 702 | --> |
| 703 | |
| 704 | <h3 id="os_fileinfo">The os.FileInfo type</h3> |
| 705 | |
| 706 | <h2 id="go_command">The go command</h2> |
| 707 | |
| 708 | <h2 id="releases">Packaged releases</h2> |
| 709 | |