Browse Source
With Mount method, we can simplify subrouter with tidy code.
```
todos := r.PathPrefix("/todos").Subrouter()
todosResource{}.SubrouterFunc(todos)
```
```
r.Mount("/todos", todosResource{}.SubrouterFunc)
```
```
type todosResource struct{}
func (rs todosResource) SubrouterFunc(r *mux.Router) {
r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
_, _ = fmt.Fprintln(w, "entry [/todos/].")
})
r.HandleFunc("/list", func(w http.ResponseWriter, r *http.Request) {
_, _ = fmt.Fprintln(w, "entry [/todos/list].")
})
}
```
pull/612/head
1 changed files with 6 additions and 0 deletions
Loading…
Reference in new issue