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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
"github.com/go-chi/chi/v5"
|
"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")
|
w.Header().Set("Content-Type", "text/html; charset=utf8")
|
||||||
tpl, err := template.ParseFiles(filepath)
|
tpl, err := template.ParseFiles("templates/home.gohtml")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error parsing template: %v", err)
|
panic(err)
|
||||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
err = tpl.Execute(w, nil)
|
err = tpl.Execute(w, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error executing template: %v", err)
|
panic(err)
|
||||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
func contactHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
path := filepath.Join("templates", "contact.gohtml")
|
w.Header().Set("Content-Type", "text/html; charset=utf8")
|
||||||
executeTemplate(w, path)
|
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) {
|
func faqHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
path := filepath.Join("templates", "faq.gohtml")
|
w.Header().Set("Content-Type", "text/html; charset=utf8")
|
||||||
executeTemplate(w, path)
|
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) {
|
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