0

For example, I have a func that handles "/items/{item-id}" and another func that handles "/items/request-task". How to make the first func ignores "/items/request-task" and match the rest?

  • ```mux``` allows you control priorities of handlers just by their order. If you have several suitable patterns, the earliest defined handler will be called. – bayrinat Feb 26 '18 at 07:31

1 Answers1

0

like this.

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)
}
No_20
  • 101
  • 3