diff --git a/go-web-app/gowiki/TestPage2.txt b/go-web-app/gowiki/TestPage2.txt
new file mode 100644
index 0000000..6d8fbf7
--- /dev/null
+++ b/go-web-app/gowiki/TestPage2.txt
@@ -0,0 +1 @@
+This is a test page for page two.
\ No newline at end of file
diff --git a/go-web-app/gowiki/edit.html b/go-web-app/gowiki/edit.html
new file mode 100644
index 0000000..970aea7
--- /dev/null
+++ b/go-web-app/gowiki/edit.html
@@ -0,0 +1,15 @@
+
+
+
+
+
+ {{.Title}}
+
+
+
{{.Title}}
+
+
+
\ No newline at end of file
diff --git a/go-web-app/gowiki/view.html b/go-web-app/gowiki/view.html
new file mode 100644
index 0000000..5872f1e
--- /dev/null
+++ b/go-web-app/gowiki/view.html
@@ -0,0 +1,12 @@
+
+
+
+
+
+ {{ .Title }}
+
+
+
{{.Title}}
+
{{ printf "%s" .Body }}
+
+
\ No newline at end of file
diff --git a/go-web-app/gowiki/wiki.go b/go-web-app/gowiki/wiki.go
index efc8589..c8d752e 100644
--- a/go-web-app/gowiki/wiki.go
+++ b/go-web-app/gowiki/wiki.go
@@ -1,7 +1,7 @@
package main
import (
- "fmt"
+ "html/template"
"log"
"net/http"
"os"
@@ -34,11 +34,32 @@ func loadPage(title string) (*Page, error) {
return &Page{Title: title, Body: body}, nil
}
+func renderTemplate(w http.ResponseWriter, tmpl string, p *Page) {
+ t, err := template.ParseFiles(tmpl + ".html")
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+ err = t.Execute(w, p)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ }
+}
+
func viewHandler(w http.ResponseWriter, r *http.Request) {
- html := "