diff options
Diffstat (limited to 'doc/codelab/wiki/final.go')
| -rw-r--r-- | doc/codelab/wiki/final.go | 19 | 
1 files changed, 11 insertions, 8 deletions
| 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)  	}  } | 
