Commit a0514459 authored by Andrew Gerrand's avatar Andrew Gerrand

codelab/wiki: switch edit/view, as they were backwards

Fixes #757.

R=rsc
CC=golang-dev
https://golang.org/cl/1064041
parent 26078c39
...@@ -34,13 +34,13 @@ func editHandler(c *http.Conn, r *http.Request) { ...@@ -34,13 +34,13 @@ func editHandler(c *http.Conn, r *http.Request) {
if err != nil { if err != nil {
p = &page{title: title} p = &page{title: title}
} }
renderTemplate(c, "view", p) renderTemplate(c, "edit", p)
} }
func viewHandler(c *http.Conn, r *http.Request) { func viewHandler(c *http.Conn, r *http.Request) {
title := r.URL.Path[lenPath:] title := r.URL.Path[lenPath:]
p, _ := loadPage(title) p, _ := loadPage(title)
renderTemplate(c, "edit", p) renderTemplate(c, "view", p)
} }
func saveHandler(c *http.Conn, r *http.Request) { func saveHandler(c *http.Conn, r *http.Request) {
......
...@@ -544,7 +544,7 @@ to its own function: ...@@ -544,7 +544,7 @@ to its own function:
func viewHandler(c *http.Conn, r *http.Request) { func viewHandler(c *http.Conn, r *http.Request) {
title := r.URL.Path[lenPath:] title := r.URL.Path[lenPath:]
p, _ := loadPage(title) p, _ := loadPage(title)
renderTemplate(c, "edit", p) renderTemplate(c, "view", p)
} }
func editHandler(c *http.Conn, r *http.Request) { func editHandler(c *http.Conn, r *http.Request) {
...@@ -553,7 +553,7 @@ func editHandler(c *http.Conn, r *http.Request) { ...@@ -553,7 +553,7 @@ func editHandler(c *http.Conn, r *http.Request) {
if err != nil { if err != nil {
p = &page{title: title} p = &page{title: title}
} }
renderTemplate(c, "view", p) renderTemplate(c, "edit", p)
} }
func renderTemplate(c *http.Conn, tmpl string, p *page) { func renderTemplate(c *http.Conn, tmpl string, p *page) {
......
...@@ -58,13 +58,15 @@ package main ...@@ -58,13 +58,15 @@ package main
import ( import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os"
) )
</pre> </pre>
<p> <p>
Both <code>fmt</code> and <code>ioutil</code> are built-in packages that We import the <code>fmt</code>, <code>ioutil</code> and <code>os</code>
we'll be using. Later, as we implement additional functionality, we will add packages from the Go standard library. Later, as we implement additional
more packages to this <code>import</code> declaration. functionality, we will add more packages to this <code>import</code>
declaration.
</p> </p>
<h2>Data Structures</h2> <h2>Data Structures</h2>
...@@ -161,7 +163,7 @@ function to return <code>*page</code> and <code>os.Error</code>. ...@@ -161,7 +163,7 @@ function to return <code>*page</code> and <code>os.Error</code>.
<p> <p>
Callers of this function can now check the second parameter; if it is 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 <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 href="http://golang.org/pkg/os/#Error">os package documentation</a> for
details). details).
...@@ -198,7 +200,7 @@ This is a sample page. ...@@ -198,7 +200,7 @@ This is a sample page.
<p> <p>
(The <code>8g</code> and <code>8l</code> commands are applicable to (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, <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>
<p> <p>
...@@ -268,6 +270,7 @@ import ( ...@@ -268,6 +270,7 @@ import (
"fmt" "fmt"
<b>"http"</b> <b>"http"</b>
"io/ioutil" "io/ioutil"
"os"
) )
</pre> </pre>
...@@ -389,7 +392,7 @@ import ( ...@@ -389,7 +392,7 @@ import (
</pre> </pre>
<p> <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: Open a new file named <code>edit.html</code>, and add the following lines:
</p> </p>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment