Refactoring

This commit is contained in:
stSolo
2022-08-11 16:39:39 +03:00
parent 9563097dcb
commit 39a6f9a1ce
300 changed files with 64 additions and 58 deletions

View File

@@ -0,0 +1,15 @@
package computeci
import (
"github.com/rudecs/decort-sdk/interfaces"
)
type ComputeCI struct {
client interfaces.Caller
}
func New(client interfaces.Caller) *ComputeCI {
return &ComputeCI{
client,
}
}

View File

@@ -0,0 +1,41 @@
package computeci
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type GetRequest struct {
ComputeCIID uint64 `url:"computeciId"`
}
func (krq GetRequest) Validate() error {
if krq.ComputeCIID == 0 {
return errors.New("field ComputeCIID can not be empty or equal to 0")
}
return nil
}
func (c ComputeCI) Get(ctx context.Context, req GetRequest, options ...opts.DecortOpts) (*ComputeCIRecord, error) {
if err := req.Validate(); err != nil {
return nil, err
}
url := "/cloudapi/computeci/get"
computeciRaw, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
computeci := &ComputeCIRecord{}
if err := json.Unmarshal(computeciRaw, computeci); err != nil {
return nil, err
}
return computeci, nil
}

View File

@@ -0,0 +1,30 @@
package computeci
import (
"context"
"encoding/json"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type ListRequest struct {
IncludeDeleted bool `url:"includeDeleted,omitempty"`
Page uint64 `url:"page,omitempty"`
Size uint64 `url:"size,omitempty"`
}
func (c ComputeCI) List(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (ComputeCIList, error) {
url := "/cloudapi/computeci/list"
computeciListRaw, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
computeciList := ComputeCIList{}
if err := json.Unmarshal(computeciListRaw, &computeciList); err != nil {
return nil, err
}
return computeciList, nil
}

View File

@@ -0,0 +1,14 @@
package computeci
type ComputeCIRecord struct {
CustomFields map[string]interface{} `json:"customFields"`
Description string `json:"desc"`
Drivers []string `json:"drivers"`
GUID uint64 `json:"guid"`
ID uint64 `json:"id"`
Name string `json:"name"`
Status string `json:"status"`
Template string `jsnn:"template"`
}
type ComputeCIList []ComputeCIRecord