handlers and render funcs take apart

This commit is contained in:
2024-04-17 14:24:03 -06:00
parent 54d3976f90
commit a64a032324
5 changed files with 48 additions and 21 deletions

20
main.go
View File

@@ -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)