December 2017
Intermediate to advanced
316 pages
6h 58m
English
Sometimes we need to allow requests from specific hosts. If the host is matched, then the request proceeds to the route handlers. This could be very helpful if we have multiple domains and subdomains and match them with the custom routes.
Using the Host method on the router variable, we can regulate from which hosts routes can be directed:
r := mux.NewRouter()r.Host("aaa.bbb.ccc")r.HandleFunc("/id1/id2/id3", MyHandler)
If we set this, all requests coming from the host aaa.bbb.ccc of the form http://aaa.bbb.ccc/111/222/333 will be matched. Similarly, we can regulate HTTP schemes (http, https) using Schemes and REST methods like (GET, POST) using Methods Mux functions. The program queryParameters.go explains how to use ...
Read now
Unlock full access