File tree Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -26,11 +26,19 @@ func loadPage(title string) (*Page, error) {
26
26
return & Page {Title : title , Body : body }, nil
27
27
}
28
28
29
+ func renderTemplate (w http.ResponseWriter , tmpl string , p * Page ) {
30
+ t , _ := template .ParseFiles (tmpl + ".html" )
31
+ t .Execute (w , p )
32
+ }
33
+
29
34
func viewHandler (w http.ResponseWriter , r * http.Request ) {
30
35
title := r .URL .Path [len ("/view/" ):]
31
- p , _ := loadPage (title )
32
- t , _ := template .ParseFiles ("view.html" )
33
- t .Execute (w , p )
36
+ p , err := loadPage (title )
37
+ if err != nil {
38
+ http .Redirect (w , r , "/edit/" + title , http .StatusFound )
39
+ return
40
+ }
41
+ renderTemplate (w , "view" , p )
34
42
}
35
43
36
44
func editHandler (w http.ResponseWriter , r * http.Request ) {
@@ -39,8 +47,7 @@ func editHandler(w http.ResponseWriter, r *http.Request) {
39
47
if err != nil {
40
48
p = & Page {Title : title }
41
49
}
42
- t , _ := template .ParseFiles ("edit.html" )
43
- t .Execute (w , p )
50
+ renderTemplate (w , "edit" , p )
44
51
}
45
52
46
53
func main () {
You can’t perform that action at this time.
0 commit comments