Here’s my testing code:
import (
"fmt"
"net/http"
"github.com/gorilla/mux"
)
func main() {
multiplex := mux.NewRouter()
multiplex.HandleFunc("/", WelcomeHandler)
multiplex.HandleFunc("/directory/", DirectoryHandler)
multiplex.HandleFunc("/dashboard/{userId}/", DashboardHandler)
http.ListenAndServe("127.0.0.1:8000", multiplex)
}
// WelcomeHandler Handles requests for welcome Page
func WelcomeHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "<h1>Welcome Page!</h1>")
}
// DirectoryHandler Handles requests for directory
func DirectoryHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "<h1>Directory Page!</h1>")
}
// DashboardHandler Handles requests for dashboard
func DashboardHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "<h1>Dashboard!</h1>")
}
I’m curious why it is that if I go to the /dashboard/{anything other than exactly userId}/ that it 404’s by default. I assumed it was going to do something to auto parse the url for data retrieval, but I appear to have been wrong.