Commits

Joseph Poirier committed b5bf470 Merge

Merged changes from golang.

Comments (0)

Files changed (41)

 96bd78e7d35e892113bdfa1bdc392d3a5f2e644b weekly.2012-02-22
 f4470a54e6dbcdd52d8d404e12e4754adcd2c948 weekly.2012-03-04
 3cdba7b0650c6c906ef3e782654f61701abd7dd2 weekly.2012-03-13
-3cdba7b0650c6c906ef3e782654f61701abd7dd2 weekly
+bce220d0377405146527ab9478867cbc572a6886 weekly.2012-03-22
+bce220d0377405146527ab9478867cbc572a6886 weekly
 	articles/go_concurrency_patterns_timing_out_moving_on.rawhtml\
 	articles/godoc_documenting_go_code.rawhtml\
 	articles/gobs_of_data.rawhtml\
+	articles/json_and_go.rawhtml\
 	articles/image_draw.rawhtml\
 	effective_go.rawhtml\
 	go1.rawhtml\

doc/articles/c_go_cgo.html

 {{code "/doc/progs/cgo1.go" `/package rand/` `/END/`}}
 
 <p>
-Lets look at what's happening here, starting with the import statement.
+Let's look at what's happening here, starting with the import statement.
 </p>
 
 <p>
 {{code "/doc/progs/cgo1.go" `/func Random/` `/STOP/`}}
 
 <p>
-Heres an equivalent function that uses a temporary variable to illustrate
+Here's an equivalent function that uses a temporary variable to illustrate
 the type conversion more explicitly:
 </p>
 
 {{code "/doc/progs/cgo1.go" `/\/\*/` `/STOP/`}}
 
 <p>
-Cgo recognizes this comment and uses it as a header when compiling the C
-parts of the package. In this case it is just a simple include statement,
-but it can be any valid C code. The comment must be immediately before the
-line that imports <code>"C"</code>, without any intervening blank lines,
-just like a documentation comment.
+Cgo recognizes this comment.  Any lines starting
+with <code>#cgo</code>
+followed
+by a space character are removed; these become directives for cgo.
+The remaining lines are used as a header when compiling the C parts of
+the package.  In this case those lines are just a
+single <code>#include</code>
+statement, but they can be almost any C code.  The <code>#cgo</code>
+directives are
+used to provide flags for the compiler and linker when building the C
+parts of the package.
+</p>
+
+<p>
+There is a limitation: if your program uses any <code>//export</code>
+directives, then the C code in the comment may only include declarations
+(<code>extern int f();</code>), not definitions (<code>int f() {
+return 1; }</code>).  You can use <code>//export</code> directives to
+make Go functions accessible to C code.
+</p>
+
+<p>
+The <code>#cgo</code> and <code>//export</code> directives are
+documented in
+the <a href="/cmd/cgo/">cgo documentation</a>.
 </p>
 
 <p>
 </p>
 
 <p>
-Unlike Go, C doesnt have an explicit string type. Strings in C are
+Unlike Go, C doesn't have an explicit string type. Strings in C are
 represented by a zero-terminated array of chars.
 </p>
 
 <p>
 Memory allocations made by C code are not known to Go's memory manager.
 When you create a C string with <code>C.CString</code> (or any C memory
-allocation) you must remember to free the memory when youre done with it
+allocation) you must remember to free the memory when you're done with it
 by calling <code>C.free</code>.
 </p>
 
 </p>
 
 <p>
-For a simple, idiomatic example of a cgo-based package, see Russ Coxs <a
+For a simple, idiomatic example of a cgo-based package, see Russ Cox's <a
 href="http://code.google.com/p/gosqlite/source/browse/sqlite/sqlite.go">gosqlite</a>.
 Also, the Go Project Dashboard lists <a
 href="https://godashboard.appspot.com/project?tag=cgo">several other
 </p>
 
 <p>
-Finally, if you’re curious as to how all this works internally, take a look
-at the introductory comment of the runtime package’s <a href="/src/pkg/runtime/cgocall.c">cgocall.c</a>.
+Finally, if you're curious as to how all this works internally, take a look
+at the introductory comment of the runtime package's <a href="/src/pkg/runtime/cgocall.c">cgocall.c</a>.
 </p>

doc/articles/concurrency_patterns.html

+<!--{
+"Title": "Go Concurrency Patterns: Timing out, moving on",
+"Template": true
+}-->
+
+<p>
+Concurrent programming has its own idioms. A good example is timeouts. Although
+Go's channels do not support them directly, they are easy to implement. Say we
+want to receive from the channel <code>ch</code>, but want to wait at most one
+second for the value to arrive. We would start by creating a signalling channel
+and launching a goroutine that sleeps before sending on the channel:
+</p>
+
+{{code "/doc/progs/timeout1.go" `/timeout :=/` `/STOP/`}}
+
+<p>
+We can then use a <code>select</code> statement to receive from either
+<code>ch</code> or <code>timeout</code>. If nothing arrives on <code>ch</code>
+after one second, the timeout case is selected and the attempt to read from
+<cde>ch</cde> is abandoned.
+</p>
+
+{{code "/doc/progs/timeout1.go" `/select {/` `/STOP/`}}
+
+<p>
+The <code>timeout</code> channel is buffered with space for 1 value, allowing
+the timeout goroutine to send to the channel and then exit. The goroutine
+doesn't know (or care) whether the value is received. This means the goroutine
+won't hang around forever if the <code>ch</code> receive happens before the
+timeout is reached. The <code>timeout</code> channel will eventually be
+deallocated by the garbage collector.
+</p>
+
+<p>
+(In this example we used <code>time.Sleep</code> to demonstrate the mechanics
+of goroutines and channels. In real programs you should use <code>
+<a href="/pkg/time/#After">time.After</a></code>, a function that returns
+a channel and sends on that channel after the specified duration.)
+</p>
+
+<p>
+Let's look at another variation of this pattern. In this example we have a
+program that reads from multiple replicated databases simultaneously. The
+program needs only one of the answers, and it should accept the answer that
+arrives first.
+</p>
+
+<p>
+The function <code>Query</code> takes a slice of database connections and a
+<code>query</code> string. It queries each of the databases in parallel and
+returns the first response it receives:
+</p>
+
+{{code "/doc/progs/timeout2.go" `/func Query/` `/STOP/`}}
+
+<p>
+In this example, the closure does a non-blocking send, which it achieves by
+using the send operation in <code>select</code> statement with a
+<code>default</code> case. If the send cannot go through immediately the
+default case will be selected. Making the send non-blocking guarantees that
+none of the goroutines launched in the loop will hang around. However, if the
+result arrives before the main function has made it to the receive, the send
+could fail since no one is ready.
+</p>
+
+<p>
+This problem is a textbook of example of what is known as a
+<a href="https://en.wikipedia.org/wiki/Race_condition">race condition</a>, but
+the fix is trivial. We just make sure to buffer the channel <code>ch</code> (by
+adding the buffer length as the second argument to <a href="/pkg/builtin/#make">make</a>),
+guaranteeing that the first send has a place to put the value. This ensures the
+send will always succeed, and the first value to arrive will be retrieved
+regardless of the order of execution.
+</p>
+
+<p>
+These two examples demonstrate the simplicity with which Go can express complex
+interactions between goroutines.
+</p>

doc/articles/defer_panic_recover.html

 <p>
 This works, but there is a bug. If the call to os.Create fails, the
 function will return without closing the source file. This can be easily
-remedied by putting a call to src.Close() before the second return statement,
+remedied by putting a call to src.Close before the second return statement,
 but if the function were more complex the problem might not be so easily
 noticed and resolved. By introducing defer statements we can ensure that the
 files are always closed:
 It decodes JSON-encoded data with a set of recursive functions.
 When malformed JSON is encountered, the parser calls panic to unwind the
 stack to the top-level function call, which recovers from the panic and returns
