Simple Routing
The server built just now in the previous exercise does not do much. It just responds with a message and we cannot ask anything else. Before we can make our server more dynamic, let's imagine we want to create an online book and we want to be able to select a chapter just changing the URL. At the moment, if we browse the following pages:
http://localhost:8080 http://localhost:8080/hello http://localhost:8080/chapter1
We always see the same message, but we now want to associate different messages with these different paths on our server. We will do this by introducing some simple routing to our server.
A path is what you see after the 8080
in the URL; it can be one number, a word, a set of numbers or character groups separated by a "/". In order to do this, we will use another function of the net/http package, which is:
HandleFunc(pattern string, handler func(ResponseWriter, *Request))
Here, the pattern is the path we want to be served by...