In Chapter 1, Introducing and Setting Up, we produced a very basic URL endpoint that allowed static file serving.
The following are the simple routes we produced for that example:
func main() { http.HandleFunc("/static",serveStatic) http.HandleFunc("/",serveDynamic) http.ListenAndServe(Port,nil) }
In review, you can see two endpoints, /static
and /
, which either serve a single static file or generate output to the http.ResponseWriter
.
We can have any number of routers sitting side by side. However, consider a scenario where we have a basic website with about, contact, and staff pages, with each residing in /var/www/about/index.html
, /var/www/contact.html
, and /var/www/staff/home.html
. While it's an intentionally obtuse example, it demonstrates the limitations of Go's built-in and unmodified routing system. We cannot route all requests to the same directory locally, we need something that provides more malleable URLs.
3.146.176.145