r := mux.NewRouter() r.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello from the other side!") })
r.HandleFunc("/users/{id}", func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) fmt.Fprintf(w, "User with ID %s", vars["id"]) })
articlesRouter := r.PathPrefix("/articles").Subrouter() articlesRouter.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Articles homepage") })This sets up a subrouter for the "/articles" endpoint, with a specific handler for the homepage ("/"). Overall, the go github.com/gorilla/mux package library is a very useful tool for building HTTP services in Go, and provides many advanced features for routing and handling requests.