Reputation: 652
I am trying to read routes from json and appending them to mux , but instead of appending it seems to overwrite routes.
Code snippet
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))
}
Upvotes: 1
Views: 2163
Reputation: 652
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)
}
Upvotes: 1