Cloud Native programming with Golang
上QQ阅读APP看书,第一时间看更新

Gorilla web toolkit

Now that we have covered how web Restful APIs work, it's time to understand how to best implement them in Go. The Go language comes with a very powerful web package in the standard library; Go also enjoys the support of numerous third-party packages. In this book, we will use a very popular Go web third-party toolkit called Gorilla web toolkit. The Gorilla web toolkit consists of a collection of Go packages that together helps build powerful web applications quickly and efficiently.

The key package in the Gorilla web toolkit ecosystem is called gorilla/mux. The mux package is described in the package documentation as a request router and dispatcher. This is basically a software component that accepts an incoming HTTP request, then decides what to do based on the nature of the request. For example, let's assume that a client sends an HTTP request to our web server. The HTTP router dispatcher component in our web server can then detect that the incoming request includes a GET method with a relative URL of ../events/id/1345. It will then retrieve the information of the event ID 1345 and send it back to the client.