if err != nil {
p = &page{title: title}
}
- renderTemplate(c, "view", p)
+ renderTemplate(c, "edit", p)
}
func viewHandler(c *http.Conn, r *http.Request) {
title := r.URL.Path[lenPath:]
p, _ := loadPage(title)
- renderTemplate(c, "edit", p)
+ renderTemplate(c, "view", p)
}
func saveHandler(c *http.Conn, r *http.Request) {
func viewHandler(c *http.Conn, r *http.Request) {
title := r.URL.Path[lenPath:]
p, _ := loadPage(title)
- renderTemplate(c, "edit", p)
+ renderTemplate(c, "view", p)
}
func editHandler(c *http.Conn, r *http.Request) {
if err != nil {
p = &page{title: title}
}
- renderTemplate(c, "view", p)
+ renderTemplate(c, "edit", p)
}
func renderTemplate(c *http.Conn, tmpl string, p *page) {
import (
"fmt"
"io/ioutil"
+ "os"
)
</pre>
<p>
-Both <code>fmt</code> and <code>ioutil</code> are built-in packages that
-we'll be using. Later, as we implement additional functionality, we will add
-more packages to this <code>import</code> declaration.
+We import the <code>fmt</code>, <code>ioutil</code> and <code>os</code>
+packages from the Go standard library. Later, as we implement additional
+functionality, we will add more packages to this <code>import</code>
+declaration.
</p>
<h2>Data Structures</h2>
<p>
Callers of this function can now check the second parameter; if it is
-<code>nil</code> then it has succesfully loaded a page. If not, it will be an
+<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
href="http://golang.org/pkg/os/#Error">os package documentation</a> for
details).
<p>
(The <code>8g</code> and <code>8l</code> commands are applicable to
<code>GOARCH=386</code>. If you're on an <code>amd64</code> system,
-subtitute 6's for the 8's.)
+substitute 6's for the 8's.)
</p>
<p>
"fmt"
<b>"http"</b>
"io/ioutil"
+ "os"
)
</pre>
</pre>
<p>
-Let's create a template file containg the HTML form.
+Let's create a template file containing the HTML form.
Open a new file named <code>edit.html</code>, and add the following lines:
</p>