From 7a7042bc668bebefdf670277d75d9dc1bfb48835 Mon Sep 17 00:00:00 2001 From: lbenedar Date: Wed, 4 Mar 2026 15:21:35 +0300 Subject: [PATCH] ch3.5 --- cmd/web/main.go | 10 +--------- cmd/web/routes.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 cmd/web/routes.go diff --git a/cmd/web/main.go b/cmd/web/main.go index 36a54e4..d440ed1 100644 --- a/cmd/web/main.go +++ b/cmd/web/main.go @@ -31,18 +31,10 @@ func main() { infoLog: infoLog, } - mux := http.NewServeMux() - fileServer := http.FileServer(http.Dir("./ui/static/")) - - mux.HandleFunc("/", app.home) - mux.HandleFunc("/snippet/view", app.snippetView) - mux.HandleFunc("/snippet/create", app.snippetCreate) - mux.Handle("/static/", http.StripPrefix("/static", fileServer)) - srv := &http.Server{ Addr: cfg.addr, ErrorLog: errorLog, - Handler: mux, + Handler: app.routes(), } infoLog.Printf("Starting server on %s", cfg.addr) diff --git a/cmd/web/routes.go b/cmd/web/routes.go new file mode 100644 index 0000000..8d37b37 --- /dev/null +++ b/cmd/web/routes.go @@ -0,0 +1,16 @@ +package main + +import "net/http" + +func (app *application) routes() *http.ServeMux { + mux := http.NewServeMux() + + fileServer := http.FileServer(http.Dir("./ui/static/")) + mux.Handle("/static/", http.StripPrefix("/static", fileServer)) + + mux.HandleFunc("/", app.home) + mux.HandleFunc("/snippet/view", app.snippetView) + mux.HandleFunc("/snippet/create", app.snippetCreate) + + return mux +}