This commit is contained in:
committed by
GitHub
parent
f43f2786d0
commit
6c5288a5f8
+13
-1
@@ -1,6 +1,7 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"expvar"
|
||||
"net/http"
|
||||
@@ -37,8 +38,19 @@ func registerApiRoutes(apiRoutes *mux.Router) {
|
||||
}
|
||||
|
||||
func routesListHandler(writer http.ResponseWriter, _ *http.Request) {
|
||||
type serverRoute = struct {
|
||||
Backend string `json:"backend"`
|
||||
ScalingTarget string `json:"scalingTarget"`
|
||||
}
|
||||
|
||||
mappings := Routes.GetMappings()
|
||||
bytes, err := json.Marshal(mappings)
|
||||
routes := make(map[string]serverRoute, len(mappings))
|
||||
for k := range mappings {
|
||||
backend, address, scalingTarget, _, _ := Routes.FindBackendForServerAddress(context.Background(), k)
|
||||
routes[address] = serverRoute{Backend: backend, ScalingTarget: scalingTarget}
|
||||
}
|
||||
|
||||
bytes, err := json.Marshal(routes)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Error("Failed to marshal mappings")
|
||||
writer.WriteHeader(http.StatusInternalServerError)
|
||||
|
||||
Reference in New Issue
Block a user