Add home page template

This commit is contained in:
Lucas Schumacher 2024-07-31 20:29:15 -04:00
parent d1cd20225b
commit 3b4543c77a
2 changed files with 10 additions and 1 deletions

10
main.go
View File

@ -2,6 +2,7 @@ package main
import (
"fmt"
"html/template"
"net/http"
"github.com/go-chi/chi/v5"
@ -9,7 +10,14 @@ import (
func homeHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf8")
fmt.Fprint(w, "<h1>Welcome to my awesome site!</h1>")
tpl, err := template.ParseFiles("templates/home.gohtml")
if err != nil {
panic(err)
}
err = tpl.Execute(w, nil)
if err != nil {
panic(err)
}
}
func contactHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf8")

1
templates/home.gohtml Normal file
View File

@ -0,0 +1 @@
<h1>Welcome to my awesome site!</h1>