summaryrefslogtreecommitdiff
path: root/doc/codelab/wiki
diff options
context:
space:
mode:
Diffstat (limited to 'doc/codelab/wiki')
-rw-r--r--doc/codelab/wiki/Makefile4
-rw-r--r--doc/codelab/wiki/final-noclosure.go26
-rw-r--r--doc/codelab/wiki/final-noerror.go17
-rw-r--r--doc/codelab/wiki/final-parsetemplate.go21
-rw-r--r--doc/codelab/wiki/final-template.go15
-rw-r--r--doc/codelab/wiki/final.go19
-rw-r--r--doc/codelab/wiki/get.go8
-rw-r--r--doc/codelab/wiki/htmlify.go8
-rw-r--r--doc/codelab/wiki/http-sample.go2
-rw-r--r--doc/codelab/wiki/index.html48
-rw-r--r--doc/codelab/wiki/notemplate.go11
-rw-r--r--doc/codelab/wiki/part1-noerror.go7
-rw-r--r--doc/codelab/wiki/part1.go9
-rw-r--r--doc/codelab/wiki/part2.go11
-rw-r--r--doc/codelab/wiki/srcextract.go8
-rw-r--r--doc/codelab/wiki/wiki.html16
16 files changed, 135 insertions, 95 deletions
diff --git a/doc/codelab/wiki/Makefile b/doc/codelab/wiki/Makefile
index 32dc1a1c2..233917f2c 100644
--- a/doc/codelab/wiki/Makefile
+++ b/doc/codelab/wiki/Makefile
@@ -8,7 +8,7 @@ all: index.html
include ../../../src/Make.common
-CLEANFILES+=index.html srcextract.bin htmlify.bin get.bin
+CLEANFILES+=srcextract.bin htmlify.bin get.bin
index.html: wiki.html srcextract.bin htmlify.bin
PATH=.:$$PATH awk '/^!/{system(substr($$0,2)); next} {print}' < wiki.html | tr -d '\r' > index.html
@@ -21,5 +21,5 @@ test: get.bin
$(LD) -o $@ $<
%.$O: %.go
- $(GC) $*.go
+ $(GC) $(GCFLAGS) $(GCIMPORTS) $*.go
diff --git a/doc/codelab/wiki/final-noclosure.go b/doc/codelab/wiki/final-noclosure.go
index 067f502c6..a0428d42d 100644
--- a/doc/codelab/wiki/final-noclosure.go
+++ b/doc/codelab/wiki/final-noclosure.go
@@ -1,11 +1,15 @@
+// Copyright 2010 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 (
- "http"
+ "errors"
"io/ioutil"
- "os"
+ "net/http"
"regexp"
- "template"
+ "text/template"
)
type Page struct {
@@ -13,12 +17,12 @@ type Page struct {
Body []byte
}
-func (p *Page) save() os.Error {
+func (p *Page) save() error {
filename := p.Title + ".txt"
return ioutil.WriteFile(filename, p.Body, 0600)
}
-func loadPage(title string) (*Page, os.Error) {
+func loadPage(title string) (*Page, error) {
filename := title + ".txt"
body, err := ioutil.ReadFile(filename)
if err != nil {
@@ -61,21 +65,21 @@ func saveHandler(w http.ResponseWriter, r *http.Request) {
p := &Page{Title: title, Body: []byte(body)}
err = p.save()
if err != nil {
- http.Error(w, err.String(), http.StatusInternalServerError)
+ http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.Redirect(w, r, "/view/"+title, http.StatusFound)
}
func renderTemplate(w http.ResponseWriter, tmpl string, p *Page) {
- t, err := template.ParseFile(tmpl+".html")
+ t, err := template.ParseFiles(tmpl + ".html")
if err != nil {
- http.Error(w, err.String(), http.StatusInternalServerError)
+ http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
err = t.Execute(w, p)
if err != nil {
- http.Error(w, err.String(), http.StatusInternalServerError)
+ http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
@@ -83,11 +87,11 @@ const lenPath = len("/view/")
var titleValidator = regexp.MustCompile("^[a-zA-Z0-9]+$")
-func getTitle(w http.ResponseWriter, r *http.Request) (title string, err os.Error) {
+func getTitle(w http.ResponseWriter, r *http.Request) (title string, err error) {
title = r.URL.Path[lenPath:]
if !titleValidator.MatchString(title) {
http.NotFound(w, r)
- err = os.NewError("Invalid Page Title")
+ err = errors.New("Invalid Page Title")
}
return
}
diff --git a/doc/codelab/wiki/final-noerror.go b/doc/codelab/wiki/final-noerror.go
index b8edbee9b..e86bc1a3c 100644
--- a/doc/codelab/wiki/final-noerror.go
+++ b/doc/codelab/wiki/final-noerror.go
@@ -1,10 +1,13 @@
+// Copyright 2010 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 (
- "http"
"io/ioutil"
- "os"
- "template"
+ "net/http"
+ "text/template"
)
type Page struct {
@@ -12,12 +15,12 @@ type Page struct {
Body []byte
}
-func (p *Page) save() os.Error {
+func (p *Page) save() error {
filename := p.Title + ".txt"
return ioutil.WriteFile(filename, p.Body, 0600)
}
-func loadPage(title string) (*Page, os.Error) {
+func loadPage(title string) (*Page, error) {
filename := title + ".txt"
body, err := ioutil.ReadFile(filename)
if err != nil {
@@ -34,14 +37,14 @@ func editHandler(w http.ResponseWriter, r *http.Request) {
if err != nil {
p = &Page{Title: title}
}
- t, _ := template.ParseFile("edit.html")
+ t, _ := template.ParseFiles("edit.html")
t.Execute(w, p)
}
func viewHandler(w http.ResponseWriter, r *http.Request) {
title := r.URL.Path[lenPath:]
p, _ := loadPage(title)
- t, _ := template.ParseFile("view.html")
+ t, _ := template.ParseFiles("view.html")
t.Execute(w, p)
}
diff --git a/doc/codelab/wiki/final-parsetemplate.go b/doc/codelab/wiki/final-parsetemplate.go
index f25012eed..c068a616f 100644
--- a/doc/codelab/wiki/final-parsetemplate.go
+++ b/doc/codelab/wiki/final-parsetemplate.go
@@ -1,11 +1,14 @@
+// Copyright 2010 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 (
- "http"
"io/ioutil"
- "os"
+ "net/http"
"regexp"
- "template"
+ "text/template"
)
type Page struct {
@@ -13,12 +16,12 @@ type Page struct {
Body []byte
}
-func (p *Page) save() os.Error {
+func (p *Page) save() error {
filename := p.Title + ".txt"
return ioutil.WriteFile(filename, p.Body, 0600)
}
-func loadPage(title string) (*Page, os.Error) {
+func loadPage(title string) (*Page, error) {
filename := title + ".txt"
body, err := ioutil.ReadFile(filename)
if err != nil {
@@ -49,21 +52,21 @@ func saveHandler(w http.ResponseWriter, r *http.Request, title string) {
p := &Page{Title: title, Body: []byte(body)}
err := p.save()
if err != nil {
- http.Error(w, err.String(), http.StatusInternalServerError)
+ http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.Redirect(w, r, "/view/"+title, http.StatusFound)
}
func renderTemplate(w http.ResponseWriter, tmpl string, p *Page) {
- t, err := template.ParseFile(tmpl+".html", nil)
+ t, err := template.ParseFiles(tmpl+".html", nil)
if err != nil {
- http.Error(w, err.String(), http.StatusInternalServerError)
+ http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
err = t.Execute(w, p)
if err != nil {
- http.Error(w, err.String(), http.StatusInternalServerError)
+ http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
diff --git a/doc/codelab/wiki/final-template.go b/doc/codelab/wiki/final-template.go
index aab536ee1..5386210a5 100644
--- a/doc/codelab/wiki/final-template.go
+++ b/doc/codelab/wiki/final-template.go
@@ -1,10 +1,13 @@
+// Copyright 2010 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 (
- "http"
"io/ioutil"
- "os"
- "template"
+ "net/http"
+ "text/template"
)
type Page struct {
@@ -12,12 +15,12 @@ type Page struct {
Body []byte
}
-func (p *Page) save() os.Error {
+func (p *Page) save() error {
filename := p.Title + ".txt"
return ioutil.WriteFile(filename, p.Body, 0600)
}
-func loadPage(title string) (*Page, os.Error) {
+func loadPage(title string) (*Page, error) {
filename := title + ".txt"
body, err := ioutil.ReadFile(filename)
if err != nil {
@@ -52,7 +55,7 @@ func saveHandler(w http.ResponseWriter, r *http.Request) {
}
func renderTemplate(w http.ResponseWriter, tmpl string, p *Page) {
- t, _ := template.ParseFile(tmpl+".html", nil)
+ t, _ := template.ParseFiles(tmpl+".html", nil)
t.Execute(w, p)
}
diff --git a/doc/codelab/wiki/final.go b/doc/codelab/wiki/final.go
index 47a4c3473..97f0a16a6 100644
--- a/doc/codelab/wiki/final.go
+++ b/doc/codelab/wiki/final.go
@@ -1,11 +1,14 @@
+// Copyright 2010 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 (
- "http"
"io/ioutil"
- "os"
+ "net/http"
"regexp"
- "template"
+ "text/template"
)
type Page struct {
@@ -13,12 +16,12 @@ type Page struct {
Body []byte
}
-func (p *Page) save() os.Error {
+func (p *Page) save() error {
filename := p.Title + ".txt"
return ioutil.WriteFile(filename, p.Body, 0600)
}
-func loadPage(title string) (*Page, os.Error) {
+func loadPage(title string) (*Page, error) {
filename := title + ".txt"
body, err := ioutil.ReadFile(filename)
if err != nil {
@@ -49,7 +52,7 @@ func saveHandler(w http.ResponseWriter, r *http.Request, title string) {
p := &Page{Title: title, Body: []byte(body)}
err := p.save()
if err != nil {
- http.Error(w, err.String(), http.StatusInternalServerError)
+ http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.Redirect(w, r, "/view/"+title, http.StatusFound)
@@ -59,7 +62,7 @@ var templates = make(map[string]*template.Template)
func init() {
for _, tmpl := range []string{"edit", "view"} {
- t := template.Must(template.ParseFile(tmpl+".html"))
+ t := template.Must(template.ParseFiles(tmpl + ".html"))
templates[tmpl] = t
}
}
@@ -67,7 +70,7 @@ func init() {
func renderTemplate(w http.ResponseWriter, tmpl string, p *Page) {
err := templates[tmpl].Execute(w, p)
if err != nil {
- http.Error(w, err.String(), http.StatusInternalServerError)
+ http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
diff --git a/doc/codelab/wiki/get.go b/doc/codelab/wiki/get.go
index c36684e3e..c6e9bf28b 100644
--- a/doc/codelab/wiki/get.go
+++ b/doc/codelab/wiki/get.go
@@ -1,12 +1,16 @@
+// Copyright 2011 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 (
- "http"
"flag"
"fmt"
"io"
"log"
"net"
+ "net/http"
"os"
"strings"
)
@@ -32,7 +36,7 @@ func main() {
log.Fatal("no url supplied")
}
var r *http.Response
- var err os.Error
+ var err error
if *post != "" {
b := strings.NewReader(*post)
r, err = http.Post(url, "application/x-www-form-urlencoded", b)
diff --git a/doc/codelab/wiki/htmlify.go b/doc/codelab/wiki/htmlify.go
index 9e7605b92..2a845a174 100644
--- a/doc/codelab/wiki/htmlify.go
+++ b/doc/codelab/wiki/htmlify.go
@@ -1,9 +1,13 @@
+// Copyright 2010 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 (
- "template"
- "os"
"io/ioutil"
+ "os"
+ "text/template"
)
func main() {
diff --git a/doc/codelab/wiki/http-sample.go b/doc/codelab/wiki/http-sample.go
index 33379a1b6..ac8cc4f2d 100644
--- a/doc/codelab/wiki/http-sample.go
+++ b/doc/codelab/wiki/http-sample.go
@@ -2,7 +2,7 @@ package main
import (
"fmt"
- "http"
+ "net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
diff --git a/doc/codelab/wiki/index.html b/doc/codelab/wiki/index.html
index 50e9db5e9..ae71a402e 100644
--- a/doc/codelab/wiki/index.html
+++ b/doc/codelab/wiki/index.html
@@ -98,7 +98,7 @@ But what about persistent storage? We can address that by creating a
</p>
<pre>
-func (p *Page) save() os.Error {
+func (p *Page) save() error {
filename := p.Title + &#34;.txt&#34;
return ioutil.WriteFile(filename, p.Body, 0600)
}
@@ -107,7 +107,7 @@ func (p *Page) save() os.Error {
<p>
This method's signature reads: "This is a method named <code>save</code> that
takes as its receiver <code>p</code>, a pointer to <code>Page</code> . It takes
-no parameters, and returns a value of type <code>os.Error</code>."
+no parameters, and returns a value of type <code>error</code>."
</p>
<p>
@@ -116,7 +116,7 @@ file. For simplicity, we will use the <code>Title</code> as the file name.
</p>
<p>
-The <code>save</code> method returns an <code>os.Error</code> value because
+The <code>save</code> method returns an <code>error</code> value because
that is the return type of <code>WriteFile</code> (a standard library function
that writes a byte slice to a file). The <code>save</code> method returns the
error value, to let the application handle it should anything go wrong while
@@ -152,7 +152,7 @@ The function <code>loadPage</code> constructs the file name from
<p>
Functions can return multiple values. The standard library function
-<code>io.ReadFile</code> returns <code>[]byte</code> and <code>os.Error</code>.
+<code>io.ReadFile</code> returns <code>[]byte</code> and <code>error</code>.
In <code>loadPage</code>, error isn't being handled yet; the "blank identifier"
represented by the underscore (<code>_</code>) symbol is used to throw away the
error return value (in essence, assigning the value to nothing).
@@ -161,11 +161,11 @@ error return value (in essence, assigning the value to nothing).
<p>
But what happens if <code>ReadFile</code> encounters an error? For example,
the file might not exist. We should not ignore such errors. Let's modify the
-function to return <code>*Page</code> and <code>os.Error</code>.
+function to return <code>*Page</code> and <code>error</code>.
</p>
<pre>
-func loadPage(title string) (*Page, os.Error) {
+func loadPage(title string) (*Page, error) {
filename := title + &#34;.txt&#34;
body, err := ioutil.ReadFile(filename)
if err != nil {
@@ -178,7 +178,7 @@ func loadPage(title string) (*Page, os.Error) {
<p>
Callers of this function can now check the second parameter; if it is
<code>nil</code> then it has successfully loaded a Page. If not, it will be an
-<code>os.Error</code> that can be handled by the caller (see the <a
+<code>error</code> that can be handled by the caller (see the <a
href="http://golang.org/pkg/os/#Error">os package documentation</a> for
details).
</p>
@@ -237,7 +237,7 @@ package main
import (
&#34;fmt&#34;
- &#34;http&#34;
+ &#34;net/http&#34;
)
func handler(w http.ResponseWriter, r *http.Request) {
@@ -337,7 +337,7 @@ HTML, and writes it to <code>w</code>, the <code>http.ResponseWriter</code>.
</p>
<p>
-Again, note the use of <code>_</code> to ignore the <code>os.Error</code>
+Again, note the use of <code>_</code> to ignore the <code>error</code>
return value from <code>loadPage</code>. This is done here for simplicity
and generally considered bad practice. We will attend to this later.
</p>
@@ -476,7 +476,7 @@ func editHandler(w http.ResponseWriter, r *http.Request) {
if err != nil {
p = &amp;Page{Title: title}
}
- t, _ := template.ParseFile(&#34;edit.html&#34;)
+ t, _ := template.ParseFiles(&#34;edit.html&#34;)
t.Execute(w, p)
}
</pre>
@@ -530,7 +530,7 @@ Modify <code>viewHandler</code> accordingly:
func viewHandler(w http.ResponseWriter, r *http.Request) {
title := r.URL.Path[lenPath:]
p, _ := loadPage(title)
- t, _ := template.ParseFile(&#34;view.html&#34;)
+ t, _ := template.ParseFiles(&#34;view.html&#34;)
t.Execute(w, p)
}
</pre>
@@ -558,7 +558,7 @@ func editHandler(w http.ResponseWriter, r *http.Request) {
}
func renderTemplate(w http.ResponseWriter, tmpl string, p *Page) {
- t, _ := template.ParseFile(tmpl+&#34;.html&#34;, nil)
+ t, _ := template.ParseFiles(tmpl+&#34;.html&#34;, nil)
t.Execute(w, p)
}
</pre>
@@ -643,14 +643,14 @@ First, let's handle the errors in <code>renderTemplate</code>:
<pre>
func renderTemplate(w http.ResponseWriter, tmpl string, p *Page) {
- t, err := template.ParseFile(tmpl+&#34;.html&#34;, nil)
+ t, err := template.ParseFiles(tmpl+&#34;.html&#34;, nil)
if err != nil {
- http.Error(w, err.String(), http.StatusInternalServerError)
+ http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
err = t.Execute(w, p)
if err != nil {
- http.Error(w, err.String(), http.StatusInternalServerError)
+ http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
</pre>
@@ -675,7 +675,7 @@ func saveHandler(w http.ResponseWriter, r *http.Request) {
p := &amp;Page{Title: title, Body: []byte(body)}
err = p.save()
if err != nil {
- http.Error(w, err.String(), http.StatusInternalServerError)
+ http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.Redirect(w, r, &#34;/view/&#34;+title, http.StatusFound)
@@ -711,7 +711,7 @@ var templates = make(map[string]*template.Template)
Then we create an <code>init</code> function, which will be called before
<code>main</code> at program initialization. The function
<code>template.Must</code> is a convenience wrapper that panics when passed a
-non-nil <code>os.Error</code> value, and otherwise returns the
+non-nil <code>error</code> value, and otherwise returns the
<code>*Template</code> unaltered. A panic is appropriate here; if the templates
can't be loaded the only sensible thing to do is exit the program.
</p>
@@ -719,7 +719,7 @@ can't be loaded the only sensible thing to do is exit the program.
<pre>
func init() {
for _, tmpl := range []string{&#34;edit&#34;, &#34;view&#34;} {
- t := template.Must(template.ParseFile(tmpl + &#34;.html&#34;))
+ t := template.Must(template.ParseFiles(tmpl + &#34;.html&#34;))
templates[tmpl] = t
}
}
@@ -741,7 +741,7 @@ the <code>Execute</code> method on the appropriate <code>Template</code> from
func renderTemplate(w http.ResponseWriter, tmpl string, p *Page) {
err := templates[tmpl].Execute(w, p)
if err != nil {
- http.Error(w, err.String(), http.StatusInternalServerError)
+ http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
</pre>
@@ -768,7 +768,7 @@ The function <code>regexp.MustCompile</code> will parse and compile the
regular expression, and return a <code>regexp.Regexp</code>.
<code>MustCompile</code> is distinct from <code>Compile</code> in that it will
panic if the expression compilation fails, while <code>Compile</code> returns
-an <code>os.Error</code> as a second parameter.
+an <code>error</code> as a second parameter.
</p>
<p>
@@ -777,11 +777,11 @@ URL, and tests it against our <code>TitleValidator</code> expression:
</p>
<pre>
-func getTitle(w http.ResponseWriter, r *http.Request) (title string, err os.Error) {
+func getTitle(w http.ResponseWriter, r *http.Request) (title string, err error) {
title = r.URL.Path[lenPath:]
if !titleValidator.MatchString(title) {
http.NotFound(w, r)
- err = os.NewError(&#34;Invalid Page Title&#34;)
+ err = errors.New(&#34;Invalid Page Title&#34;)
}
return
}
@@ -833,7 +833,7 @@ func saveHandler(w http.ResponseWriter, r *http.Request) {
p := &amp;Page{Title: title, Body: []byte(body)}
err = p.save()
if err != nil {
- http.Error(w, err.String(), http.StatusInternalServerError)
+ http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.Redirect(w, r, &#34;/view/&#34;+title, http.StatusFound)
@@ -958,7 +958,7 @@ func saveHandler(w http.ResponseWriter, r *http.Request, title string) {
p := &amp;Page{Title: title, Body: []byte(body)}
err := p.save()
if err != nil {
- http.Error(w, err.String(), http.StatusInternalServerError)
+ http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.Redirect(w, r, &#34;/view/&#34;+title, http.StatusFound)
diff --git a/doc/codelab/wiki/notemplate.go b/doc/codelab/wiki/notemplate.go
index 9cbe9ad76..33006ac95 100644
--- a/doc/codelab/wiki/notemplate.go
+++ b/doc/codelab/wiki/notemplate.go
@@ -1,10 +1,13 @@
+// Copyright 2010 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"
- "http"
"io/ioutil"
- "os"
+ "net/http"
)
type Page struct {
@@ -12,12 +15,12 @@ type Page struct {
Body []byte
}
-func (p *Page) save() os.Error {
+func (p *Page) save() error {
filename := p.Title + ".txt"
return ioutil.WriteFile(filename, p.Body, 0600)
}
-func loadPage(title string) (*Page, os.Error) {
+func loadPage(title string) (*Page, error) {
filename := title + ".txt"
body, err := ioutil.ReadFile(filename)
if err != nil {
diff --git a/doc/codelab/wiki/part1-noerror.go b/doc/codelab/wiki/part1-noerror.go
index 14cfc321a..7577b7b46 100644
--- a/doc/codelab/wiki/part1-noerror.go
+++ b/doc/codelab/wiki/part1-noerror.go
@@ -1,9 +1,12 @@
+// Copyright 2010 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"
"io/ioutil"
- "os"
)
type Page struct {
@@ -11,7 +14,7 @@ type Page struct {
Body []byte
}
-func (p *Page) save() os.Error {
+func (p *Page) save() error {
filename := p.Title + ".txt"
return ioutil.WriteFile(filename, p.Body, 0600)
}
diff --git a/doc/codelab/wiki/part1.go b/doc/codelab/wiki/part1.go
index 4b0654f8b..d7bf1be97 100644
--- a/doc/codelab/wiki/part1.go
+++ b/doc/codelab/wiki/part1.go
@@ -1,9 +1,12 @@
+// Copyright 2010 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"
"io/ioutil"
- "os"
)
type Page struct {
@@ -11,12 +14,12 @@ type Page struct {
Body []byte
}
-func (p *Page) save() os.Error {
+func (p *Page) save() error {
filename := p.Title + ".txt"
return ioutil.WriteFile(filename, p.Body, 0600)
}
-func loadPage(title string) (*Page, os.Error) {
+func loadPage(title string) (*Page, error) {
filename := title + ".txt"
body, err := ioutil.ReadFile(filename)
if err != nil {
diff --git a/doc/codelab/wiki/part2.go b/doc/codelab/wiki/part2.go
index d57c3a01f..dd4365c82 100644
--- a/doc/codelab/wiki/part2.go
+++ b/doc/codelab/wiki/part2.go
@@ -1,10 +1,13 @@
+// Copyright 2010 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"
- "http"
"io/ioutil"
- "os"
+ "net/http"
)
type Page struct {
@@ -12,12 +15,12 @@ type Page struct {
Body []byte
}
-func (p *Page) save() os.Error {
+func (p *Page) save() error {
filename := p.Title + ".txt"
return ioutil.WriteFile(filename, p.Body, 0600)
}
-func loadPage(title string) (*Page, os.Error) {
+func loadPage(title string) (*Page, error) {
filename := title + ".txt"
body, err := ioutil.ReadFile(filename)
if err != nil {
diff --git a/doc/codelab/wiki/srcextract.go b/doc/codelab/wiki/srcextract.go
index 6b5fbcb43..813e25283 100644
--- a/doc/codelab/wiki/srcextract.go
+++ b/doc/codelab/wiki/srcextract.go
@@ -1,15 +1,19 @@
+// Copyright 2010 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 (
"bytes"
"flag"
+ "go/ast"
"go/parser"
"go/printer"
- "go/ast"
"go/token"
"log"
- "template"
"os"
+ "text/template"
)
var (
diff --git a/doc/codelab/wiki/wiki.html b/doc/codelab/wiki/wiki.html
index 634babd8b..c3dee3f70 100644
--- a/doc/codelab/wiki/wiki.html
+++ b/doc/codelab/wiki/wiki.html
@@ -101,7 +101,7 @@ But what about persistent storage? We can address that by creating a
<p>
This method's signature reads: "This is a method named <code>save</code> that
takes as its receiver <code>p</code>, a pointer to <code>Page</code> . It takes
-no parameters, and returns a value of type <code>os.Error</code>."
+no parameters, and returns a value of type <code>error</code>."
</p>
<p>
@@ -110,7 +110,7 @@ file. For simplicity, we will use the <code>Title</code> as the file name.
</p>
<p>
-The <code>save</code> method returns an <code>os.Error</code> value because
+The <code>save</code> method returns an <code>error</code> value because
that is the return type of <code>WriteFile</code> (a standard library function
that writes a byte slice to a file). The <code>save</code> method returns the
error value, to let the application handle it should anything go wrong while
@@ -142,7 +142,7 @@ The function <code>loadPage</code> constructs the file name from
<p>
Functions can return multiple values. The standard library function
-<code>io.ReadFile</code> returns <code>[]byte</code> and <code>os.Error</code>.
+<code>io.ReadFile</code> returns <code>[]byte</code> and <code>error</code>.
In <code>loadPage</code>, error isn't being handled yet; the "blank identifier"
represented by the underscore (<code>_</code>) symbol is used to throw away the
error return value (in essence, assigning the value to nothing).
@@ -151,7 +151,7 @@ error return value (in essence, assigning the value to nothing).
<p>
But what happens if <code>ReadFile</code> encounters an error? For example,
the file might not exist. We should not ignore such errors. Let's modify the
-function to return <code>*Page</code> and <code>os.Error</code>.
+function to return <code>*Page</code> and <code>error</code>.
</p>
<pre>
@@ -161,7 +161,7 @@ function to return <code>*Page</code> and <code>os.Error</code>.
<p>
Callers of this function can now check the second parameter; if it is
<code>nil</code> then it has successfully loaded a Page. If not, it will be an
-<code>os.Error</code> that can be handled by the caller (see the <a
+<code>error</code> that can be handled by the caller (see the <a
href="http://golang.org/pkg/os/#Error">os package documentation</a> for
details).
</p>
@@ -297,7 +297,7 @@ HTML, and writes it to <code>w</code>, the <code>http.ResponseWriter</code>.
</p>
<p>
-Again, note the use of <code>_</code> to ignore the <code>os.Error</code>
+Again, note the use of <code>_</code> to ignore the <code>error</code>
return value from <code>loadPage</code>. This is done here for simplicity
and generally considered bad practice. We will attend to this later.
</p>
@@ -575,7 +575,7 @@ our <code>*Template</code> values, keyed by <code>string</code>
Then we create an <code>init</code> function, which will be called before
<code>main</code> at program initialization. The function
<code>template.Must</code> is a convenience wrapper that panics when passed a
-non-nil <code>os.Error</code> value, and otherwise returns the
+non-nil <code>error</code> value, and otherwise returns the
<code>*Template</code> unaltered. A panic is appropriate here; if the templates
can't be loaded the only sensible thing to do is exit the program.
</p>
@@ -622,7 +622,7 @@ The function <code>regexp.MustCompile</code> will parse and compile the
regular expression, and return a <code>regexp.Regexp</code>.
<code>MustCompile</code> is distinct from <code>Compile</code> in that it will
panic if the expression compilation fails, while <code>Compile</code> returns
-an <code>os.Error</code> as a second parameter.
+an <code>error</code> as a second parameter.
</p>
<p>