mirror of
https://github.com/acepanel/panel.git
synced 2026-02-04 06:47:20 +08:00
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package api
|
|
|
|
import "fmt"
|
|
|
|
type Environment struct {
|
|
Type string `json:"type"`
|
|
Slug string `json:"slug"`
|
|
Name string `json:"name"`
|
|
Version string `json:"version"`
|
|
Description string `json:"description"`
|
|
Order int `json:"order"`
|
|
}
|
|
|
|
type Environments []*Environment
|
|
|
|
// Environments 返回所有环境
|
|
func (r *API) Environments() (*Environments, error) {
|
|
resp, err := r.client.R().SetResult(&Response{}).Get("/environments")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if !resp.IsSuccess() {
|
|
return nil, fmt.Errorf("failed to get environments: %s", resp.String())
|
|
}
|
|
|
|
environments, err := getResponseData[Environments](resp)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return environments, nil
|
|
}
|
|
|
|
// EnvironmentCallback 环境下载回调
|
|
func (r *API) EnvironmentCallback(typ, slug string) error {
|
|
resp, err := r.client.R().
|
|
SetResult(&Response{}).
|
|
Post(fmt.Sprintf("/environments/%s/%s/callback", typ, slug))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if !resp.IsSuccess() {
|
|
return fmt.Errorf("failed to callback environment: %s", resp.String())
|
|
}
|
|
|
|
return nil
|
|
}
|