garm-provider-edge-connect/internal/client/models.go
Manuel Ganter 278073d7ab
Some checks failed
Go Tests / go-tests (push) Failing after 1m6s
resolved conflict
2025-09-05 15:54:24 +02:00

104 lines
2.4 KiB
Go

package client
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 != ""
}
type NewAppInstanceInput struct {
Region string `json:"region"`
AppInst AppInstance `json:"appinst"`
}
type AppInstance struct {
Key AppInstanceKey `json:"key"`
AppKey AppKey `json:"app_key,omitzero"`
Flavor Flavor `json:"flavor,omitzero"`
State string `json:"state,omitempty"`
PowerState string `json:"power_state,omitempty"`
}
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"`
Name string `json:"name,omitempty"`
Version string `json:"version,omitempty"`
}
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"`
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"`
}