Skip to content

Instantly share code, notes, and snippets.

@shiyanhui
Last active December 20, 2016 02:43
Show Gist options
  • Save shiyanhui/b55fbec7799b2cb52385d1caf65cfad8 to your computer and use it in GitHub Desktop.
Save shiyanhui/b55fbec7799b2cb52385d1caf65cfad8 to your computer and use it in GitHub Desktop.
// Router implements http router.
type Router struct {
//...
}
// RegisterHandler registers handler to the router.
func (router *Router) RegisterHandler(method, path string, handler http.HandlerFunc) {
}
// Handler returns handler mapped to method and path.
func (router *Router) Handler(method, path string) http.HandlerFunc {
}
// ServeHTTP implements the interface http.Handler.
func (router *Router) ServeHTTP(w http.ResponseWriter, req *http.Request) {
}
func main() {
handler := func(w http.ResponseWriter, req *http.Request) {
fmt.Fprint(w, "hello world")
}
router := &Router{}
router.RegisterHandler("GET", "/", handler)
http.ListenAndServe(":8080", router)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment