2025-09-02 16:16:34 +02:00
|
|
|
package client
|
|
|
|
|
|
2025-09-05 15:54:24 +02:00
|
|
|
import "fmt"
|
|
|
|
|
|
|
|
|
|
type Responses[T any] struct {
|
|
|
|
|
Responses []Response[T]
|
|
|
|
|
StatusCode int
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *Responses[T]) GetData() []T {
|
|
|
|
|
var data []T
|
|
|
|
|
for _, v := range r.Responses {
|
|
|
|
|
if v.HasData() {
|
|
|
|
|
data = append(data, *v.Data)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return data
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *Responses[T]) GetMessages() []string {
|
|
|
|
|
var messages []string
|
|
|
|
|
for _, v := range r.Responses {
|
|
|
|
|
if v.HasData() {
|
|
|
|
|
messages = append(messages, v.Message)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return messages
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *Responses[T]) IsSuccessful() bool {
|
|
|
|
|
return r.StatusCode < 400 && r.StatusCode > 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *Responses[T]) Error() error {
|
|
|
|
|
if r.IsSuccessful() {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fmt.Errorf("error with status code %v and messages %v", r.StatusCode, r.GetMessages())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Response[T any] struct {
|
|
|
|
|
Data *T `json:"data"`
|
|
|
|
|
Message string `json:"message"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (res *Response[T]) HasData() bool {
|
|
|
|
|
return res.Data != nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (res *Response[T]) IsMessage() bool {
|
|
|
|
|
return res.Message != ""
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-02 16:16:34 +02:00
|
|
|
type NewAppInstanceInput struct {
|
|
|
|
|
Region string `json:"region"`
|
|
|
|
|
AppInst AppInstance `json:"appinst"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type AppInstance struct {
|
2025-09-03 13:36:57 +02:00
|
|
|
Key AppInstanceKey `json:"key"`
|
2025-09-05 15:54:24 +02:00
|
|
|
AppKey AppKey `json:"app_key,omitzero"`
|
|
|
|
|
Flavor Flavor `json:"flavor,omitzero"`
|
2025-09-03 15:36:49 +02:00
|
|
|
State string `json:"state,omitempty"`
|
|
|
|
|
PowerState string `json:"power_state,omitempty"`
|
2025-09-02 16:16:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type AppInstanceKey struct {
|
|
|
|
|
Organization string `json:"organization"`
|
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
CloudletKey CloudletKey `json:"cloudlet_key"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type CloudletKey struct {
|
|
|
|
|
Organization string `json:"organization"`
|
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type AppKey struct {
|
|
|
|
|
Organization string `json:"organization"`
|
2025-09-04 11:19:07 +02:00
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
|
Version string `json:"version,omitempty"`
|
2025-09-02 16:16:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Flavor struct {
|
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type NewAppInput struct {
|
|
|
|
|
Region string `json:"region"`
|
|
|
|
|
App App `json:"app"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type App struct {
|
|
|
|
|
Key AppKey `json:"key"`
|
2025-09-05 15:54:24 +02:00
|
|
|
Deployment string `json:"deployment,omitempty"`
|
|
|
|
|
ImageType string `json:"image_type,omitempty"`
|
|
|
|
|
ImagePath string `json:"image_path,omitempty"`
|
|
|
|
|
AllowServerless bool `json:"allow_serverless,omitempty"`
|
|
|
|
|
DefaultFlavor Flavor `json:"defaultFlavor,omitempty"`
|
|
|
|
|
ServerlessConfig any `json:"serverless_config,omitempty"`
|
|
|
|
|
DeploymentGenerator string `json:"deployment_generator,omitempty"`
|
|
|
|
|
DeploymentManifest string `json:"deployment_manifest,omitempty"`
|
2025-09-02 16:16:34 +02:00
|
|
|
}
|