Compare commits
No commits in common. "1e61052ec1b9493a8d587caaf97d8d8cb32a6d24" and "3b4543c77aee959079766684b2beffa9779cbadb" have entirely different histories.
1e61052ec1
...
3b4543c77a
34
main.go
34
main.go
@ -3,40 +3,36 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
|
||||
func executeTemplate(w http.ResponseWriter, filepath string) {
|
||||
func homeHandler(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf8")
|
||||
tpl, err := template.ParseFiles(filepath)
|
||||
tpl, err := template.ParseFiles("templates/home.gohtml")
|
||||
if err != nil {
|
||||
log.Printf("Error parsing template: %v", err)
|
||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||
return
|
||||
panic(err)
|
||||
}
|
||||
err = tpl.Execute(w, nil)
|
||||
if err != nil {
|
||||
log.Printf("Error executing template: %v", err)
|
||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||
return
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func homeHandler(w http.ResponseWriter, r *http.Request) {
|
||||
path := filepath.Join("templates", "home.gohtml")
|
||||
executeTemplate(w, path)
|
||||
}
|
||||
func contactHandler(w http.ResponseWriter, r *http.Request) {
|
||||
path := filepath.Join("templates", "contact.gohtml")
|
||||
executeTemplate(w, path)
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf8")
|
||||
fmt.Fprint(w, "<h1>Contact Page</h1><p>To get in touch, email me at <a href=\"mailto:example@example.com\">example@example.com</a></p>")
|
||||
}
|
||||
func faqHandler(w http.ResponseWriter, r *http.Request) {
|
||||
path := filepath.Join("templates", "faq.gohtml")
|
||||
executeTemplate(w, path)
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf8")
|
||||
fmt.Fprint(w, `
|
||||
<h1>FAQ</h1>
|
||||
<hr>
|
||||
<h3>Is this a real website?</h3>
|
||||
<p>No.</p>
|
||||
<h3>I Can Has Cheezburger?</h3>
|
||||
<p>No.</p>
|
||||
`)
|
||||
}
|
||||
|
||||
func notFoundHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@ -1,2 +0,0 @@
|
||||
<h1>Contact Page</h1>
|
||||
<p>To get in touch, email me at <a href="mailto:example@example.com">example@example.com</a></p>
|
||||
@ -1,6 +0,0 @@
|
||||
<h1>FAQ</h1>
|
||||
<hr>
|
||||
<h3>Is this a real website?</h3>
|
||||
<p>No.</p>
|
||||
<h3>I Can Has Cheezburger?</h3>
|
||||
<p>No.</p>
|
||||
Loading…
x
Reference in New Issue
Block a user