diff --git a/go.mod b/go.mod index 8cb88e9..eece440 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,4 @@ module github.com/joeychilson/hackernews go 1.21.5 -require ( - github.com/a-h/templ v0.2.476 // indirect - github.com/go-chi/chi/v5 v5.0.11 // indirect -) +require github.com/a-h/templ v0.2.476 diff --git a/go.sum b/go.sum index 2296c20..230ffdb 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,4 @@ github.com/a-h/templ v0.2.476 h1:+H4hP4CwK4kfJwXsE6kHeFWMGtcVOVoOm/I64uzARBk= github.com/a-h/templ v0.2.476/go.mod h1:zQ95mSyadNTGHv6k5Fm+wQU8zkBMMbHCHg7eAvUZKNM= -github.com/go-chi/chi/v5 v5.0.11 h1:BnpYbFZ3T3S1WMpD79r7R5ThWX40TaFB7L31Y8xqSwA= -github.com/go-chi/chi/v5 v5.0.11/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= diff --git a/main.go b/main.go index 4a82190..34e5fd7 100644 --- a/main.go +++ b/main.go @@ -5,8 +5,6 @@ import ( "fmt" "net/http" - "github.com/go-chi/chi/v5" - "github.com/go-chi/chi/v5/middleware" "github.com/joeychilson/hackernews/client" "github.com/joeychilson/hackernews/handlers" "github.com/joeychilson/hackernews/pages" @@ -18,37 +16,31 @@ var assets embed.FS func main() { client := client.New() - router := chi.NewRouter() - - router.Use(middleware.RequestID) - router.Use(middleware.RealIP) - router.Use(middleware.Logger) - router.Use(middleware.Recoverer) + mux := http.NewServeMux() // Redirects to GitHub repo - router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + if r.URL.Path != "/" { + pages.NotFound().Render(r.Context(), w) + return + } http.Redirect(w, r, "/news", http.StatusFound) }) // Assets - router.Handle("/assets/*", http.FileServer(http.FS(assets))) + mux.Handle("/assets/", http.FileServer(http.FS(assets))) // Pages - router.HandleFunc("/ask", handlers.HandleAsk(client)) - router.HandleFunc("/item", handlers.HandleItem(client)) - router.HandleFunc("/jobs", handlers.HandleJobs(client)) - router.HandleFunc("/newest", handlers.HandleNewest(client)) - router.HandleFunc("/news", handlers.HandleNews(client)) - router.HandleFunc("/show", handlers.HandleShow(client)) - router.HandleFunc("/submitted", handlers.HandleSubmitted(client)) - router.HandleFunc("/threads", handlers.HandleThreads(client)) - router.HandleFunc("/user", handlers.HandleUser(client)) - - // Not Found - router.HandleFunc("/*", func(w http.ResponseWriter, r *http.Request) { - pages.NotFound().Render(r.Context(), w) - }) + mux.HandleFunc("/ask", handlers.HandleAsk(client)) + mux.HandleFunc("/item", handlers.HandleItem(client)) + mux.HandleFunc("/jobs", handlers.HandleJobs(client)) + mux.HandleFunc("/newest", handlers.HandleNewest(client)) + mux.HandleFunc("/news", handlers.HandleNews(client)) + mux.HandleFunc("/show", handlers.HandleShow(client)) + mux.HandleFunc("/submitted", handlers.HandleSubmitted(client)) + mux.HandleFunc("/threads", handlers.HandleThreads(client)) + mux.HandleFunc("/user", handlers.HandleUser(client)) fmt.Println("Listening on http://localhost:8080") - http.ListenAndServe(":8080", router) + http.ListenAndServe(":8080", mux) }