diff --git a/handlers.go b/handlers.go new file mode 100644 index 0000000..d22cac3 --- /dev/null +++ b/handlers.go @@ -0,0 +1,15 @@ +package main + +import ( + "net/http" +) + +// Home is the home 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 a840042..627c073 100644 --- a/main.go +++ b/main.go @@ -3,30 +3,10 @@ package main import ( "fmt" "net/http" - "text/template" ) var portNumber = ":8080" -// Home is the home 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) - return - } -} - // 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..e208804 --- /dev/null +++ b/render.go @@ -0,0 +1,16 @@ +package main + +import ( + "fmt" + "net/http" + "text/template" +) + +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) + return + } +} diff --git a/templates/about.page.tmpl b/templates/about.page.tmpl index 422657c..c485d3c 100644 --- a/templates/about.page.tmpl +++ b/templates/about.page.tmpl @@ -4,8 +4,17 @@
This is some text
+