我写了一个demo,
访问
```
localhost:3005/host
```
但是报404,为啥啊,但是去掉Host("localhost")就正确了。
```
package main
import (
"fmt"
"log"
"net/http"
"github.com/gorilla/mux"
)
func main() {
r := mux.NewRouter()
r.HandleFunc("/host", hostHandler).Host("localhost")
// r.Host("localhost").Path("/host").HandlerFunc(hostHandler)
err := http.ListenAndServe(":3005", r)
if err != nil {
log.Fatal("ListenAndServe error: ", err)
}
}
func hostHandler(w http.ResponseWriter, r *http.Request) {
fmt.Print("hhahadaf")
fmt.Fprint(w, "hello")
}
```
有疑问加站长微信联系(非本文作者)