以前在做IIS时可以实现a.a.com 与b.a.com 或是 c.b.com 同时绑定80端口,实现不同网站。 现在再用http.ListenAndServe(":80", nil) 如何实现这一功能。
求大神给出办法。谢谢了
以前在做IIS时可以实现a.a.com 与b.a.com 或是 c.b.com 同时绑定80端口,实现不同网站。 现在再用http.ListenAndServe(":80", nil) 如何实现这一功能。
求大神给出办法。谢谢了
你说的我还是不太理解。
var SiteMap = make(map[string]http.HandlerFunc) func router(){ SiteMap["/index"] = HomePage SiteMap["/error"] = ErrorPage SiteMap["/class/"] = HRootClass SiteMap["/detail/"]= HRootDetail }
func main() {
router()
//自定义WEB路由表,以/结尾的URL可以匹配它的任何子路径
mux := http.NewServeMux()
mux.HandleFunc("/",HandleRoot)
for k,v := range SiteMap {
mux.HandleFunc(k,v)
}
fmt.Println("http server Running on:", 9090)
err := http.ListenAndServe(":9090", mux)
if err != nil {
panic(err)
}
}
func HomePage(w http.ResponseWriter, r *http.Request) { log.Printf("HomePage Url:%s",r.URL) t, _ := template.ParseFiles("views/index/index.html") t.Execute(w, nil) }
我现在是这么做的路由功能。
路由功能,能不能做分级别,比如一级路由用来区分域名,二级路由来分不同页面。