-an appropriate error value (see the 'error' and 'unmarshal' functions in
+an appropriate error value (see the 'error' and 'unmarshal' methods of
+the decodeState type in
 <a href="/src/pkg/encoding/json/decode.go">decode.go</a>).
 </p>
 
 </p>
  
 <p>
-Other uses of <b>defer</b> (beyond the file.Close() example given earlier)
+Other uses of <b>defer</b> (beyond the file.Close example given earlier)
 include releasing a mutex:
 </p>
 

doc/articles/go_command.html

 <h2>Configuration versus convention</h2>
 
 <p>The way to achieve the simplicity of a configuration-free system is to
-establish conventions. The system works only to the extent that the convention
-is followed. When we first launched Go, many people published packages that
+establish conventions. The system works only to the extent that those conventions
+are followed. When we first launched Go, many people published packages that
 had to be installed in certain places, under certain names, using certain build
 tools, in order to be used. That's understandable: that's the way it works in
 most other languages. Over the last few years we consistently reminded people
-about the old <code>goinstall</code> command
+about the <code>goinstall</code> command
 (now replaced by <a href="/cmd/go/#Download_and_install_packages_and_dependencies"><code>go get</code></a>)
 and its conventions: first, that the import path is derived in a known way from
 the URL of the source code; second, that that the place to store the sources in
 that each directory in a source tree corresponds to a single package; and
 fourth, that the package is built using only information in the source code.
 Today, the vast majority of packages follow these conventions.
-The Go ecosystem is simpler and more powerful for it.</p>
+The Go ecosystem is simpler and more powerful as a result.</p>
 
 <p>We received many requests to allow a makefile in a package directory to
 provide just a little extra configuration beyond what's in the source code.

doc/articles/go_concurrency_patterns_timing_out_moving_on.html

-<!--{
-"Title": "Go Concurrency Patterns: Timing out, moving on",
-"Template": true
-}-->
-
-<p>
-Concurrent programming has its own idioms. A good example is timeouts. Although
-Go's channels do not support them directly, they are easy to implement. Say we
-want to receive from the channel <code>ch</code>, but want to wait at most one
-second for the value to arrive. We would start by creating a signalling channel
-and launching a goroutine that sleeps before sending on the channel:
-</p>
-
-{{code "/doc/progs/timeout1.go" `/timeout :=/` `/STOP/`}}
-
-<p>
-We can then use a <code>select</code> statement to receive from either
-<code>ch</code> or <code>timeout</code>. If nothing arrives on <code>ch</code>
-after one second, the timeout case is selected and the attempt to read from
-<cde>ch</cde> is abandoned.
-</p>
-
-{{code "/doc/progs/timeout1.go" `/select {/` `/STOP/`}}
-
-<p>
-The <code>timeout</code> channel is buffered with space for 1 value, allowing
-the timeout goroutine to send to the channel and then exit. The goroutine
-doesn't know (or care) whether the value is received. This means the goroutine
-won't hang around forever if the <code>ch</code> receive happens before the
-timeout is reached. The <code>timeout</code> channel will eventually be
-deallocated by the garbage collector.
-</p>
-
-<p>
-(In this example we used <code>time.Sleep</code> to demonstrate the mechanics
-of goroutines and channels. In real programs you should use <code>
-<a href="/pkg/time/#After">time.After</a></code>, a function that returns
-a channel and sends on that channel after the specified duration.)
-</p>
-
-<p>
-Let's look at another variation of this pattern. In this example we have a
-program that reads from multiple replicated databases simultaneously. The
-program needs only one of the answers, and it should accept the answer that
-arrives first.
-</p>
-
-<p>
-The function <code>Query</code> takes a slice of database connections and a
-<code>query</code> string. It queries each of the databases in parallel and
-returns the first response it receives:
-</p>
-
-{{code "/doc/progs/timeout2.go" `/func Query/` `/STOP/`}}
-
-<p>
-In this example, the closure does a non-blocking send, which it achieves by
-using the send operation in <code>select</code> statement with a
-<code>default</code> case. If the send cannot go through immediately the
-default case will be selected. Making the send non-blocking guarantees that
-none of the goroutines launched in the loop will hang around. However, if the
-result arrives before the main function has made it to the receive, the send
-could fail since no one is ready.
-</p>
-
-<p>
-This problem is a textbook of example of what is known as a
-<a href="https://en.wikipedia.org/wiki/Race_condition">race condition</a>, but
-the fix is trivial. We just make sure to buffer the channel <code>ch</code> (by
-adding the buffer length as the second argument to <a href="/pkg/builtin/#make">make</a>),
-guaranteeing that the first send has a place to put the value. This ensures the
-send will always succeed, and the first value to arrive will be retrieved
-regardless of the order of execution.
-</p>
-
-<p>
-These two examples demonstrate the simplicity with which Go can express complex
-interactions between goroutines.
-</p>

doc/articles/gobs_of_data.html

 First, protocol buffers only work on the data type we call a struct in Go. You
 can't encode an integer or array at the top level, only a struct with fields
 inside it. That seems a pointless restriction, at least in Go. If all you want
-to send is an array of integers, why should you have to put put it into a
+to send is an array of integers, why should you have to put it into a
 struct first?
 </p>
 

doc/articles/image_draw.html

 <code>r</code>:
 </p>
 
-{{code "/doc/progs/image_draw.go" `/CIRCLE/` `/STOP/`}}
+{{code "/doc/progs/image_draw.go" `/CIRCLESTRUCT/` `/STOP/`}}
 {{code "/doc/progs/image_draw.go" `/CIRCLE2/` `/STOP/`}}
   
 <p>

doc/articles/json_and_go.html

+<!--{
+"Title": "JSON and Go",
+"Template": true
+}-->
+
+<p>
+JSON (JavaScript Object Notation) is a simple data interchange format.
+Syntactically it resembles the objects and lists of JavaScript. It is most
+commonly used for communication between web back-ends and JavaScript programs
+running in the browser, but it is used in many other places, too. Its home page,
+<a href="http://json.org">json.org</a>, provides a wonderfully clear and concise
+definition of the standard.
+</p>
+
+<p>
+With the <a href="/pkg/encoding/json/">json package</a> it's a snap to read and
+write JSON data from your Go programs.
+</p>
+
+<p>
+<b>Encoding</b>
+</p>
+
+<p>
+To encode JSON data we use the
+<a href="/pkg/encoding/json/#Marshal"><code>Marshal</code></a> function.
+</p>
+
+<pre>
+func Marshal(v interface{}) ([]byte, error)
+</pre>
+
+<p>
+Given the Go data structure, <code>Message</code>,
+</p>
+
+{{code "/doc/progs/json1.go" `/type Message/` `/STOP/`}}
+
+<p>
+and an instance of <code>Message</code>
+</p>
+
+{{code "/doc/progs/json1.go" `/m :=/`}}
+
+<p>
+we can marshal a JSON-encoded version of m using <code>json.Marshal</code>:
+</p>
+
+{{code "/doc/progs/json1.go" `/b, err :=/`}}
+
+<p>
+If all is well, <code>err</code> will be <code>nil</code> and <code>b</code>
+will be a <code>[]byte</code> containing this JSON data:
+</p>
+
+<pre>
+b == []byte(`{"Name":"Alice","Body":"Hello","Time":1294706395881547000}`)
+</pre>
+
+<p>
+Only data structures that can be represented as valid JSON will be encoded:
+</p>
+
+<ul>
+<li>
+JSON objects only support strings as keys; to encode a Go map type it must be
+of the form <code>map[string]T</code> (where <code>T</code> is any Go type
+supported by the json package).
+</li>
+<li>
+Channel, complex, and function types cannot be encoded.
+</li>
+<li>
+Cyclic data structures are not supported; they will cause <code>Marshal</code>
+to go into an infinite loop.
+</li>
+<li>
+Pointers will be encoded as the values they point to (or 'null' if the pointer
+is <code>nil</code>).
+</li>
+</ul>
+
+<p>
+The json package only accesses the exported fields of struct types (those that
+begin with an uppercase letter). Therefore only the the exported fields of a
+struct will be present in the JSON output.
+</p>
+
+<p>
+<b>Decoding</b>
+</p>
+
+<p>
+To decode JSON data we use the
+<a href="/pkg/encoding/json/#Unmarshal"><code>Unmarshal</code></a> function.
+</p>
+
+<pre>
+func Unmarshal(data []byte, v interface{}) error
+</pre>
+
+<p>
+We must first create a place where the decoded data will be stored
+</p>
+
+{{code "/doc/progs/json1.go" `/var m Message/`}}
+
+<p>
+and call <code>json.Unmarshal</code>, passing it a <code>[]byte</code> of JSON
+data and a pointer to <code>m</code>
+</p>
+
+{{code "/doc/progs/json1.go" `/err := json.Unmarshal/`}}
+
+<p>
+If <code>b</code> contains valid JSON that fits in <code>m</code>, after the
+call <code>err</code> will be <code>nil</code> and the data from <code>b</code>
+will have been stored in the struct <code>m</code>, as if by an assignment
+like:
+</p>
+
+{{code "/doc/progs/json1.go" `/m = Message/` `/STOP/`}}
+
+<p>
+How does <code>Unmarshal</code> identify the fields in which to store the
+decoded data? For a given JSON key <code>"Foo"</code>, <code>Unmarshal</code>
+will look through the destination struct's fields to find (in order of
+preference):
+</p>
+
+<ul>
+<li>
+An exported field with a tag of <code>"Foo"</code> (see the
+<a href="/ref/spec#Struct_types">Go spec</a> for more on struct tags),
+</li>
+<li>
+An exported field named <code>"Foo"</code>, or
+</li>
+<li>
+An exported field named <code>"FOO"</code> or <code>"FoO"</code> or some other
+case-insensitive match of <code>"Foo"</code>.
+</li>
+</ul>
+
+<p>
+What happens when the structure of the JSON data doesn't exactly match the Go
+type?
+</p>
+
+{{code "/doc/progs/json1.go" `/"Food":"Pickle"/` `/STOP/`}}
+
+<p>
+<code>Unmarshal</code> will decode only the fields that it can find in the
+destination type.  In this case, only the Name field of m will be populated,
+and the Food field will be ignored. This behavior is particularly useful when
+you wish to pick only a few specific fields out of a large JSON blob. It also
+means that any unexported fields in the destination struct will be unaffected
+by <code>Unmarshal</code>.
+</p>
+
+<p>
+But what if you don't know the structure of your JSON data beforehand?
+</p>
+
+<p>
+<b>Generic JSON with interface{}</b>
+</p>
+
+<p>
+The <code>interface{}</code> (empty interface) type describes an interface with
+zero methods.  Every Go type implements at least zero methods and therefore
+satisfies the empty interface.
+</p>
+
+<p>
+The empty interface serves as a general container type:
+</p>
+
+{{code "/doc/progs/json2.go" `/var i interface{}/` `/STOP/`}}
+
+<p>
+A type assertion accesses the underlying concrete type:
+</p>
+
+{{code "/doc/progs/json2.go" `/r := i/` `/STOP/`}}
+
+<p>
+Or, if the underlying type is unknown, a type switch determines the type:
+</p>
+
+{{code "/doc/progs/json2.go" `/switch v/` `/STOP/`}}
+
+
+The json package uses <code>map[string]interface{}</code> and
+<code>[]interface{}</code> values to store arbitrary JSON objects and arrays;
+it will happily unmarshal any valid JSON blob into a plain
+<code>interface{}</code> value.  The default concrete Go types are:
+
+<ul>
+<li>
+<code>bool</code> for JSON booleans,
+</li>
+<li>
+<code>float64</code> for JSON numbers,
+</li>
+<li>
+<code>string</code> for JSON strings, and
+</li>
+<li>
+<code>nil</code> for JSON null.
+</li>
+</ul>
+
+<p>
+<b>Decoding arbitrary data</b>
+</p>
+
+<p>
+Consider this JSON data, stored in the variable <code>b</code>:
+</p>
+
+{{code "/doc/progs/json3.go" `/b :=/`}}
+
+<p>
+Without knowing this data's structure, we can decode it into an
+<code>interface{}</code> value with <code>Unmarshal</code>:
+</p>
+
+{{code "/doc/progs/json3.go" `/var f interface/` `/STOP/`}}
+
+<p>
+At this point the Go value in <code>f</code> would be a map whose keys are
+strings and whose values are themselves stored as empty interface values:
+</p>
+
+{{code "/doc/progs/json3.go" `/f = map/` `/STOP/`}}
+
+<p>
+To access this data we can use a type assertion to access <code>f</code>'s
+underlying <code>map[string]interface{}</code>:
+</p>
+
+{{code "/doc/progs/json3.go" `/m := f/`}}
+
+<p>
+We can then iterate through the map with a range statement and use a type switch
+to access its values as their concrete types:
+</p>
+
+{{code "/doc/progs/json3.go" `/for k, v/` `/STOP/`}}
+
+<p>
+In this way you can work with unknown JSON data while still enjoying the
+benefits of type safety.
+</p>
+
+<p>
+<b>Reference Types</b>
+</p>
+
+<p>
+Let's define a Go type to contain the data from the previous example:
+</p>
+
+{{code "/doc/progs/json4.go" `/type FamilyMember/` `/STOP/`}}
+
+{{code "/doc/progs/json4.go" `/var m FamilyMember/` `/STOP/`}}
+
+<p>
+Unmarshaling that data into a <code>FamilyMember</code> value works as
+expected, but if we look closely we can see a remarkable thing has happened.
+With the var statement we allocated a <code>FamilyMember</code> struct, and
+then provided a pointer to that value to <code>Unmarshal</code>, but at that
+time the <code>Parents</code> field was a <code>nil</code> slice value. To
+populate the <code>Parents</code> field, <code>Unmarshal</code> allocated a new
+slice behind the scenes. This is typical of how <code>Unmarshal</code> works
+with the supported reference types (pointers, slices, and maps).
+</p>
+
+<p>
+Consider unmarshaling into this data structure:
+</p>
+
+<pre>
+type Foo struct {
+    Bar *Bar
+}
+</pre>
+
+<p>
+If there were a <code>Bar</code> field in the JSON object,
+<code>Unmarshal</code> would allocate a new <code>Bar</code> and populate it.
+If not, <code>Bar</code> would be left as a <code>nil</code> pointer.
+</p>
+
+<p>
+From this a useful pattern arises: if you have an application that receives a
+few distinct message types, you might define "receiver" structure like
+</p>
+
+<pre>
+type IncomingMessage struct {
+    Cmd *Command
+    Msg *Message
+}
+</pre>
+
+<p>
+and the sending party can populate the <code>Cmd</code> field and/or the
+<code>Msg</code> field of the top-level JSON object, depending on the type of
+message they want to communicate. <code>Unmarshal</code>, when decoding the
+JSON into an <code>IncomingMessage</code> struct, will only allocate the data
+structures present in the JSON data. To know which messages to process, the
+programmer need simply test that either <code>Cmd</code> or <code>Msg</code> is
+not <code>nil</code>.
+</p>
+
+<p>
+<b>Streaming Encoders and Decoders</b>
+</p>
+
+<p>
+The json package provides <code>Decoder</code> and <code>Encoder</code> types
+to support the common operation of reading and writing streams of JSON data.
+The <code>NewDecoder</code> and <code>NewEncoder</code> functions wrap the
+<a href="/pkg/io/#Reader"><code>io.Reader</code></a> and
+<a href="/pkg/io/#Writer"><code>io.Writer</code></a> interface types.
+</p>
+
+<pre>
+func NewDecoder(r io.Reader) *Decoder
+func NewEncoder(w io.Writer) *Encoder
+</pre>
+
+<p>
+Here's an example program that reads a series of JSON objects from standard
+input, removes all but the <code>Name</code> field from each object, and then
+writes the objects to standard output:
+</p>
+
+{{code "/doc/progs/json5.go" `/package main/` `$`}}
+
+<p>
+Due to the ubiquity of Readers and Writers, these <code>Encoder</code> and
+<code>Decoder</code> types can be used in a broad range of scenarios, such as
+reading and writing to HTTP connections, WebSockets, or files.
+</p>
+
+<p>
+<b>References</b>
+</p>
+
+<p>
+For more information see the <a href="/pkg/encoding/json/">json package documentation</a>. For an example usage of
+json see the source files of the <a href="/pkg/net/rpc/jsonrpc/">jsonrpc package</a>.
+</p>

