Add home page template
This commit is contained in:
parent
d1cd20225b
commit
3b4543c77a
10
main.go
10
main.go
@ -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
1
templates/home.gohtml
Normal file
@ -0,0 +1 @@
|
||||
<h1>Welcome to my awesome site!</h1>
|
||||
Loading…
x
Reference in New Issue
Block a user