【发布时间】:2014-09-28 16:14:20
【问题描述】:
我无法让 gorilla mux 工作..
当请求http://www.localhost:9000 时,Web 服务器会返回 404 page not found
但这工作 http://localhost:9000/ 并打印 Hello world
package main
import (
"net/http"
"fmt"
"log"
"github.com/gorilla/mux"
)
func Handler(w http.ResponseWriter, r *http.Request){
fmt.Fprint(w, "Hello world")
}
func main(){
r := mux.NewRouter()
r.Host("www.localhost")
r.HandleFunc("/", Handler)
err := http.ListenAndServe(":9000", r)
if err != nil {
log.Fatal("ListenAndServe error: ", err)
}
}
【问题讨论】:
-
/etc/hosts 已设置.. 网络服务器响应
www.localhost但404