doc/articles/laws_of_reflection.html

 the executable code):
 </p>
 
-{{code "/doc/progs/interface2.go" `/var x/` `/STOP/`}}
+{{code "/doc/progs/interface2.go" `/START f9/` `/STOP/`}}
 
 <p>
 prints

doc/articles/wiki/wiki.html

 </p>
 
 <p>
-Make a new directory for this tutorial and cd to it:
+Make a new directory for this tutorial inside your <code>GOPATH</code> and cd to it:
 </p>
 
 <pre>
 
 <p>
 There is an inefficiency in this code: <code>renderTemplate</code> calls 
-<code>ParseFile</code> every time a page is rendered. 
-A better approach would be to call <code>ParseFile</code> once for each 
+<code>ParseFiles</code> every time a page is rendered. 
+A better approach would be to call <code>ParseFiles</code> once for each 
 template at program initialization, and store the resultant 
 <code>*Template</code> values in a data structure for later use.
 </p>

doc/codewalk/sharemem.xml

 channel after appropriate delays.
 </step>
 
-<step title="Creating channels" src="doc/codewalk/urlpoll.go:/create our/,/complete/">
+<step title="Creating channels" src="doc/codewalk/urlpoll.go:/Create our/,/complete/">
 First, main makes two channels of *Resource, pending and complete.
 <br/><br/>
 Inside main, a new goroutine sends one Resource per URL to pending
 goroutines, within which they are known as in and out. 
 </step>
 
