官术网_书友最值得收藏!

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
主站蜘蛛池模板: 通许县| 宁城县| 油尖旺区| 平乐县| 皮山县| 长阳| 家居| 英吉沙县| 辽中县| 望江县| 扎兰屯市| 厦门市| 内丘县| 桐梓县| 乐昌市| 长治县| 东莞市| 清苑县| 进贤县| 正宁县| 无为县| 天气| 广昌县| 忻城县| 新平| 砀山县| 文昌市| 黔西县| 邯郸县| 张北县| 河西区| 新巴尔虎左旗| 吕梁市| 垣曲县| 曲沃县| 若羌县| 尉犁县| 营山县| 康乐县| 揭阳市| 岳阳市|