carousell/Orion

Routes are not mapped in order

Closed this issue · 0 comments

func (h *httpHandler) Run(httpListener net.Listener) error {
r := mux.NewRouter()
fmt.Println("Mapped URLs: ")
for url, info := range h.paths {
if strings.TrimSpace(info.encoderPath) != "" && info.encoderPath != url {
continue
}
routeURL := url
r.Methods(info.httpMethod...).Path(url).Handler(h.getHTTPHandler(url))
if !strings.HasSuffix(url, "/") {
routeURL = url + "/"
r.Methods(info.httpMethod...).Path(url + "/").Handler(h.getHTTPHandler(url))
}
fmt.Println("\t", info.httpMethod, routeURL)
}
h.svr = &http.Server{
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
Handler: r,
}
return h.svr.Serve(httpListener)
}

When mapping registered URLs, a map is iterated through, which causes the URLs to not be mapped in the order of registration.