go-proxy ls-route now query api server first, then fallback to read from config file

This commit is contained in:
yusing
2024-09-30 15:56:03 +08:00
parent b38d7595a7
commit 9065d990e5
4 changed files with 28 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
package utils
import (
"encoding/json"
"fmt"
"io"
"net/http"
@@ -29,3 +30,20 @@ func ReloadServer() E.NestedError {
}
return nil
}
func ListRoutes() (map[string]map[string]any, E.NestedError) {
resp, err := httpClient.Get(fmt.Sprintf("%s/v1/list/routes", common.APIHTTPURL))
if err != nil {
return nil, E.From(err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, E.Failure("list routes").Extraf("status code: %v", resp.StatusCode)
}
var routes map[string]map[string]any
err = json.NewDecoder(resp.Body).Decode(&routes)
if err != nil {
return nil, E.From(err)
}
return routes, nil
}