例如,我有一个func来处理" / items / {item-id}"和另一个处理" / items / request-task"的函数。如何使第一个func忽略" / items / request-task"并匹配其余的?
答案 0 :(得分:0)
package main
import (
"net/http"
"github.com/gorilla/mux"
)
func main() {
r := mux.NewRouter()
r.HandleFunc("/items/request-task", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("task."))
}) // task HandleFunc before other
r.HandleFunc("/items/{item-id}", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("other."))
})
http.Handle("/", r)
http.ListenAndServe(":8080", nil)
}