-<step title="Initializing StateMonitor" src="doc/codewalk/urlpoll.go:/launch the StateMonitor/,/statusInterval/">
+<step title="Initializing StateMonitor" src="doc/codewalk/urlpoll.go:/Launch the StateMonitor/,/statusInterval/">
 StateMonitor will initialize and launch a goroutine that stores the state 
 of each Resource. We will look at this function in detail later. 
 <br/><br/>
 which is saved as status and passed to the Poller goroutines.
 </step>
 
-<step title="Launching Poller goroutines" src="doc/codewalk/urlpoll.go:/launch some Poller/,/}/">
+<step title="Launching Poller goroutines" src="doc/codewalk/urlpoll.go:/Launch some Poller/,/}/">
 Now that it has the necessary channels, main launches a number of
 Poller goroutines, passing the channels as arguments.
 The channels provide the means of communication between the main, Poller, and 
 StateMonitor goroutines.
 </step>
 
-<step title="Send Resources to pending" src="doc/codewalk/urlpoll.go:/send some Resources/,/}\(\)/">
+<step title="Send Resources to pending" src="doc/codewalk/urlpoll.go:/Send some Resources/,/}\(\)/">
 To add the initial work to the system, main starts a new goroutine
 that allocates and sends one Resource per URL to pending.
 <br/><br/>

doc/devel/weekly.html

 hg update weekly.<i>YYYY-MM-DD</i>
 </pre>
 
-<h2 id="2012-03-13">2012-03-13</h2>
+<h2 id="2012-03-22">2012-03-22 (Go 1 Release Candidate 2)</h2>
+
+<pre>
+As with last week's snapshot, this snapshot is another Go 1 release candidate.
+A notable change in this snapshot are Windows installer fixes.
+
+Changes in this snapshot:
+* 5l, 6l, 8l: fix stack split logic for stacks near default segment size.
+* archive/zip: move r.zip off disk, into reader_test.go.
+* build: catch API changes during build,
+	do more during windows build (thanks Alex Brainman),
+	lengthen timeout for the lengthy runtime test (thanks Shenghou Ma),
+	unset GOPATH before tests (thanks Shenghou Ma).
+* cmd/cgo: add support for function export for gccgo (thanks Rémy Oudompheng),
+	fix handling of errno for gccgo.
+* cmd/go: add -fno-common by default on Darwin (thanks Shenghou Ma),
+	don't add detail to errPrintedOutput,
+	fix directory->import path conversion,
+	make build errors more visible,
+	use .o, not .{5,6,8}, for gccgo created object files,
+	work around occasional ETXTBSY running cgo.
+* cmd/godoc: add toys, tour button to playground,
+	inform users that the playground doesn't work via local godoc,
+	style example headings like links,
+	use *goroot as base path in zip file,
+	use FormatText for formating code in html template,
+	use shorter titles for tabs.
+* cmd/gofmt: show ascii in usage (thanks Yasuhiro Matsumoto).
+* cmd/pack: also recognize '\\' as path separator in filenames (thanks Shenghou Ma).
+* crypto/tls: always send a Certificate message if one was requested.
+* doc/install: remove reference to "Go Tutorial" (thanks Shenghou Ma).
+* doc/play: use []rune instead of []int (thanks Yasuhiro Matsumoto).
+* doc: add Go Concurrency Patterns: Timing out, moving on article (thanks Francisco Souza),
+	add Go image/draw package article and convert code snippets to Go1,
+	add Gobs of data article (thanks Francisco Souza),
+	add Godoc: documenting Go code article (thanks Francisco Souza),
+	add JSON and Go article (thanks Francisco Souza),
+	general update of gccgo installation instructions,
+	minor updates to most docs.
+* flag: add examples.
+* gc: fix struct and array comparisons for new bool rules (thanks Anthony Martin),
+	use quoted string format in import error,
+	when expanding append inline, preserve arguments.
+* go/build: clarify why we exclude files starting with '_' or '.' (thanks Shenghou Ma),
+	clearer argument name for Import (src -> srcDir),
+	do not report Target for local imports,
+	fix match.
+* go/printer, gofmt: fix multi-line logic.
+* html/template: add Templates and XXXEscape functions,
+	fix nil pointer bug,
+	fix panic on Clone.
+* io/ioutil: fix crash when Stat fails.
+* make.bat: fix for old files (thanks Christopher Redden),
+	don't show error message if old generated files do not exist (thanks Shenghou Ma),
+	properly handle directories with spaces (thanks Alex Brainman).
+* misc/cgo/gmp: update for Go 1 (thanks Shenghou Ma).
+* misc/dashboard: remove old python package dashboard.
+* misc/dist: don't ship cmd/cov or cmd/prof,
+	force modes to 0755 or 0644 in tarballs,
+	remove exp and old before building.
+* misc/vim: restore fileencodings (thanks Yasuhiro Matsumoto).
+* net/http: couple more triv.go modernizations,
+	ensure triv.go compiles and runs (thanks Robert Hencke).
+* net: drop unnecessary type assertions and fix leak in test (thanks Mikio Hara).
+* os: IsNotExist() should also consider ERROR_PATH_NOT_FOUND on Windows (thanks Shenghou Ma),
+	do not assume syscall.Write will write everything,
+	remove document duplication in error predicate functions (thanks Shenghou Ma),
+	return some invented data from Stat(DevNull) on windows (thanks Alex Brainman).
+* path/filepath: implement Match and Glob on windows (thanks Alex Brainman).
+* reflect: document PkgPath, Method, StructField,
+	panic if MakeSlice is given bad len/cap arguments.
+* run.bat: disable test in test\bench\go1 to fix build (thanks Alex Brainman).
+* runtime/cgo: darwin signal masking (thanks Mikio Hara),
+	linux signal masking (thanks Mikio Hara).
+* runtime: do not handle signals before configuring handler,
+	manage stack by ourselves for badcallback on windows/amd64 (thanks Shenghou Ma),
+	remove unused goc2c.c (thanks Shenghou Ma).
+* sort: add time complexity to doc (thanks Stefan Nilsson),
+	fix computation of maxDepth to avoid infinite loop (thanks Stefan Nilsson).
+* spec: delete references to unsafe.Reflect,Typeof,Unreflect.
+* syscall: Test SCM_CREDENTIALS, SO_PASSCRED on Linux (thanks Albert Strasheim),
+	add a test for passing an fd over a unix socket,
+	delete passfd_test.go.
+* test: use testlib in a few more cases (thanks Shenghou Ma).
+* text/template: fix a couple of parse bugs around identifiers,
+	variables do not take arguments.
+</pre>
+
+<h2 id="2012-03-13">2012-03-13 (Go 1 Release Candidate 1)</h2>
 
 <pre>
 This weekly snapshot is very close to what we expect will be the contents of
 <li><a href="http://blog.golang.org/2010/04/json-rpc-tale-of-interfaces.html">JSON-RPC: a tale of interfaces</a></li>
 <li><a href="/doc/articles/gos_declaration_syntax.html">Go's Declaration Syntax</a></li>
 <li><a href="/doc/articles/defer_panic_recover.html">Defer, Panic, and Recover</a></li>
