July 2017
Beginner to intermediate
358 pages
10h 54m
English
Whilst we are mostly going to be dealing with APIs in this book, it is a useful illustration to see how the default router and paths work by adding a secondary endpoint.
As a little exercise, try to modify the code in reading_writing_json_5/reading_writing_json_5.go to add an endpoint /cat, which returns the cat picture specified in the URI. To give you a little hint, you are going to need to use the FileServer function on the net/http package and your URI will look something like http://localhost:8080/cat/cat.jpg.
Did it work the first time or did you forget to add the StripPrefix handler?
Example 1.7 reading_writing_json_6/reading_writing_json_6.go:
21 cathandler := http.FileServer(http.Dir("./images")) 22 http.Handle("/cat/", ...Read now
Unlock full access