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

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
主站蜘蛛池模板: 晋中市| 筠连县| 新竹县| 马龙县| 清新县| 阳泉市| 修水县| 竹北市| 九江县| 牟定县| 玛沁县| 汨罗市| 淮滨县| 尼勒克县| 沧州市| 南陵县| 盐城市| 蒙城县| 高密市| 色达县| 云阳县| 马关县| 龙门县| 濉溪县| 云阳县| 雷山县| 恩施市| 姜堰市| 临西县| 石棉县| 清流县| 呼伦贝尔市| 德化县| 蛟河市| 隆德县| 广汉市| 巴林左旗| 得荣县| 金溪县| 淄博市| 道真|