diff --git a/handlers.go b/handlers.go new file mode 100644 index 0000000..85be798 --- /dev/null +++ b/handlers.go @@ -0,0 +1,15 @@ +package main + +import ( + "net/http" +) + +// Home is the about page handler +func Home(w http.ResponseWriter, r *http.Request) { + renderTemplate(w, "home.page.tmpl") +} + +// About is the about page handler +func About(w http.ResponseWriter, r *http.Request) { + renderTemplate(w, "about.page.tmpl") +} diff --git a/main.go b/main.go index 422a8e1..0c7bb13 100644 --- a/main.go +++ b/main.go @@ -2,30 +2,11 @@ package main import ( "fmt" - "html/template" "net/http" ) const portNumber = ":8080" -// Home is the about page handler -func Home(w http.ResponseWriter, r *http.Request) { - renderTemplate(w, "home.page.tmpl") -} - -// About is the about page handler -func About(w http.ResponseWriter, r *http.Request) { - renderTemplate(w, "about.page.tmpl") -} - -func renderTemplate(w http.ResponseWriter, tmpl string) { - parsedTemplate, _ := template.ParseFiles("./templates/" + tmpl) - err := parsedTemplate.Execute(w, nil) - if err != nil { - fmt.Println("error parsing template:", err) - } -} - // main is the main application function func main() { http.HandleFunc("/", Home) diff --git a/render.go b/render.go new file mode 100644 index 0000000..97f7f6c --- /dev/null +++ b/render.go @@ -0,0 +1,16 @@ +package main + +import ( + "fmt" + "html/template" + "net/http" +) + +// renderTemplate renders a template file +func renderTemplate(w http.ResponseWriter, tmpl string) { + parsedTemplate, _ := template.ParseFiles("./templates/" + tmpl) + err := parsedTemplate.Execute(w, nil) + if err != nil { + fmt.Println("error parsing template:", err) + } +} diff --git a/templates/about.page.tmpl b/templates/about.page.tmpl index 9803cb3..b8c05cc 100644 --- a/templates/about.page.tmpl +++ b/templates/about.page.tmpl @@ -4,12 +4,21 @@ - + About page + -

This is the about page

+
+
+
+

This is the about page

+

This is the content

+
+
+
diff --git a/templates/home.page.tmpl b/templates/home.page.tmpl index 68ab72a..ecde361 100644 --- a/templates/home.page.tmpl +++ b/templates/home.page.tmpl @@ -4,12 +4,21 @@ - + Home page + -

This is the home page

+
+
+
+

This is the home page

+

This is the content

+
+
+