From 145b0e74247a161c4c22e1aa0c5568604a3a83b6 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Thu, 8 Feb 2024 15:17:57 +0000 Subject: Moved main to cmd/web and added routes() method Started to separate out funtionality: added an application struct and several methods (routes(), home() and a notFound() error). At the moment, the application struct does not carry any other configuration objects or a database pool connection - it is just there to get the routing going. --- cmd/web/handlers.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 cmd/web/handlers.go (limited to 'cmd/web/handlers.go') diff --git a/cmd/web/handlers.go b/cmd/web/handlers.go new file mode 100644 index 0000000..aed4103 --- /dev/null +++ b/cmd/web/handlers.go @@ -0,0 +1,18 @@ +package main + +import ( + "net/http" +) + +func (app *application) notFound(w http.ResponseWriter) { + http.Error(w, http.StatusText(401), 401) +} + +func (app *application) home(w http.ResponseWriter, r *http.Request) { + if r.URL.Path != "/" { + app.notFound(w) + return + } + + w.Write([]byte("Hello from DED")) +} -- cgit v1.2.3