-<li><a href="/doc/articles/go_concurrency_patterns_timing_out_moving_on.html">Go Concurrency Patterns: Timing out, moving on</a></li>
+<li><a href="/doc/articles/concurrency_patterns.html">Go Concurrency Patterns: Timing out, moving on</a></li>
 <li><a href="/doc/articles/slices_usage_and_internals.html">Go Slices: usage and internals</a></li>
 <li><a href="http://blog.golang.org/2011/05/gif-decoder-exercise-in-go-interfaces.html">A GIF decoder: an exercise in Go interfaces</a></li>
 <li><a href="/doc/articles/error_handling.html">Error Handling and Go</a></li>
 
 <h4>Packages</h4>
 <ul>
-<li><a href="http://blog.golang.org/2011/01/json-and-go.html">JSON and Go</a> - using the <a href="/pkg/encoding/json/">json</a> package.</li>
+<li><a href="/doc/articles/json_and_go.html">JSON and Go</a> - using the <a href="/pkg/encoding/json/">json</a> package.</li>
 <li><a href="/doc/articles/gobs_of_data.html">Gobs of data</a> - the design and use of the <a href="/pkg/encoding/gob/">gob</a> package.</li>
 <li><a href="/doc/articles/laws_of_reflection.html">The Laws of Reflection</a> - the fundamentals of the <a href="/pkg/reflect/">reflect</a> package.</li>
 <li><a href="http://blog.golang.org/2011/09/go-image-package.html">The Go image package</a> - the fundamentals of the <a href="/pkg/image/">image</a> package.</li>
 <em>Updating</em>:
 Running <code>go</code> <code>fix</code> will update imports of these packages to use the new import paths.
 Installations that depend on these packages will need to install them using
-a <code>go install</code> command.
+a <code>go get</code> command.
 </p>
 
 <h2 id="major">Major changes to the library</h2>
 
 <h2 id="releases">Packaged releases</h2>
 
+<p>
+One of the most significant changes associated with Go 1 is the availability
+of prepackaged, downloadable distributions.
+They are available for many combinations of architecture and operating system
+(including Windows) and the list will grow.
+Installation details are described on the
+<a href="/doc/install">Getting Started</a> page, while
+the distributions themselves are listed on the
+<a href="http://code.google.com/p/go/downloads/list">downloads page</a>.
     el.attachEvent('on'+e, fn);
   }
 }
-bindEvent(window, 'load', godocs_onload);
-
-function godocs_onload() {
-  godocs_bindSearchEvents();
-  godocs_generateTOC();
-  godocs_bindExamples();
-}
 
 function godocs_bindSearchEvents() {
   var search = document.getElementById('search');
     }
   }
   function restoreInactive() {
-    if (search.value != "") {
+    if (search.value !== "") {
       return;
     }
     if (search.type != "search") {
   bindEvent(search, 'blur', restoreInactive);
 }
 
+/* Returns the "This sweet header" from <h2>This <i>sweet</i> header</h2>.
+ * Takes a node, returns a string.
+ */
+function godocs_nodeToText(node) {
+  var TEXT_NODE = 3; // Defined in Mozilla but not MSIE :(
+
+  var text = '';
+  for (var j = 0; j != node.childNodes.length; j++) {
+    var child = node.childNodes[j];
+    if (child.nodeType == TEXT_NODE) {
+      if (child.nodeValue != '[Top]') { //ok, that's a hack, but it works.
+        text = text + child.nodeValue;
+      }
+    } else {
+      text = text + godocs_nodeToText(child);
+    }
+  }
+  return text;
+}
+
 /* Generates a table of contents: looks for h2 and h3 elements and generates
  * links.  "Decorates" the element with id=="nav" with this table of contents.
  */
   tocCell.appendChild(dl2);
 }
 
-/* Returns the "This sweet header" from <h2>This <i>sweet</i> header</h2>.
- * Takes a node, returns a string.
- */
-function godocs_nodeToText(node) {
-  var TEXT_NODE = 3; // Defined in Mozilla but not MSIE :(
-
-  var text = '';
-  for (var j = 0; j != node.childNodes.length; j++) {
-    var child = node.childNodes[j];
-    if (child.nodeType == TEXT_NODE) {
-      if (child.nodeValue != '[Top]') { //ok, that's a hack, but it works.
-        text = text + child.nodeValue;
-      }
-    } else {
-      text = text + godocs_nodeToText(child);
+function getElementsByClassName(base, clazz) {
+  if (base.getElementsByClassName) {
+    return base.getElementsByClassName(clazz);
+  }
+  var elements = base.getElementsByTagName('*'), foundElements = [];
+  for (var n in elements) {
+    if (clazz == elements[n].className) {
+      foundElements.push(elements[n]);
     }
   }
-  return text;
+  return foundElements;
 }
 
-function godocs_bindExamples() {
-  var examples = document.getElementsByClassName("example");
-  for (var i = 0; i < examples.length; i++) {
-    godocs_bindExampleToggle(examples[i]);
-  }
-  var links = document.getElementsByClassName("exampleLink");
-  for (var i = 0; i < links.length; i++) {
-    godocs_bindExampleLink(links[i]);
-  }
-}
 function godocs_bindExampleToggle(eg) {
-  var heading = eg.getElementsByClassName("exampleHeading");
+  var heading = getElementsByClassName(eg, "exampleHeading");
+  var callback = function() {
+    if (eg.className == "example") {
+      eg.className = "exampleVisible";
+    } else {
+      eg.className = "example";
+    }
+  };
   for (var i = 0; i < heading.length; i++) {
-    bindEvent(heading[i], "click", function() {
-      if (eg.className == "example") {
-        eg.className = "exampleVisible";
-      } else {
-        eg.className = "example";
-      }
-    });
+    bindEvent(heading[i], "click", callback);
   }
 }
 function godocs_bindExampleLink(l) {
   var prefix = "example_";
   bindEvent(l, "click", function() {
     var i = l.href.indexOf("#"+prefix);
-    if (i < 0)
+    if (i < 0) {
       return;
+    }
     var id = prefix + l.href.slice(i+1+prefix.length);
     var eg = document.getElementById(id);
     eg.className = "exampleVisible";
   });
 }
+function godocs_bindExamples() {
+  var examples = getElementsByClassName(document, "example");
+  for (var i = 0; i < examples.length; i++) {
+    godocs_bindExampleToggle(examples[i]);
+  }
+  var links = getElementsByClassName(document, "exampleLink");
+  for (i = 0; i < links.length; i++) {
+    godocs_bindExampleLink(links[i]);
+  }
+}
+
+function godocs_onload() {
+  godocs_bindSearchEvents();
+  godocs_generateTOC();
+  godocs_bindExamples();
+}
+
+bindEvent(window, 'load', godocs_onload);

doc/progs/image_draw.go

 	// STOP OMIT
 }
 
-//CIRCLE OMIT
+//CIRCLESTRUCT OMIT
 type circle struct {
 	p image.Point
 	r int
 	return color.Alpha{0}
 }
 
-//STOP
+//STOP OMIT

doc/progs/interface2.go

 	fmt.Println("t is now", t)
 	// STOP OMIT
 }
+
+func f9() {
+	// START f9 OMIT
+	var x float64 = 3.4
+	fmt.Println("value:", reflect.ValueOf(x))
+	// STOP OMIT
+}

doc/progs/json1.go

+// Copyright 2012 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import (
+	"encoding/json"
+	"log"
+	"reflect"
+)
+
+type Message struct {
+	Name string
+	Body string
+	Time int64
+}
+
+// STOP OMIT
+
+func Encode() {
+	m := Message{"Alice", "Hello", 1294706395881547000}
+	b, err := json.Marshal(m)
+
+	if err != nil {
+		panic(err)
+	}
+
+	expected := []byte(`{"Name":"Alice","Body":"Hello","Time":1294706395881547000}`)
+	if !reflect.DeepEqual(b, expected) {
+		log.Panicf("Error marshalling %q, expected %q, got %q.", m, expected, b)
+	}
+
+}
+
+func Decode() {
+	b := []byte(`{"Name":"Alice","Body":"Hello","Time":1294706395881547000}`)
+	var m Message
+	err := json.Unmarshal(b, &m)
+
+	if err != nil {
+		panic(err)
+	}
+
+	expected := Message{
+		Name: "Alice",
+		Body: "Hello",
+		Time: 1294706395881547000,
+	}
+
+	if !reflect.DeepEqual(m, expected) {
+		log.Panicf("Error unmarshalling %q, expected %q, got %q.", b, expected, m)
+	}
+
+	m = Message{
+		Name: "Alice",
+		Body: "Hello",
+		Time: 1294706395881547000,
+	}
+
+	// STOP OMIT
+}
+
+func PartialDecode() {
+	b := []byte(`{"Name":"Bob","Food":"Pickle"}`)
+	var m Message
+	err := json.Unmarshal(b, &m)
+
+	// STOP OMIT
+
+	if err != nil {
+		panic(err)
+	}
+
+	expected := Message{
+		Name: "Bob",
+	}
+
+	if !reflect.DeepEqual(expected, m) {
+		log.Panicf("Error unmarshalling %q, expected %q, got %q.", b, expected, m)
+	}
+}
+
+func main() {
+	Encode()
+	Decode()
+	PartialDecode()
+}

doc/progs/json2.go

+// Copyright 2012 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import (
+	"fmt"
+	"math"
+)
+
+func InterfaceExample() {
+	var i interface{}
+	i = "a string"
+	i = 2011
+	i = 2.777
+
+	// STOP OMIT
+
+	r := i.(float64)
+	fmt.Println("the circle's area", math.Pi*r*r)
+
+	// STOP OMIT
+
+	switch v := i.(type) {
+	case int:
+		fmt.Println("twice i is", v*2)
+	case float64:
+		fmt.Println("the reciprocal of i is", 1/v)
+	case string:
+		h := len(v) / 2
+		fmt.Println("i swapped by halves is", v[h:]+v[:h])
+	default:
+		// i isn't one of the types above
+	}
+
+	// STOP OMIT
+}
+
+func main() {
+	InterfaceExample()
+}

