大猩猩复用器子路由器空路径

i want to create a /user subrouter as following

user := app.Router.PathPrefix("/user").Subrouter()
user.HandleFunc("/create", (&controllers.User{c}).Create)
user.HandleFunc("", (&controllers.User{c}).Create).Methods("POST")
user.HandleFunc("", (&controllers.User{c}).FindAll).Methods("GET")
user.HandleFunc("/{id}", (&controllers.User{c}).Update).Methods("PUT")
user.HandleFunc("/{id}", (&controllers.User{c}).Destroy).Methods("DELETE")
user.HandleFunc("/{id}", (&controllers.User{c}).FindOne).Methods("GET")

the problem is the domain/user doenst work. i can do this

user.HandleFunc("/", (&controllers.User{c}).Create).Methods("POST")

but then it only matches domain/user/ any idea how to fix this

If setting strict slash to true won't work for you, then you may have to handle the routes without a slash in the router rather than using a subrouter:

app.Router.HandleFunc("/user", (&controllers.User{c}).Create).Methods("POST")
app.Router.HandleFunc("/user", (&controllers.User{c}).FindAll).Methods("GET")

You could set the router's strict slash to true so that /domain/user redirects to /domain/user/.

You would need to have at the top:

app.Router.StrictSlash(true)

and set the routes to:

user.HandleFunc("/", (&controllers.User{c}).Create).Methods("POST")
user.HandleFunc("/", (&controllers.User{c}).FindAll).Methods("GET")