Lines Matching full:code
25 Code that compiles in Go 1 should, with few exceptions, continue to compile and
42 for old programs. Fortunately, the <code>go</code> <code>fix</code> tool can
48 updating existing code; its reference point is the prior release, r60 (tagged as
49 r60.3). It also explains how to update code from r60 to run under Go 1.
57 The <code>append</code> predeclared variadic function makes it easy to grow a slice
60 However, <code>append</code> did not provide a way to append a string to a <code>[]byte</code>,
64 {{code "/doc/progs/go1.go" `/greeting := ..byte/` `/append.*hello/`}}
67 By analogy with the similar property of <code>copy</code>, Go 1
73 {{code "/doc/progs/go1.go" `/append.*world/`}}
77 This is a new feature, so existing code needs no changes.
83 The <code>close</code> predeclared function provides a mechanism
85 It is important to the implementation of <code>for</code> <code>range</code>
90 However, before Go 1 there was no compile-time checking that <code>close</code>
95 To close this gap, at least in part, Go 1 disallows <code>close</code> on receive-only channels.
110 Existing code that attempts to close a receive-only channel was
112 now reject such code.
123 {{code "/doc/progs/go1.go" `/type Date struct/` `/STOP/`}}
127 This change has no effect on existing code, but the command
128 <code>gofmt</code> <code>-s</code> applied to existing source
136 The 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.
138 of the <code>init</code> construct:
147 In Go 1, code that uses goroutines can be called from
148 <code>init</code> routines and global initialization expressions
152 {{code "/doc/progs/go1.go" `/PackageGlobal/` `/^}/`}}
156 This is a new feature, so existing code needs no changes,
157 although it's possible that code that depends on goroutines not starting before <code>main</code> will break.
158 There was no such code in the standard repository.
164 The 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.
165 It would be preferable to have <code>int</code> be 64 bits on 64-bit platforms.
168 the 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.
172 To make changing to 64-bit <code>int</code> feasible,
173 Go 1 introduces a new basic type, <code>rune</code>, to represent
174 individual Unicode code points.
175 It is an alias for <code>int32</code>, analogous to <code>byte</code>
176 as an alias for <code>uint8</code>.
180 Character literals such as <code>'a'</code>, <code>'?'</code>, and <code>'\u0345'</code>
181 now have default type <code>rune</code>,
182 analogous to <code>1.0</code> having default type <code>float64</code>.
184 have type <code>rune</code> unless otherwise specified.
188 Libraries have been updated to use <code>rune</code> rather than <code>int</code>
189 when appropriate. For instance, the functions <code>unicode.ToLower</code> and
190 relatives now take and return a <code>rune</code>.
193 {{code "/doc/progs/go1.go" `/STARTRUNE/` `/ENDRUNE/`}}
197 Most source code will be unaffected by this because the type inference from
198 <code>:=</code> initializers introduces the new type silently, and it propagates
200 Some code may get type errors that a trivial conversion will resolve.
206 Go 1 introduces a new built-in type, <code>error</code>, which has the following definition:
223 In the old language, to delete the entry with key <code>k</code> from map <code>m</code>, one wrote the statement,
233 plus a boolean that was nearly always the constant <code>false</code>.
239 function, <code>delete</code>. The call
242 {{code "/doc/progs/go1.go" `/delete\(m, k\)/`}}
245 will delete the map entry retrieved by the expression <code>m[k]</code>.
251 Running <code>go</code> <code>fix</code> will convert expressions of the form <code>m[k] = value,
252 false</code> into <code>delete(m, k)</code> when it is clear that
254 <code>false</code> refers to the predefined boolean constant.
270 over a map using a <code>for</code> <code>range</code> statement
273 Code should not assume that the elements are visited in any particular order.
277 This change means that code that depends on iteration order is very likely to break early and be fixed long before it becomes a problem.
281 {{code "/doc/progs/go1.go" `/Sunday/` `/^ }/`}}
285 This is one change where tools cannot help. Most existing code
316 {{code "/doc/progs/go1.go" `/sa :=/` `/then sc.0. = 2/`}}
321 No code in the standard repository was broken by this change, and code
328 A 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.
359 Code that shadows return values in this way will be rejected by the compiler and will need to be fixed by hand.
368 also, the implementations of <code>copy</code> and <code>append</code> have never honored the restriction.
375 The new implementations of <code>time.Time</code> and
376 <code>reflect.Value</code> are examples of types taking advantage of this new property.
380 As an example, if package <code>p</code> includes the definitions,
397 a package that imports <code>p</code> can assign and copy values of type
398 <code>p.Struct</code> at will.
401 but the client code will never be aware of them. The code
418 This is a new feature, so existing code needs no changes.
437 (<code>==</code> and <code>!=</code>),
443 {{code "/doc/progs/go1.go" `/type Day struct/` `/Printf/`}}
447 except for comparison with <code>nil</code>.
448 Finally, map equality is gone too, also except for comparison with <code>nil</code>.
454 comparison operators (<code><</code> <code><=</code>
455 <code>></code> <code>>=</code>) are still undefined for
460 Struct and array equality is a new feature, so existing code needs no changes.
461 code that depends on function or map equality will be
485 into subdirectories. For instance, <code>utf8</code> and
486 <code>utf16</code> now occupy subdirectories of <code>unicode</code>.
489 <a href="//code.google.com/p/go"><code>code.google.com/p/go</code></a>
550 Note that the package names for the old <code>cmath</code> and
551 <code>exp/template/html</code> packages have changed to <code>cmplx</code>
552 and <code>template</code>.
557 Running <code>go</code> <code>fix</code> will update all imports and package renames for packages that
566 Because they are not standardized, the packages under the <code>exp</code> directory will not be available in the
567 standard Go 1 release distributions, although they will be available in source code form
568 in <a href="//code.google.com/p/go/">the repository</a> for
573 Several packages have moved under <code>exp</code> at the time of Go 1's release:
577 <li><code>ebnf</code></li>
578 <li><code>html</code><sup>†</sup></li>
579 <li><code>go/types</code></li>
583 (<sup>†</sup>The <code>EscapeString</code> and <code>UnescapeString</code> types remain
584 in package <code>html</code>.)
588 All these packages are available under the same names, with the prefix <code>exp/</code>: <code>exp/ebnf</code> etc.
592 Also, the <code>utf8.String</code> type has been moved to its own package, <code>exp/utf8string</code>.
596 Finally, the <code>gotype</code> command now resides in <code>exp/gotype</code>, while
597 <code>ebnflint</code> is now in <code>exp/ebnflint</code>.
598 If they are installed, they now reside in <code>$GOROOT/bin/tool</code>.
603 Code that uses packages in <code>exp</code> will need to be updated by hand,
604 or else compiled from an installation that has <code>exp</code> available.
605 The <code>go</code> <code>fix</code> tool or the compiler will complain about such uses.
611 Because they are deprecated, the packages under the <code>old</code> directory will not be available in the
612 standard Go 1 release distributions, although they will be available in source code form for
621 <li><code>old/netchan</code></li>
626 Code that uses packages now in <code>old</code> will need to be updated by hand,
627 or else compiled from an installation that has <code>old</code> available.
628 The <code>go</code> <code>fix</code> tool will warn about such uses.
638 <li><code>container/vector</code></li>
639 <li><code>exp/datafmt</code></li>
640 <li><code>go/typechecker</code></li>
641 <li><code>old/regexp</code></li>
642 <li><code>old/template</code></li>
643 <li><code>try</code></li>
647 and also the command <code>gotry</code>.
652 Code that uses <code>container/vector</code> should be updated to use
654 <a href="//code.google.com/p/go-wiki/wiki/SliceTricks">the Go
656 Code that uses the other packages (there should be almost zero) will need to be rethought.
663 <a href="//code.google.com/p/go/">the main Go repository</a>.
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>
694 <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>
699 <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>
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>
710 <tr><td>exp/wingui</td> <td>code.google.com/p/gowingui</tr>
715 Running <code>go</code> <code>fix</code> will update imports of these packages to use the new import paths.
717 a <code>go get</code> command.
730 The 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.
731 Since 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>.
732 Also, having <code>Error</code> in <code>os</code> introduces many dependencies on <code>os</code> that would otherwise not exist.
736 Go 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.
737 It replaces <code>os.NewError</code> with
738 <a href="/pkg/errors/#New"><code>errors.New</code></a>,
743 So the widely-used <code>String</code> method does not cause accidental satisfaction
744 of the <code>error</code> interface, the <code>error</code> interface uses instead
745 the name <code>Error</code> for that method:
755 The <code>fmt</code> library automatically invokes <code>Error</code>, as it already
756 does for <code>String</code>, for easy printing of error values.
759 {{code "/doc/progs/go1.go" `/START ERROR EXAMPLE/` `/END ERROR EXAMPLE/`}}
762 All standard packages have been updated to use the new interface; the old <code>os.Error</code> is gone.
766 A new package, <a href="/pkg/errors/"><code>errors</code></a>, contains the function
774 to turn a string into an error. It replaces the old <code>os.NewError</code>.
777 {{code "/doc/progs/go1.go" `/ErrSyntax/`}}
781 Running <code>go</code> <code>fix</code> will update almost all code affected by the change.
782 Code that defines error types with a <code>String</code> method will need to be updated
783 by hand to rename the methods to <code>Error</code>.
789 The old <code>syscall</code> package, which predated <code>os.Error</code>
791 returned errors as <code>int</code> values.
792 In turn, the <code>os</code> package forwarded many of these errors, such
793 as <code>EINVAL</code>, but using a different set of errors on each platform.
799 <a href="/pkg/syscall/"><code>syscall</code></a>
800 package instead returns an <code>error</code> for system call errors.
802 <a href="/pkg/syscall/#Errno"><code>syscall.Errno</code></a> type
803 that satisfies <code>error</code> and replaces the old <code>os.Errno</code>.
807 The changes affecting <code>os.EINVAL</code> and relatives are
812 Running <code>go</code> <code>fix</code> will update almost all code affected by the change.
813 Regardless, most code should use the <code>os</code> package
814 rather than <code>syscall</code> and so will be unaffected.
821 The old Go <code>time</code> package had <code>int64</code> units, no
829 <a href="/pkg/time/"><code>time</code></a> package.
830 Instead of an integer number of nanoseconds as an <code>int64</code>,
831 and a separate <code>*time.Time</code> type to deal with human
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;
836 and <a href="/pkg/time/#Duration"><code>time.Duration</code></a>,
839 A <code>Time</code> can represent any time into the ancient
840 past and remote future, while a <code>Duration</code> can
843 predefined constant durations such as <code>time.Second</code>.
848 <a href="/pkg/time/#Time.Add"><code>Time.Add</code></a>,
849 which adds a <code>Duration</code> to a <code>Time</code>, and
850 <a href="/pkg/time/#Time.Sub"><code>Time.Sub</code></a>,
851 which subtracts two <code>Times</code> to yield a <code>Duration</code>.
857 <a href="/pkg/time/#Unix"><code>time.Unix</code></a>
858 and the <a href="/pkg/time/#Time.Unix"><code>Unix</code></a>
859 and <a href="/pkg/time/#Time.UnixNano"><code>UnixNano</code></a> methods
860 of the <code>Time</code> type.
862 <a href="/pkg/time/#Now"><code>time.Now</code></a>
863 returns a <code>time.Time</code> value rather than, in the old
867 {{code "/doc/progs/go1.go" `/sleepUntil/` `/^}/`}}
871 all the standard packages that use time, such as <code>os</code> and
877 The <code>go</code> <code>fix</code> tool will update many uses of the old <code>time</code> package to use the new
878 types and methods, although it does not replace values such as <code>1e9</code>
892 few programs beyond the need to run <code>go</code> <code>fix</code>.
901 In Go 1, <a href="/pkg/archive/zip/#Writer"><code>*zip.Writer</code></a> no
902 longer has a <code>Write</code> method. Its presence was a mistake.
907 What little code is affected will be caught by the compiler and must be updated by hand.
913 In Go 1, <a href="/pkg/bufio/#NewReaderSize"><code>bufio.NewReaderSize</code></a>
915 <a href="/pkg/bufio/#NewWriterSize"><code>bufio.NewWriterSize</code></a>
922 Running <code>go</code> <code>fix</code> will update calls that assign the error to _.
929 In 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>
933 all return <codecode> if they take a compression level,
934 and <code>*Writer</code> otherwise. Package <code>gzip</code>'s
935 <code>Compressor</code> and <code>Decompressor</code> types have been renamed
936 to <code>Writer</code> and <code>Reader</code>. Package <code>flate</code>'s
937 <code>WrongValueError</code> type has been removed.
942 Running <code>go</code> <code>fix</code> will update old names and calls that assign the error to _.
949 In Go 1, the <code>Reset</code> method has been removed. Go does not guarantee
954 The cipher-specific types <code>*aes.Cipher</code>, <code>*des.Cipher</code>,
955 and <code>*des.TripleDESCipher</code> have been removed in favor of
956 <code>cipher.Block</code>.
968 In Go 1, <a href="/pkg/crypto/elliptic/#Curve"><code>elliptic.Curve</code></a>
971 <a href="/pkg/crypto/elliptic/#CurveParams"><code>elliptic.CurveParams</code></a>
977 Existing users of <code>*elliptic.Curve</code> will need to change to
978 simply <code>elliptic.Curve</code>. Calls to <code>Marshal</code>,
979 <code>Unmarshal</code> and <code>GenerateKey</code> are now functions
980 in <code>crypto/elliptic</code> that take an <code>elliptic.Curve</code>
987 In Go 1, the hash-specific functions, such as <code>hmac.NewMD5</code>, have
988 been removed from <code>crypto/hmac</code>. Instead, <code>hmac.New</code> takes
989 a function that returns a <code>hash.Hash</code>, such as <code>md5.New</code>.
994 Running <code>go</code> <code>fix</code> will perform the needed changes.
1001 <a href="/pkg/crypto/x509/#CreateCertificate"><code>CreateCertificate</code></a>
1003 <a href="/pkg/crypto/x509/#Certificate.CreateCRL"><code>CreateCRL</code></a>
1004 method in <code>crypto/x509</code> have been altered to take an
1005 <code>interface{}</code> where they previously took a <code>*rsa.PublicKey</code>
1006 or <code>*rsa.PrivateKey</code>. This will allow other public key algorithms
1018 In Go 1, the <code>binary.TotalSize</code> function has been replaced by
1019 <a href="/pkg/encoding/binary/#Size"><code>Size</code></a>,
1020 which takes an <code>interface{}</code> argument rather than
1021 a <code>reflect.Value</code>.
1026 What little code is affected will be caught by the compiler and must be updated by hand.
1032 In Go 1, the <a href="/pkg/encoding/xml/"><code>xml</code></a> package
1034 as <a href="/pkg/encoding/gob/"><code>encoding/gob</code></a>.
1038 The 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
1041 <a href="/pkg/encoding/xml/#Encoder"><code>Encoder</code></a> type was also introduced.
1045 The functions <a href="/pkg/encoding/xml/#Marshal"><code>Marshal</code></a>
1046 and <a href="/pkg/encoding/xml/#Unmarshal"><code>Unmarshal</code></a>
1047 work with <code>[]byte</code> values now. To work with streams,
1048 use the new <a href="/pkg/encoding/xml/#Encoder"><code>Encoder</code></a>
1049 and <a href="/pkg/encoding/xml/#Decoder"><code>Decoder</code></a> types.
1055 <a href="/pkg/encoding/json"><code>json</code></a> package
1056 (<code>`xml:"name,flag"`</code>). The matching done between field tags, field
1058 The <code>XMLName</code> field tag, if present, must also match the name
1064 Running <code>go</code> <code>fix</code> will update most uses of the package except for some calls to
1065 <code>Unmarshal</code>. Special care must be taken with field tags,
1068 <code>"attr"</code> is now written <code>",attr"</code> while plain
1069 <code>"attr"</code> remains valid but with a different meaning.
1075 In Go 1, the <code>RemoveAll</code> function has been removed.
1076 The <code>Iter</code> function and Iter method on <code>*Map</code> have
1078 <a href="/pkg/expvar/#Do"><code>Do</code></a>
1080 <a href="/pkg/expvar/#Map.Do"><code>(*Map).Do</code></a>.
1085 Most code using <code>expvar</code> will not need changing. The rare code that used
1086 <code>Iter</code> can be updated to pass a closure to <code>Do</code> to achieve the same effect.
1092 In Go 1, the interface <a href="/pkg/flag/#Value"><code>flag.Value</code></a> has changed slightly.
1093 The <code>Set</code> method now returns an <code>error</code> instead of
1094 a <code>bool</code> to indicate success or failure.
1098 There is also a new kind of flag, <code>Duration</code>, to support argument
1100 Values for such flags must be given units, just as <code>time.Duration</code>
1101 formats them: <code>10s</code>, <code>1h30m</code>, etc.
1104 {{code "/doc/progs/go1.go" `/timeout/`}}
1109 <code>Set</code> methods.
1110 The <code>Duration</code> flag is new and affects no existing code.
1117 Several packages under <code>go</code> have slightly revised APIs.
1121 A concrete <code>Mode</code> type was introduced for configuration mode flags
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>.
1130 The modes <code>AllowIllegalChars</code> and <code>InsertSemis</code> have been removed
1131 from the <a href="/pkg/go/scanner/"><code>go/scanner</code></a> package. They were mostly
1133 <a href="/pkg/text/scanner/"><code>text/scanner</code></a> package should be used
1138 The <a href="/pkg/go/scanner/#ErrorHandler"><code>ErrorHandler</code></a> provided
1139 to the scanner's <a href="/pkg/go/scanner/#Scanner.Init"><code>Init</code></a> method is
1140 now simply a function rather than an interface. The <code>ErrorVector</code> type has
1141 been removed in favor of the (existing) <a href="/pkg/go/scanner/#ErrorList"><code>ErrorList</code></a>
1142 type, and the <code>ErrorVector</code> methods have been migrated. Instead of embedding
1143 an <code>ErrorVector</code> in a client of the scanner, now a client should maintain
1144 an <code>ErrorList</code>.
1148 The set of parse functions provided by the <a href="/pkg/go/parser/"><code>go/parser</code></a>
1150 <a href="/pkg/go/parser/#ParseFile"><code>ParseFile</code></a>, and a couple of
1151 convenience functions <a href="/pkg/go/parser/#ParseDir"><code>ParseDir</code></a>
1152 and <a href="/pkg/go/parser/#ParseExpr"><code>ParseExpr</code></a>.
1156 The <a href="/pkg/go/printer/"><code>go/printer</code></a> package supports an additional
1157 configuration mode <a href="/pkg/go/printer/#Mode"><code>SourcePos</code></a>;
1158 if set, the printer will emit <code>//line</code> comments such that the generated
1159 output contains the original source code position information. The new type
1160 <a href="/pkg/go/printer/#CommentedNode"><code>CommentedNode</code></a> can be
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).
1167 The type names of the <a href="/pkg/go/doc/"><code>go/doc</code></a> package have been
1168 streamlined by removing the <code>Doc</code> suffix: <code>PackageDoc</code>
1169 is now <code>Package</code>, <code>ValueDoc</code> is <code>Value</code>, etc.
1170 Also, all types now consistently have a <code>Name</code> field (or <code>Names</code>,
1171 in the case of type <code>Value</code>) and <code>Type.Factories</code> has become
1172 <code>Type.Funcs</code>.
1173 Instead of calling <code>doc.NewPackageDoc(pkg, importpath)</code>,
1182 where the new <code>mode</code> parameter specifies the operation mode:
1183 if set to <a href="/pkg/go/doc/#AllDecls"><code>AllDecls</code></a>, all declarations
1185 The function <code>NewFileDoc</code> was removed, and the function
1186 <code>CommentText</code> has become the method
1187 <a href="/pkg/go/ast/#CommentGroup.Text"><code>Text</code></a> of
1188 <a href="/pkg/go/ast/#CommentGroup"><code>ast.CommentGroup</code></a>.
1192 In 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>
1194 (which originally returned a channel of <code>*token.File</code>s) has been replaced
1195 with the iterator <a href="/pkg/go/token/#FileSet.Iterate"><code>Iterate</code></a> that
1200 In package <a href="/pkg/go/build/"><code>go/build</code></a>, the API
1203 but it does not run the build: the <code>Cmd</code> and <code>Script</code>
1205 (To build code, use the new
1206 <a href="/cmd/go/"><code>go</code></a> command instead.)
1207 The <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>
1212 <a href="/pkg/go/build/#ImportDir"><code>ImportDir</code></a>.
1217 Code that uses packages in <code>go</code> will have to be updated by hand; the
1219 <code>go/doc</code> types may need manual fixes; the renamed fields will lead
1226 In Go 1, the definition of <a href="/pkg/hash/#Hash"><code>hash.Hash</code></a> includes
1227 a new method, <code>BlockSize</code>. This new method is used primarily in the
1232 The <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.
1235 The previous behavior can be recreated by adding a <code>nil</code> argument to the call.
1240 Existing implementations of <code>hash.Hash</code> will need to add a
1241 <code>BlockSize</code> method. Hashes that process the input one byte at
1242 a time can implement <code>BlockSize</code> to return 1.
1243 Running <code>go</code> <code>fix</code> will update calls to the <code>Sum</code> methods of the various
1244 implementations of <code>hash.Hash</code>.
1255 In Go 1 the <a href="/pkg/net/http/"><code>http</code></a> package is refactored,
1257 <a href="/pkg/net/http/httputil/"><code>httputil</code></a> subdirectory.
1278 The <code>Request.RawURL</code> field has been removed; it was a
1283 The <code>Handle</code> and <code>HandleFunc</code>
1284 functions, and the similarly-named methods of <code>ServeMux</code>,
1290 Running <code>go</code> <code>fix</code> will update the few programs that are affected except for
1291 uses of <code>RawURL</code>, which must be fixed by hand.
1297 The <a href="/pkg/image/"><code>image</code></a> package has had a number of
1302 Most of the color handling code has been moved into its own package,
1303 <a href="/pkg/image/color/"><code>image/color</code></a>.
1306 <a href="/pkg/image/#RGBA"><code>image.RGBA</code></a>
1308 <a href="/pkg/image/color/#RGBA"><code>color.RGBA</code></a>.
1312 The old <code>image/ycbcr</code> package has been folded, with some
1314 <a href="/pkg/image/"><code>image</code></a>
1316 <a href="/pkg/image/color/"><code>image/color</code></a>
1321 The old <code>image.ColorImage</code> type is still in the <code>image</code>
1323 <a href="/pkg/image/#Uniform"><code>image.Uniform</code></a>,
1324 while <code>image.Tiled</code> has been removed.
1388 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.)
1391 take an <a href="/pkg/image/#Rectangle"><code>image.Rectangle</code></a> as an argument
1396 Finally, 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>
1401 <a href="/pkg/image/color/#Transparent"><code>color.Transparent</code></a>.
1406 Running <code>go</code> <code>fix</code> will update almost all code affected by the change.
1412 In Go 1, the <a href="/pkg/log/syslog/#NewLogger"><code>syslog.NewLogger</code></a>
1413 function returns an error as well as a <code>log.Logger</code>.
1418 What little code is affected will be caught by the compiler and must be updated by hand.
1424 In Go 1, the <a href="/pkg/mime/#FormatMediaType"><code>FormatMediaType</code></a> function
1425 of the <code>mime</code> package has been simplified to make it
1427 <a href="/pkg/mime/#ParseMediaType"><code>ParseMediaType</code></a>.
1428 It now takes <code>"text/html"</code> rather than <code>"text"</code> and <code>"html"</code>.
1433 What little code is affected will be caught by the compiler and must be updated by hand.
1439 In Go 1, the various <code>SetTimeout</code>,
1440 <code>SetReadTimeout</code>, and <code>SetWriteTimeout</code> methods
1442 <a href="/pkg/net/#IPConn.SetDeadline"><code>SetDeadline</code></a>,
1443 <a href="/pkg/net/#IPConn.SetReadDeadline"><code>SetReadDeadline</code></a>, and
1444 <a href="/pkg/net/#IPConn.SetWriteDeadline"><code>SetWriteDeadline</code></a>,
1447 absolute deadline (as a <code>time.Time</code> value) after which
1453 <a href="/pkg/net/#DialTimeout"><code>net.DialTimeout</code></a>
1455 <a href="/pkg/net/#ListenMulticastUDP"><code>net.ListenMulticastUDP</code></a>
1457 The <code>net.ListenMulticastUDP</code> function replaces the old
1458 <code>JoinGroup</code> and <code>LeaveGroup</code> methods.
1463 Code that uses the old methods will fail to compile and must be updated by hand.
1470 The <code>Time</code> function has been removed; callers should use
1471 the <a href="/pkg/time/#Time"><code>Time</code></a> type from the
1472 <code>time</code> package.
1476 The <code>Exec</code> function has been removed; callers should use
1477 <code>Exec</code> from the <code>syscall</code> package, where available.
1481 The <code>ShellExpand</code> function has been renamed to <a
1482 href="/pkg/os/#ExpandEnv"><code>ExpandEnv</code></a>.
1486 The <a href="/pkg/os/#NewFile"><code>NewFile</code></a> function
1487 now takes a <code>uintptr</code> fd, instead of an <code>int</code>.
1488 The <a href="/pkg/os/#File.Fd"><code>Fd</code></a> method on files now
1489 also returns a <code>uintptr</code>.
1493 There are no longer error constants such as <code>EINVAL</code>
1494 in the <code>os</code> package, since the set of values varied with
1496 <a href="/pkg/os/#IsPermission"><code>IsPermission</code></a>
1499 <a href="/pkg/os/#ErrPermission"><code>ErrPermission</code></a>
1501 <a href="/pkg/os/#ErrNotExist"><code>ErrNotExist</code></a>.
1505 The <code>Getenverror</code> function has been removed. To distinguish
1507 use <a href="/pkg/os/#Environ"><code>os.Environ</code></a> or
1508 <a href="/pkg/syscall/#Getenv"><code>syscall.Getenv</code></a>.
1513 The <a href="/pkg/os/#Process.Wait"><code>Process.Wait</code></a> method has
1516 Also, the function <code>Wait</code> is gone; only the method of
1517 the <code>Process</code> type persists.
1521 The <code>Waitmsg</code> type returned by
1522 <a href="/pkg/os/#Process.Wait"><code>Process.Wait</code></a>
1524 <a href="/pkg/os/#ProcessState"><code>ProcessState</code></a>
1527 Because of changes to <code>Wait</code>, the <code>ProcessState</code>
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>
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.
1539 Running <code>go</code> <code>fix</code> will drop a zero argument to <code>Process.Wait</code>.
1546 Go 1 redefines the <a href="/pkg/os/#FileInfo"><code>os.FileInfo</code></a> type,
1563 <a href="/pkg/os/#FileMode"><code>os.FileMode</code></a>,
1564 a simple integer type with <code>IsDir</code>, <code>Perm</code>, and <code>String</code>
1570 i-number have been removed from <code>FileInfo</code> altogether.
1571 Instead, each operating system's <code>os</code> package provides an
1572 implementation of the <code>FileInfo</code> interface, which
1573 has a <code>Sys</code> method that returns the
1576 the <code>FileInfo</code> like this:
1593 Assuming (which is unwise) that <code>"hello.go"</code> is a Unix file,
1602 The vast majority of uses of <code>FileInfo</code> need only the methods
1607 The <code>os</code> package no longer contains wrappers for the POSIX errors
1608 such as <code>ENOENT</code>.
1611 <a href="/pkg/os/#IsExist"><code>IsExist</code></a>,
1612 <a href="/pkg/os/#IsNotExist"><code>IsNotExist</code></a>
1614 <a href="/pkg/os/#IsPermission"><code>IsPermission</code></a>.
1617 {{code "/doc/progs/go1.go" `/os\.Open/` `/}/`}}
1621 Running <code>go</code> <code>fix</code> will update code that uses the old equivalent of the current <code>os.FileInfo</code>
1622 and <code>os.FileMode</code> API.
1623 Code that needs system-specific file details will need to be updated by hand.
1624 Code that uses the old POSIX error values from the <code>os</code> package
1631 The <code>os/signal</code> package in Go 1 replaces the
1632 <code>Incoming</code> function, which returned a channel
1634 with the selective <code>Notify</code> function, which asks
1640 Code must be updated by hand.
1654 but most code should list the specific signals it wants to handle instead:
1664 In Go 1, the <a href="/pkg/path/filepath/#Walk"><code>Walk</code></a> function of the
1665 <code>path/filepath</code> package
1667 <a href="/pkg/path/filepath/#WalkFunc"><code>WalkFunc</code></a>
1668 instead of a <code>Visitor</code> interface value.
1669 <code>WalkFunc</code> unifies the handling of both files and directories.
1677 The <code>WalkFunc</code> function will be called even for files or directories that could not be opened;
1680 the function should return the value <a href="/pkg/path/filepath/#pkg-variables"><code>filepath.SkipDir</code></a>
1683 {{code "/doc/progs/go1.go" `/STARTWALK/` `/ENDWALK/`}}
1687 The change simplifies most code but has subtle consequences, so affected programs
1689 The compiler will catch code using the old interface.
1695 The <a href="/pkg/regexp/"><code>regexp</code></a> package has been rewritten.
1698 <a href="//code.google.com/p/re2/">RE2</a>.
1703 Code that uses the package should have its regular expressions checked by hand.
1710 <code>runtime</code> has been removed in favor of
1712 Code using the <code>runtime.Type</code> interface
1714 now use package <a href="/pkg/reflect/"><code>reflect</code></a>.
1715 Code using <code>runtime.Semacquire</code> or <code>runtime.Semrelease</code>
1716 should use channels or the abstractions in package <a href="/pkg/sync/"><code>sync</code></a>.
1717 The <code>runtime.Alloc</code>, <code>runtime.Free</code>,
1718 and <code>runtime.Lookup</code> functions, an unsafe API created for
1723 Before, <code>runtime.MemStats</code> was a global variable holding
1724 statistics about memory allocation, and calls to <code>runtime.UpdateMemStats</code>
1726 In 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>
1733 <a href="/pkg/runtime/#NumCPU"><code>runtime.NumCPU</code></a>, that returns the number of CPUs available
1735 Its value can inform the setting of <code>GOMAXPROCS</code>.
1736 The <code>runtime.Cgocalls</code> and <code>runtime.Goroutines</code> functions
1737 have been renamed to <code>runtime.NumCgoCall</code> and <code>runtime.NumGoroutine</code>.
1742 Running <code>go</code> <code>fix</code> will update code for the function renamings.
1743 Other code will need to be updated by hand.
1750 <a href="/pkg/strconv/"><code>strconv</code></a>
1752 although <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>).
1833 Running <code>go</code> <code>fix</code> will update almost all code affected by the change.
1835 § <code>Atoi</code> persists but <code>Atoui</code> and <code>Atof32</code> do not, so
1837 a cast that must be added by hand; the <code>go</code> <code>fix</code> tool will warn about it.
1844 The <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>.
1854 Instead of sets, a <code>Template</code> object
1868 Code that uses multiple templates in concert will need to be updated by hand.
1870 the documentation for <code>text/template</code> can provide guidance.
1876 The testing package has a type, <code>B</code>, passed as an argument to benchmark functions.
1877 In Go 1, <code>B</code> has new methods, analogous to those of <code>T</code>, enabling
1881 {{code "/doc/progs/go1.go" `/func.*Benchmark/` `/^}/`}}
1885 Existing code is unaffected, although benchmarks that use <code>println</code>
1886 or <code>panic</code> should be updated to use the new methods.
1897 No code is likely to be affected.
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;
1908 package <a href="/pkg/reflect/"><code>reflect</code></a>.
1913 Code using these functions must be rewritten to use
1914 package <a href="/pkg/reflect/"><code>reflect</code></a>.
1915 The 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>
1922 In Go 1 several fields from the <a href="/pkg/net/url/#URL"><code>url.URL</code></a> type
1927 The <a href="/pkg/net/url/#URL.String"><code>String</code></a> method now
1928 predictably rebuilds an encoded URL string using all of <code>URL</code>'s
1934 The <code>Raw</code> field has been removed. In most cases the <code>String</code>
1939 The old <code>RawUserinfo</code> field is replaced by the <code>User</code>
1940 field, of type <a href="/pkg/net/url/#Userinfo"><code>*net.Userinfo</code></a>.
1941 Values of this type may be created using the new <a href="/pkg/net/url/#User"><code>net.User</code></a>
1942 and <a href="/pkg/net/url/#UserPassword"><code>net.UserPassword</code></a>
1943 functions. The <code>EscapeUserinfo</code> and <code>UnescapeUserinfo</code>
1948 The <code>RawAuthority</code> field has been removed. The same information is
1949 available in the <code>Host</code> and <code>User</code> fields.
1953 The <code>RawPath</code> field and the <code>EncodedPath</code> method have
1955 schema) is now available only in decoded form in the <code>Path</code> field.
1962 URLs with non-rooted paths, such as <code>"mailto:dev@golang.org?subject=Hi"</code>,
1963 are also handled differently. The <code>OpaquePath</code> boolean field has been
1964 removed and a new <code>Opaque</code> string field introduced to hold the encoded
1977 A new <a href="/pkg/net/url/#URL.RequestURI"><code>RequestURI</code></a> method was
1978 added to <code>URL</code>.
1982 The <code>ParseWithReference</code> function has been renamed to <code>ParseWithFragment</code>.
1987 Code that uses the old fields will fail to compile and must be updated by hand.
1995 building, and installing Go packages and commands. The <code>go</code> command
1996 does away with makefiles, instead using Go source code to find dependencies and
2002 See <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>
2010 infrastructure (<code>Make.pkg</code>, <code>Make.cmd</code>, and so on) should
2011 switch to using the <code>go</code> command for building Go code and, if
2019 uses a different <code>_cgo_export.h</code>
2020 file, which is generated for packages containing <code>//export</code> lines.
2021 The <code>_cgo_export.h</code> file now begins with the C preamble comment,
2024 package using <code>//export</code> must not put function definitions