doc/progs/json3.go

+// Copyright 2012 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import (
+	"encoding/json"
+	"fmt"
+	"log"
+	"reflect"
+)
+
+func Decode() {
+	b := []byte(`{"Name":"Wednesday","Age":6,"Parents":["Gomez","Morticia"]}`)
+
+	var f interface{}
+	err := json.Unmarshal(b, &f)
+
+	// STOP OMIT
+
+	if err != nil {
+		panic(err)
+	}
+
+	expected := map[string]interface{}{
+		"Name": "Wednesday",
+		"Age":  float64(6),
+		"Parents": []interface{}{
+			"Gomez",
+			"Morticia",
+		},
+	}
+
+	if !reflect.DeepEqual(f, expected) {
+		log.Panicf("Error unmarshalling %q, expected %q, got %q", b, expected, f)
+	}
+
+	f = map[string]interface{}{
+		"Name": "Wednesday",
+		"Age":  6,
+		"Parents": []interface{}{
+			"Gomez",
+			"Morticia",
+		},
+	}
+
+	// STOP OMIT
+
+	m := f.(map[string]interface{})
+
+	for k, v := range m {
+		switch vv := v.(type) {
+		case string:
+			fmt.Println(k, "is string", vv)
+		case int:
+			fmt.Println(k, "is int", vv)
+		case []interface{}:
+			fmt.Println(k, "is an array:")
+			for i, u := range vv {
+				fmt.Println(i, u)
+			}
+		default:
+			fmt.Println(k, "is of a type I don't know how to handle")
+		}
+	}
+
+	// STOP OMIT
+}
+
+func main() {
+	Decode()
+}

doc/progs/json4.go

+// Copyright 2012 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import (
+	"encoding/json"
+	"log"
+	"reflect"
+)
+
+type FamilyMember struct {
+	Name    string
+	Age     int
+	Parents []string
+}
+
+// STOP OMIT
+
+func Decode() {
+	b := []byte(`{"Name":"Bob","Age":20,"Parents":["Morticia", "Gomez"]}`)
+	var m FamilyMember
+	err := json.Unmarshal(b, &m)
+
+	// STOP OMIT
+
+	if err != nil {
+		panic(err)
+	}
+
+	expected := FamilyMember{
+		Name:    "Bob",
+		Age:     20,
+		Parents: []string{"Morticia", "Gomez"},
+	}
+
+	if !reflect.DeepEqual(expected, m) {
+		log.Panicf("Error unmarshalling %q, expected %q, got %q", b, expected, m)
+	}
+}
+
+func main() {
+	Decode()
+}

doc/progs/json5.go

+// Copyright 2012 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import (
+	"encoding/json"
+	"log"
+	"os"
+)
+
+func main() {
+	dec := json.NewDecoder(os.Stdin)
+	enc := json.NewEncoder(os.Stdout)
+	for {
+		var v map[string]interface{}
+		if err := dec.Decode(&v); err != nil {
+			log.Println(err)
+			return
+		}
+		for k := range v {
+			if k != "Name" {
+				delete(v, k)
+			}
+		}
+		if err := enc.Encode(&v); err != nil {
+			log.Println(err)
+		}
+	}
+}
 	gobs2
 "
 
-all=$(echo $defer_panic_recover $effective_go $error_handling $law_of_reflection $c_go_cgo $timeout $gobs slices go1)
+json="
+	json1
+	json2
+	json3
+	json4
+	json5
+"
+
+all=$(echo $defer_panic_recover $effective_go $error_handling $law_of_reflection $c_go_cgo $timeout $gobs $json slices go1)
 
 for i in $all; do
 	go build $i.go
 testit go1 '^Christmas is a holiday: true Sleeping for 0.123s.*go1.go already exists$'
 
 testit interface2 "^type: float64$"
+testit json1 "^$"
+testit json2 "the reciprocal of i is"
+testit json3 "Age is int 6"
+testit json4 "^$"
 
 rm -f $all "$TMPFILE"

doc/progs/timeout1.go

 	ch := make(chan bool, 1)
 	timeout := make(chan bool, 1)
 	go func() {
-		time.Sleep(1e9) // one second
+		time.Sleep(1 * time.Second)
 		timeout <- true
 	}()
 

doc/reference-cmd.html

 }-->
 
 <p>
