This commit is contained in:
2025-10-25 20:03:36 +02:00
parent 381a4e4988
commit 6224e63fa9
5 changed files with 154 additions and 1 deletions

View File

@@ -59,6 +59,36 @@ func (c *Client) Apply(pr project.Project) error {
return nil
}
func (c *Client) List() ([]project.Project, error) {
url, err := url.JoinPath(c.url, "api", "v1", "projects", "all")
if err != nil {
return nil, fmt.Errorf("failed to make url: %s", err)
}
res, err := http.Get(url)
if err != nil {
return nil, fmt.Errorf("failed to send the request to the server: %s", err)
}
defer res.Body.Close()
if res.StatusCode != 201 {
return nil, fmt.Errorf("failed to send the request to the server: %s: %s", res.Status, toError(res.Body))
}
var prs []project.Project
d := json.NewDecoder(res.Body)
if err := d.Decode(&prs); err != nil {
return nil, fmt.Errorf("failed to parse the server response, is the client you up-to-date? (reason: %s)", err)
}
for i, pr := range prs {
pr.ServerURL = c.url
prs[i] = pr
}
return prs, nil
}
func toError(body io.ReadCloser) error {
var msg SimpleError