This commit is contained in:
DeveloperDurp 2024-07-28 09:40:32 -05:00
parent 035a813154
commit 67b4818274
10 changed files with 181 additions and 33 deletions

36
main.go
View file

@ -2,31 +2,29 @@ package main
import (
"fmt"
"html/template"
"net/http"
"time"
"gitlab.com/developerdurp/durpweb/pkg/catfact"
"gitlab.com/developerdurp/durpweb/pkg/index"
"gitlab.com/developerdurp/middleware"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
tmpl, err := template.ParseFiles("index.html")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
data := struct {
Message string
}{
Message: "Hello World",
}
router := http.NewServeMux()
tmpl.Execute(w, data)
})
stack := middleware.CreateStack(
middleware.Logging,
)
http.HandleFunc("/time", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Current Time: " + time.Now().Format(time.RFC1123)))
})
router.HandleFunc("/", index.GetIndex)
router.HandleFunc("/catfact", catfact.GetCatFact)
fmt.Println("Started http server on port :8080")
http.ListenAndServe(":8080", nil)
server := http.Server{
Addr: ":8080",
Handler: stack(router),
}
fmt.Println("Server listening on port :8080")
server.ListenAndServe()
}