-Click on the links for more documentation and usage messages.
+There is a suite of programs to build and process Go source code.
+Instead of being run directly, programs in the suite are usually invoked
+by the <a href="/cmd/go/">go</a> program.
+</p>
+
+<p>
+The most common way to run these programs is as a subcommand of the go
+program,
+for instance as "go fmt". Run like this, the command operates on complete
+packages of Go source code, with the go program invoking the underlying binary
+with arguments appropriate to package-level processing.
+</p>
+
+<p>
+The programs can also be run as stand-alone binaries, with unmodified arguments,
+using the go tool subcommand, such as "go tool fmt".
+This style of invocation allows, for instance, reformatting a single source file rather than
+an entire package: "go tool fmt myprogram.go" as compared to
+"go fmt mypackage".
+Some of the commands, such as prof and yacc, are accessible
+only through the go tool subcommand.
+</p>
+
+<p>
+Finally, two of the commands, fmt and
+doc, are also installed as regular binaries called
+gofmt and godoc
+because they are so often referenced.
+</p>
+
+<p>
+Click on the links for more documentation, invocation methods, and usage details.
 </p>
 
 <table class="dir">
 <td><a href="/cmd/go/">go</a></td>
 <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
 <td>
-Go is a tool for managing Go source code.
-<br>
-Besides compiling and running Go programs, the go command is also used to
-invoke the other commands listed below. See the command docs for usage
+The <code>go</code> program manages Go source code and runs the other
+commands listed here.
+See the command docs for usage
 details.
 <br><br>
 </td>
 </tr>
 
 <tr>
-<td><a href="/cmd/godoc/">godoc</a></td>
+<td><a href="/cmd/go/">doc</a></td>
 <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
-<td>Godoc extracts and generates documentation for Go programs.</td>
+<td>Doc extracts and generates documentation for Go packages, it is also available as
+an independent <a href="/cmd/godoc/">godoc</a> command with more general options.</td>
 </tr>
 
 <tr>
-<td><a href="/cmd/gofmt/">gofmt</a></td>
+<td><a href="/cmd/go/">fmt</a></td>
 <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
-<td>Gofmt formats Go programs.</td>
+<td>Fmt formats Go packages, it is also available as an independent <a href="/cmd/gofmt/">
+gofmt</a> command with more general options.</td>
 </tr>
 
 <tr>
 <tr>
 <td><a href="/cmd/vet/">vet</a></td>
 <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
-<td>Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string.</td>
+<td>Vet examines Go source code and reports suspicious constructs, such as Printf
+calls whose arguments do not align with the format string.</td>
 </tr>
 
 <tr>
 <td><a href="/cmd/yacc/">yacc</a></td>
 <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
-<td>Yacc is a version of yacc for Go.</td>
+<td>Yacc is a version of yacc that generates parsers implemented in Go.</td>
 </tr>
 
 </table>

misc/dist/windows/installer.wxs

 -->
 
 <?if $(var.Arch) = 386 ?>
-  <?define SYSFOLDER=SystemFolder ?>
-  <?define Win64=no ?>
+  <?define ProdId = {FF5B30B2-08C2-11E1-85A2-6ACA4824019B} ?>
+  <?define UpgradeCode = {1C3114EA-08C3-11E1-9095-7FCA4824019B} ?>
+  <?define SysFolder=SystemFolder ?>
+  <?define IsX64Target = no ?>
 <?else?>
-  <?define SYSFOLDER=System64Folder ?>
-  <?define Win64=yes ?>
+  <?define ProdId = {716c3eaa-9302-48d2-8e5e-5cfec5da2fab} ?>
+  <?define UpgradeCode = {22ea7650-4ac6-4001-bf29-f4b8775db1c0} ?>
+  <?define SysFolder=System64Folder ?>
+  <?define IsX64Target = yes ?>
 <?endif?>
 
 <Product
     Codepage="1252"
     Version="0.0.0.0"
     Manufacturer="http://golang.org"
-    UpgradeCode="1C3114EA-08C3-11E1-9095-7FCA4824019B" >
+    UpgradeCode="$(var.UpgradeCode)" >
     <!-- Version="$(var.Version)" TODO: Version requires X.X.X.X format -->
 
 <Package
 <Property Id="ARPHELPLINK" Value="golang.org/doc/community.html" />
 <Property Id="ARPREADME" Value="golang.org" />
 <Property Id="ARPURLINFOABOUT" Value="golang.org" />
+<Property Id="LicenseAccepted">1</Property>
 <Icon Id="gopher.ico" SourceFile="images\gopher.ico"/>
 <Property Id="ARPPRODUCTICON" Value="gopher.ico" />
 <Media Id='1' Cabinet="go.cab" EmbedCab="yes" CompressionLevel="high" />
 <Condition Message="Windows 2000 or greater required."> VersionNT >= 500</Condition>
 <MajorUpgrade AllowDowngrades="yes" />
-<SetDirectory Id="INSTALLDIRROOT" Value="C:\"/>
 
 <CustomAction
     Id="SetApplicationRootDirectory"
   <Directory Id="EnvironmentEntries">
     <Directory Id="GoEnvironmentEntries" Name="Go Programming Language"/>
   </Directory>
-  <Directory Id="DesktopFolder" Name="Desktop"/>
 </Directory>
 
-<!-- Programs Menu & Desktop Shortcuts -->
+<!-- Programs Menu Shortcuts -->
 <DirectoryRef Id="GoProgramShortcutsDir">
-  <Component Id="Component_GoShortCuts" Guid="f5fbfb5e-6c5c-423b-9298-21b0e3c98f4b">
+  <Component Id="Component_GoProgramShortCuts" Guid="{f5fbfb5e-6c5c-423b-9298-21b0e3c98f4b}" Win64="$(var.IsX64Target)">
     <Shortcut
         Id="GoDocServerStartMenuShortcut"
         Name="GoDocServer"
         Description="Starts the Go documentation server (http://localhost:6060)"
         Show="minimized"
-        Arguments='/c "start /d[INSTALLDIR]bin godoc.exe -http=:6060 &amp;&amp; start http://localhost:6060"'
+        Arguments='/c start "Godoc Server http://localhost:6060" "[INSTALLDIR]bin\godoc.exe" -http=localhost:6060 -goroot="[INSTALLDIR]." &amp;&amp; start http://localhost:6060'
         Icon="gopher.ico"
         Target="[%ComSpec]" />
     <Shortcut
-        Id="GoDocServerDesktopShortcut"
-        Directory="DesktopFolder"
-        Name="GoDocServer"
-        Description="Starts the godoc server (http://localhost:6060)"
-        Show="minimized"
-        Icon="gopher.ico"
-        Arguments='/c "start /d[INSTALLDIR]bin godoc.exe -http=:6060 &amp;&amp; start http://localhost:6060"'
-        Target="[%ComSpec]" />
-    <Shortcut
         Id="UninstallShortcut"
         Name="Uninstall Go"
         Description="Uninstalls Go and all of its components"
-        Target="[$(var.SYSFOLDER)]msiexec.exe"
+        Target="[$(var.SysFolder)]msiexec.exe"
         Arguments="/x [ProductCode]" />
     <RemoveFolder
         Id="GoProgramShortcutsDir"
 
 <!-- Registry & Environment Settings -->
 <DirectoryRef Id="GoEnvironmentEntries">
-  <Component Id="Component_GoEnvironment" Guid="3ec7a4d5-eb08-4de7-9312-2df392c45993">
+  <Component Id="Component_GoEnvironment" Guid="{3ec7a4d5-eb08-4de7-9312-2df392c45993}" Win64="$(var.IsX64Target)">
     <RegistryKey 
         Root="HKCU"
         Key="Software\GoProgrammingLanguage"
                 Value="[INSTALLDIR]" />
     </RegistryKey>
     <Environment
-        Id="Environment"
+        Id="GoPathEntry"
         Action="set"
         Part="last"
         Name="PATH"
         Permanent="no"
         System="yes"
         Value="[INSTALLDIR]bin" />
