Refactoring
This commit is contained in:
41
pkg/cloudapi/k8ci/get.go
Normal file
41
pkg/cloudapi/k8ci/get.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package k8ci
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GetRequest struct {
|
||||
K8CIID uint64 `url:"k8ciId"`
|
||||
}
|
||||
|
||||
func (krq GetRequest) Validate() error {
|
||||
if krq.K8CIID == 0 {
|
||||
return errors.New("field K8CIID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k K8CI) Get(ctx context.Context, req GetRequest, options ...opts.DecortOpts) (*K8CIRecord, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/k8ci/get"
|
||||
k8ciRaw, err := k.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
k8ci := &K8CIRecord{}
|
||||
if err := json.Unmarshal(k8ciRaw, k8ci); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return k8ci, nil
|
||||
}
|
||||
15
pkg/cloudapi/k8ci/k8ci.go
Normal file
15
pkg/cloudapi/k8ci/k8ci.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package k8ci
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
)
|
||||
|
||||
type K8CI struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
func New(client interfaces.Caller) *K8CI {
|
||||
return &K8CI{
|
||||
client,
|
||||
}
|
||||
}
|
||||
30
pkg/cloudapi/k8ci/list.go
Normal file
30
pkg/cloudapi/k8ci/list.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package k8ci
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type ListRequest struct {
|
||||
IncludeDisabled bool `url:"includeDisabled,omitempty"`
|
||||
Page uint64 `url:"page,omitempty"`
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
}
|
||||
|
||||
func (k K8CI) List(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (K8CIList, error) {
|
||||
url := "/cloudapi/k8ci/list"
|
||||
k8ciListRaw, err := k.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
k8ciList := K8CIList{}
|
||||
if err := json.Unmarshal(k8ciListRaw, &k8ciList); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return k8ciList, nil
|
||||
}
|
||||
29
pkg/cloudapi/k8ci/list_deleted.go
Normal file
29
pkg/cloudapi/k8ci/list_deleted.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package k8ci
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type ListDeletedRequest struct {
|
||||
Page uint64 `url:"page,omitempty"`
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
}
|
||||
|
||||
func (k K8CI) ListDeleted(ctx context.Context, req ListDeletedRequest, options ...opts.DecortOpts) (K8CIList, error) {
|
||||
url := "/cloudapi/k8ci/listDeleted"
|
||||
k8ciListRaw, err := k.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
k8ciList := K8CIList{}
|
||||
if err := json.Unmarshal(k8ciListRaw, &k8ciList); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return k8ciList, nil
|
||||
}
|
||||
15
pkg/cloudapi/k8ci/models.go
Normal file
15
pkg/cloudapi/k8ci/models.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package k8ci
|
||||
|
||||
type K8CIItem struct {
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
K8CIRecord
|
||||
}
|
||||
|
||||
type K8CIList []K8CIItem
|
||||
|
||||
type K8CIRecord struct {
|
||||
Description string `json:"desc"`
|
||||
ID uint64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Version string `json:"version"`
|
||||
}
|
||||
Reference in New Issue
Block a user