How to restrict web server written in golang to allow a particular address instead of a pattern?

后端 未结 2 1978
南旧
南旧 2021-01-22 15:08

When I use

http.HandleFunc(\"/\", serveRest)  //serveRest is the method to handle request
http.ListenAndServe(\"localhost:4000\", nil)

It will

2条回答
  •  盖世英雄少女心
    2021-01-22 15:47

    You could check out https://github.com/julienschmidt/httprouter

    Per its readme:

    Only explicit matches: With other routers, like http.ServeMux, a requested URL path could match multiple patterns. Therefore they have some awkward pattern priority rules, like longest match or first registered, first matched. By design of this router, a request can only match exactly one or no route. As a result, there are also no unintended matches, which makes it great for SEO and improves the user experience.

    Here is some good video content to get started in Go.

提交回复
热议问题