+    <Environment
+        Id="GoRoot"
+        Action="set"
+        Part="all"
+        Name="GOROOT"
+        Permanent="no"
+        System="yes"
+        Value="[INSTALLDIR]" />
     <RemoveFolder
         Id="GoEnvironmentEntries"
         On="uninstall" />
   </Component>
 </DirectoryRef>
 
-<!-- Components -->
-
 <!-- Install the files -->
 <Feature
     Id="GoTools"
     Level="1">
       <ComponentRef Id="Component_GoEnvironment" />
       <ComponentGroupRef Id="AppFiles" />
-      <ComponentRef Id="Component_GoShortCuts" />
+      <ComponentRef Id="Component_GoProgramShortCuts" />
 </Feature>
 
 <!-- Update the environment -->

src/cmd/gc/walk.c

 
 	walkexprlistsafe(n->list, init);
 
+	// walkexprlistsafe will leave OINDEX (s[n]) alone if both s
+	// and n are name or literal, but those may index the slice we're
+	// modifying here.  Fix explicitly.
+	for(l=n->list; l; l=l->next)
+		l->n = cheapexpr(l->n, init);
+
 	nsrc = n->list->n;
 	argc = count(n->list) - 1;
 	if (argc < 1) {

src/pkg/crypto/tls/handshake_server.go

 	for _, id := range clientHello.cipherSuites {
 		for _, supported := range config.cipherSuites() {
 			if id == supported {
-				suite = nil
+				var candidate *cipherSuite
+
 				for _, s := range cipherSuites {
 					if s.id == id {
-						suite = s
+						candidate = s
 						break
 					}
 				}
-				if suite == nil {
+				if candidate == nil {
 					continue
 				}
 				// Don't select a ciphersuite which we can't
 				// support for this client.
-				if suite.elliptic && !ellipticOk {
+				if candidate.elliptic && !ellipticOk {
 					continue
 				}
+				suite = candidate
 				break FindCipherSuite
 			}
 		}

src/pkg/crypto/tls/key_agreement.go

 		}
 	}
 
+	if curveid == 0 {
+		return nil, errors.New("tls: no supported elliptic curves offered")
+	}
+
 	var x, y *big.Int
 	var err error
 	ka.privateKey, x, y, err = elliptic.GenerateKey(ka.curve, config.rand())

src/pkg/encoding/json/encode.go

 // RFC 4627.
 //
 // See "JSON and Go" for an introduction to this package:
-// http://blog.golang.org/2011/01/json-and-go.html
+// http://golang.org/doc/articles/json_and_go.html
 package json
 
 import (

src/pkg/flag/example_test.go

+// Copyright 2012 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// These examples demonstrate more intricate uses of the flag package.
+package flag_test
+
+import (
+	"errors"
+	"flag"
+	"fmt"
+	"strings"
+	"time"
+)
+
+// Example 1: A single string flag called "species" with default value "gopher".
+var species = flag.String("species", "gopher", "the species we are studying")
+
+// Example 2: Two flags sharing a variable, so we can have a shorthand.
+// The order of initialization is undefined, so make sure both use the
+// same default value. They must be set up with an init function.
+var gopherType string
+
+func init() {
+	const (
+		defaultGopher = "pocket"
+		usage         = "the variety of gopher"
+	)
+	flag.StringVar(&gopherType, "gopher_type", defaultGopher, usage)
+	flag.StringVar(&gopherType, "g", defaultGopher, usage+" (shorthand)")
+}
+
+// Example 3: A user-defined flag type, a slice of durations.
+type interval []time.Duration
+
+// String is the method to format the flag's value, part of the flag.Value interface.
+// The String method's output will be used in diagnostics.
+func (i *interval) String() string {
+	return fmt.Sprint(*i)
+}
+
+// Set is the method to set the flag value, part of the flag.Value interface.
+// Set's argument is a string to be parsed to set the flag.
+// It's a comma-separated list, so we split it.
+func (i *interval) Set(value string) error {
+	// If we wanted to allow the flag to be set multiple times,
+	// accumulating values, we would delete this if statement.
+	// That would permit usages such as
+	//	-deltaT 10s -deltaT 15s
+	// and other combinations.
+	if len(*i) > 0 {
+		return errors.New("interval flag already set")
+	}
+	for _, dt := range strings.Split(value, ",") {
+		duration, err := time.ParseDuration(dt)
+		if err != nil {
+			return err
+		}
+		*i = append(*i, duration)
+	}
+	return nil
+}
+
+// Define a flag to accumulate durations. Because it has a special type,
+// we need to use the Var function and therefore create the flag during
+// init.
+
+var intervalFlag interval
+
+func init() {
+	// Tie the command-line flag to the intervalFlag variable and
+	// set a usage message.
+	flag.Var(&intervalFlag, "deltaT", "comma-separated list of intervals to use between events")
+}
+
+func Example() {
+	// All the interesting pieces are with the variables declared above, but
+	// to enable the flag package to see the flags defined there, one must
+	// execute, typically at the start of main (not init!):
+	//	flag.Parse()
+	// We don't run it here because this is not a main function and
+	// the testing suite has already parsed the flags.
+}

src/pkg/os/types.go

 
 func (m FileMode) String() string {
 	const str = "dalTLDpSugct"
-	var buf [20]byte
+	var buf [32]byte // Mode is uint32.
 	w := 0
 	for i, c := range str {
 		if m&(1<<uint(32-1-i)) != 0 {

src/pkg/path/filepath/path_test.go

 var volumenametests = []VolumeNameTest{
 	{`c:/foo/bar`, `c:`},
 	{`c:`, `c:`},
+	{`2:`, ``},
 	{``, ``},
 	{`\\\host`, ``},
 	{`\\\host\`, ``},

src/pkg/path/filepath/path_windows.go

 	}
 	// with drive letter
 	c := path[0]
-	if path[1] == ':' &&
-		('0' <= c && c <= '9' || 'a' <= c && c <= 'z' ||
-			'A' <= c && c <= 'Z') {
+	if path[1] == ':' && ('a' <= c && c <= 'z' || 'A' <= c && c <= 'Z') {
 		return path[:2]
 	}
 	// is it UNC

src/pkg/sort/sort.go

 }
 
 // Sort sorts data.
-// The algorithm used is not guaranteed to be a stable sort.
+// It makes one call to data.Len to determine n, and O(n*log(n)) calls to
+// data.Less and data.Swap. The sort is not guaranteed to be stable.
 func Sort(data Interface) {
 	// Switch to heapsort if depth of 2*ceil(lg(n+1)) is reached.
 	n := data.Len()

src/pkg/text/template/doc.go

 
 During execution functions are found in two function maps: first in the
 template, then in the global function map. By default, no functions are defined
-in the template but the Funcs methods can be used to add them.
+in the template but the Funcs method can be used to add them.
 
 Predefined global functions are named as follows.
 

test/fixedbugs/bug424.go

-// run
+// $G $D/$F.dir/lib.go && $G $D/$F.go && $L $F.$A && ./$A.out
 
 // Copyright 2012 The Go Authors.  All rights reserved.
 // Use of this source code is governed by a BSD-style
 
 package main
 
-import "./bug424.dir"
+import "./lib"
 import "reflect"
 import "fmt"
 

test/fixedbugs/bug428.go

+// run
+
+// Copyright 2012 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Test that when the compiler expands append inline it does not
+// overwrite a value before it needs it (issue 3369).
+
+package main
+
+func main() {
+	s := make([]byte, 5, 6)
+	copy(s, "12346")
+	s = append(s[:len(s)-1], '5', s[len(s)-1])
+	if string(s) != "123456" {
+		panic(s)
+	}
+}
 
 == bugs/
 
-=========== bugs/424.go
-BUG: myT3: lib.T.m called
-
 =========== bugs/bug395.go
 bug395 is broken