Refactoring
This commit is contained in:
15
pkg/cloudapi/computeci/computeci.go
Normal file
15
pkg/cloudapi/computeci/computeci.go
Normal 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,
|
||||
}
|
||||
}
|
||||
41
pkg/cloudapi/computeci/get.go
Normal file
41
pkg/cloudapi/computeci/get.go
Normal 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
|
||||
}
|
||||
30
pkg/cloudapi/computeci/list.go
Normal file
30
pkg/cloudapi/computeci/list.go
Normal 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
|
||||
}
|
||||
14
pkg/cloudapi/computeci/models.go
Normal file
14
pkg/cloudapi/computeci/models.go
Normal 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
|
||||
Reference in New Issue
Block a user