Skip to content

Instantly share code, notes, and snippets.

@elico
Created January 11, 2016 00:51
Show Gist options
  • Save elico/170b4d98b52b1da58d56 to your computer and use it in GitHub Desktop.
Save elico/170b4d98b52b1da58d56 to your computer and use it in GitHub Desktop.
A trial to use gorilla mux router Walk function
package main
import (
"fmt"
"github.com/gorilla/mux"
"net/http"
)
func signupHandler(w http.ResponseWriter, request *http.Request) {
fmt.Fprintf(w, "signup")
}
func play(route *mux.Route, router *mux.Router, ancestors []*mux.Route) error {
fmt.Println(route.GetName())
fmt.Println(route)
fmt.Println(router)
fmt.Println(ancestors)
return nil
}
func main() {
router := mux.NewRouter().StrictSlash(true)
router.HandleFunc("/control/dunno_flip/hola/hola", signupHandler)
router.HandleFunc("/control/db_stop/1/", signupHandler)
router.HandleFunc("/control/db_close/", signupHandler)
router.HandleFunc("/control/db_start/", signupHandler)
router.HandleFunc("/", signupHandler)
router.Walk(play)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment