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

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
主站蜘蛛池模板: 永州市| 晋中市| 赣榆县| 武穴市| 丹阳市| 曲麻莱县| 长顺县| 福鼎市| 托里县| 东宁县| 墨玉县| 徐州市| 唐河县| 会宁县| 海阳市| 乡城县| 科技| 桦川县| 固阳县| 上饶县| 玛多县| 鸡泽县| 滦平县| 七台河市| 桂平市| 合作市| 红原县| 平安县| 务川| 清流县| 乌兰浩特市| 三亚市| 南召县| 和田县| 远安县| 麻城市| 涞源县| 留坝县| 宁海县| 唐海县| 雷山县|