doc: use relative links in Laws of Reflection article

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5924050
This commit is contained in:
Andrew Gerrand 2012-03-27 20:53:16 +11:00
parent cafc2b6a24
commit 14da5298cd
1 changed files with 21 additions and 26 deletions

View File

@ -48,8 +48,8 @@ fixed sets of methods. An interface variable can store any concrete
(non-interface) value as long as that value implements the (non-interface) value as long as that value implements the
interface's methods. A well-known pair of examples is interface's methods. A well-known pair of examples is
<code>io.Reader</code> and <code>io.Writer</code>, the types <code>io.Reader</code> and <code>io.Writer</code>, the types
<code>Reader</code> and <code>Writer</code> from the <a href= <code>Reader</code> and <code>Writer</code> from the
"http://golang.org/pkg/io/">io package</a>: <a href="/pkg/io/">io package</a>:
</p> </p>
{{code "/doc/progs/interface.go" `/// Reader/` `/STOP/`}} {{code "/doc/progs/interface.go" `/// Reader/` `/STOP/`}}
@ -101,11 +101,10 @@ interfaces are closely related.
<p><b>The representation of an interface</b></p> <p><b>The representation of an interface</b></p>
<p> <p>
Russ Cox has written a <a href= Russ Cox has written a
"http://research.swtch.com/2009/12/go-data-structures-interfaces.html"> <a href="http://research.swtch.com/2009/12/go-data-structures-interfaces.html">detailed blog post</a>
detailed blog post</a> about the representation of interface values about the representation of interface values in Go. It's not necessary to
in Go. It's not necessary to repeat the full story here, but a repeat the full story here, but a simplified summary is in order.
simplified summary is in order.
</p> </p>
<p> <p>
@ -183,9 +182,9 @@ Now we're ready to reflect.
At the basic level, reflection is just a mechanism to examine the At the basic level, reflection is just a mechanism to examine the
type and value pair stored inside an interface variable. To get type and value pair stored inside an interface variable. To get
started, there are two types we need to know about in started, there are two types we need to know about in
<a href="http://golang.org/pkg/reflect">package reflect</a>: <a href="/pkg/reflect/">package reflect</a>:
<a href="http://golang.org/pkg/reflect/#Type">Type</a> and <a href="/pkg/reflect/#Type">Type</a> and
<a href="http://golang.org/pkg/reflect/#Value">Value</a>. Those two types <a href="/pkg/reflect/#Value">Value</a>. Those two types
give access to the contents of an interface variable, and two give access to the contents of an interface variable, and two
simple functions, called <code>reflect.TypeOf</code> and simple functions, called <code>reflect.TypeOf</code> and
<code>reflect.ValueOf</code>, retrieve <code>reflect.Type</code> <code>reflect.ValueOf</code>, retrieve <code>reflect.Type</code>
@ -211,13 +210,11 @@ type: float64
</pre> </pre>
<p> <p>
You might be wondering where the interface is here, since the You might be wondering where the interface is here, since the program looks
program looks like it's passing the <code>float64</code> like it's passing the <code>float64</code> variable <code>x</code>, not an
variable <code>x</code>, not an interface value, to interface value, to <code>reflect.TypeOf</code>. But it's there; as
<code>reflect.TypeOf</code>. But it's there; as <a href= <a href="/pkg/reflect/#Type.TypeOf">godoc reports</a>, the signature of
"http://golang.org/pkg/reflect/#Type.TypeOf">godoc reports</a>, the <code>reflect.TypeOf</code> includes an empty interface:
signature of <code>reflect.TypeOf</code> includes an empty
interface:
</p> </p>
<pre> <pre>
@ -573,15 +570,13 @@ fields.
</p> </p>
<p> <p>
Here's a simple example that analyzes a struct value, Here's a simple example that analyzes a struct value, <code>t</code>. We create
<code>t</code>. We create the reflection object with the address of the reflection object with the address of the struct because we'll want to
the struct because we'll want to modify it later. Then we set modify it later. Then we set <code>typeOfT</code> to its type and iterate over
<code>typeOfT</code> to its type and iterate over the fields using the fields using straightforward method calls
straightforward method calls (see (see <a href="/pkg/reflect/">package reflect</a> for details).
<a href="http://golang.org/pkg/reflect/">package reflect</a> for details). Note that we extract the names of the fields from the struct type, but the
Note that we extract the names of the fields from the struct type, fields themselves are regular <code>reflect.Value</code> objects.
but the fields themselves are regular <code>reflect.Value</code>
objects.
</p> </p>
{{code "/doc/progs/interface2.go" `/START f8/` `/STOP/`}} {{code "/doc/progs/interface2.go" `/START f8/` `/STOP/`}}