From ebdcbf1cdc3309c6cd234d93ae033937ce89a1fb Mon Sep 17 00:00:00 2001
From: Rob Pike
Since the consequences of this type are all in the package library,
-it is discussed below.
+it is discussed below.
+As mentioned above, Go 1 introduces a new built-in interface type called
+The
+All standard packages have been updated to use the new interface; the old
+A new package,
+to turn a string into an error. It replaces the old
+Updating:
+Gofix will update almost all code affected by the change.
+Code that defines error types with a
In Go 1, the
-
In Go 1, the
-
This table summarizes the renamings; see the
-package documentation
+package documentation
for full details.
error
, which has the following
Deleting from maps
@@ -547,15 +547,73 @@ by hand.
The error type and errors package
+error
.
+Its intent is to replace the old os.Error
type with a more central concept.
+So the widely-used String
method does not cause accidental satisfaction
+of the error
interface, the error
interface uses instead
+the name Error
for that method:
+
+ type error interface {
+ Error() string
+ }
+
+
+fmt
library automatically invokes Error
, as it already
+does for String
, for easy printing of error values.
+type SyntaxError struct {
+ File string
+ Line int
+ Message string
+}
+
+func (se *SyntaxError) Error() string {
+ return fmt.Sprintf("%s:%d: %s", se.File, se.Line, se.Message)
+}
+
+
+os.Error
is gone.
+errors
, contains the function
+
+func New(text string) error
+
+
+os.NewError
.
+ var ErrSyntax = errors.New("syntax error")
+
+
+String
method will need to be updated
+by hand to rename the methods to Error
.
+System call errors
syscall
+syscall
package returns an error
for system call errors,
rather than plain integer errno
values.
On Unix, the implementation is done by a
-syscall.Errno
type
+syscall.Errno
type
that satisfies error
and replaces the old os.Errno
.
syscall
and so will be unaffected.
Time
-The html package
-
The http package
The strconv package
strconv
+strconv
package has been significantly reworked to make it more Go-like and less C-like,
although Atoi
lives on (it's similar to
int(ParseInt(x, 10, 0))
, as does
@@ -587,7 +643,7 @@ return strings, to allow control over allocation.
+Because they are not standardized, the packages under the exp
directory will not be available in the
+standard Go 1 release distributions, although they will be available in source code form
+in the repository for
+developers who wish to use them.
+
+Several packages have moved under exp
at the time of Go 1's release:
+
ebnf
go/types
http/spdy
+All these packages are available under the same names, with exp/
prefixed: exp/ebnf
etc.
+
+Also, the gotype
command now resides in exp/gotype
, while
+ebnflint
is now in exp/ebnflint
+
+Updating:
+Code that uses packages in exp
will need to be updated by hand,
+or else compiled from an installation that has exp
available.
+Gofix will warn about such uses.
+
+TODO: gofix should warn about such uses.
+
+Because they are deprecated, the packages under the old
directory will not be available in the
+standard Go 1 release distributions, although they will be available in source code form for
+developers who wish to use them.
+
+The packages in their new locations are: +
+ +old/netchan
old/regexp
old/template
+Updating:
+Code that uses packages now in old
will need to be updated by hand,
+or else compiled from an installation that has old
available.
+Gofix will warn about such uses.
+
+TODO: gofix should warn about such uses.
+
+and also the command gotry
.
+
+Updating:
+Code that uses container/vector
should be updated to use
+slices directly. See
+the Go
+Language Community Wiki for some suggestions.
+Code that uses the other packages (there should be almost zero) will need to be rethought.
+
+TODO: gofix should warn such uses.
+
error
, which has the following
Since the consequences of this type are all in the package library, -it is discussed below. +it is discussed below.
+As mentioned above, Go 1 introduces a new built-in interface type called error
.
+Its intent is to replace the old os.Error
type with a more central concept.
+So the widely-used String
method does not cause accidental satisfaction
+of the error
interface, the error
interface uses instead
+the name Error
for that method:
+
+ type error interface { + Error() string + } ++ +
+The fmt
library automatically invokes Error
, as it already
+does for String
, for easy printing of error values.
+
+All standard packages have been updated to use the new interface; the old os.Error
is gone.
+
+A new package, errors
, contains the function
+
+func New(text string) error ++ +
+to turn a string into an error. It replaces the old os.NewError
.
+
+Updating:
+Gofix will update almost all code affected by the change.
+Code that defines error types with a String
method will need to be updated
+by hand to rename the methods to Error
.
+
In Go 1, the
-syscall
+syscall
package returns an error
for system call errors,
rather than plain integer errno
values.
On Unix, the implementation is done by a
-syscall.Errno
type
+syscall.Errno
type
that satisfies error
and replaces the old os.Errno
.
syscall
and so will be unaffected.
In Go 1, the
-strconv
+strconv
package has been significantly reworked to make it more Go-like and less C-like,
although Atoi
lives on (it's similar to
int(ParseInt(x, 10, 0))
, as does
@@ -502,7 +546,7 @@ return strings, to allow control over allocation.
This table summarizes the renamings; see the -package documentation +package documentation for full details.
@@ -581,33 +625,99 @@ they may require a cast that must be added by hand; gofix will warn about it. +
+Because they are not standardized, the packages under the exp
directory will not be available in the
+standard Go 1 release distributions, although they will be available in source code form
+in the repository for
+developers who wish to use them.
+
+Several packages have moved under exp
at the time of Go 1's release:
+
ebnf
go/types
http/spdy
+All these packages are available under the same names, with exp/
prefixed: exp/ebnf
etc.
+
+Also, the gotype
command now resides in exp/gotype
, while
+ebnflint
is now in exp/ebnflint
+
+Updating:
+Code that uses packages in exp
will need to be updated by hand,
+or else compiled from an installation that has exp
available.
+Gofix will warn about such uses.
+
+TODO: gofix should warn about such uses.
+
+Because they are deprecated, the packages under the old
directory will not be available in the
+standard Go 1 release distributions, although they will be available in source code form for
+developers who wish to use them.
+
+The packages in their new locations are: +
+ +old/netchan
old/regexp
old/template
+Updating:
+Code that uses packages now in old
will need to be updated by hand,
+or else compiled from an installation that has old
available.
+Gofix will warn about such uses.
+
+TODO: gofix should warn about such uses.
+
+and also the command gotry
.
+
+Updating:
+Code that uses container/vector
should be updated to use
+slices directly. See
+the Go
+Language Community Wiki for some suggestions.
+Code that uses the other packages (there should be almost zero) will need to be rethought.
+
+TODO: gofix should warn such uses.
+