- Hands-On RESTful Web Services with Go
- Naren Yellavula
- 155字
- 2021-06-24 17:04:27
Fundamentals of gorilla/mux
The gorilla/mux package primarily helps to create routers, similar to httprouter. The difference between both is the attachment of a handler function to a given URL. If we observe, the gorilla/mux way of attaching a handler is similar to that of basic ServeMux. Unlike httprouter, gorilla/mux wraps all the information of an HTTP request into a single request object.
The three important tools provided in the gorilla/mux API are:
- The mux.NewRouter method
- The *http.Request object
- The *http.ResponseWriter object
The NewRouter method creates a new router object. That object basically maps a route to a function handler. gorilla/mux passes a modified *http.Request and *http.ResponseWriter object to the function handler. These special objects have lots of additional information about headers, path parameters, request body, and query parameters. Let us explain how to define and use different routers in gorilla/mux with two common types:
- Path-based matching
- Query-based matching
- Spring Boot 2實戰之旅
- 數據庫系統原理及MySQL應用教程
- Android Native Development Kit Cookbook
- Linux Device Drivers Development
- Visual FoxPro程序設計
- Learning AngularJS for .NET Developers
- C++編程兵書
- 從零開始學Python網絡爬蟲
- Mastering Elixir
- 愛上C語言:C KISS
- Moodle 3 Administration(Third Edition)
- Android移動應用項目化教程
- Modernizing Legacy Applications in PHP
- UML基礎與Rose建模實用教程(第三版)
- 嵌入式C編程實戰