我正在尝试从json读取路由并将它们附加到多路复用器,但不是附加它似乎覆盖路由。
代码段
func main() {
configLoader()
dispatchMux := http.NewServeMux()
for _, site := range ServerConfigData.Sites {
append(dispatchMux, site.Incomming, site.Forward)
}
// Start the server
color.Green("Server Spinned Up on 2096")
http.ListenAndServe(":2096", dispatchMux)
}
// Route Appender
func append(mux *http.ServeMux, incomming, forward string) {
color.Yellow("Starting ", incomming, " on ", forward, "\n")
parsedURL, _ := url.Parse(forward)
mux.Handle(incomming, httputil.NewSingleHostReverseProxy(parsedURL))
}
答案 0 :(得分:0)
func main() {
configLoader()
dispatchMux := http.NewServeMux()
for _, site := range ServerConfigData.Sites {
//Previously code of append function
parsedURL, _ := url.Parse(site.Forward)
fmt.Println(site.Incomming)
dispatchMux.Handle(site.Incomming, httputil.NewSingleHostReverseProxy(parsedURL))
}
// Start the server
color.Green("Server Spinned Up on 2096")
http.ListenAndServe(":80", dispatchMux)
}