v1.2.1
This commit is contained in:
@@ -6,7 +6,7 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for create K8CI instance
|
||||
|
||||
78
pkg/cloudbroker/k8ci/filter.go
Normal file
78
pkg/cloudbroker/k8ci/filter.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package k8ci
|
||||
|
||||
// FilterByID returns ListK8CI with specified ID.
|
||||
func (lkc ListK8CI) FilterByID(id uint64) ListK8CI {
|
||||
predicate := func(ikc ItemK8CI) bool {
|
||||
return ikc.RecordK8CI.ID == id
|
||||
}
|
||||
|
||||
return lkc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByName returns ListK8CI with specified Name.
|
||||
func (lkc ListK8CI) FilterByName(name string) ListK8CI {
|
||||
predicate := func(ikc ItemK8CI) bool {
|
||||
return ikc.RecordK8CI.Name == name
|
||||
}
|
||||
|
||||
return lkc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByStatus returns ListK8CI with specified Status.
|
||||
func (lkc ListK8CI) FilterByStatus(status string) ListK8CI {
|
||||
predicate := func(ikc ItemK8CI) bool {
|
||||
return ikc.Status == status
|
||||
}
|
||||
|
||||
return lkc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByWorkerImageID returns ListK8CI with specified WorkerImageID.
|
||||
func (lkc ListK8CI) FilterByWorkerImageID(workerImageID uint64) ListK8CI {
|
||||
predicate := func(ikc ItemK8CI) bool {
|
||||
return ikc.WorkerImageID == workerImageID
|
||||
}
|
||||
|
||||
return lkc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByLBImageID returns ListK8CI with specified LBImageID.
|
||||
func (lkc ListK8CI) FilterByLBImageID(lbImageID uint64) ListK8CI {
|
||||
predicate := func(ikc ItemK8CI) bool {
|
||||
return ikc.LBImageID == lbImageID
|
||||
}
|
||||
|
||||
return lkc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByMasterImageID returns ListK8CI with specified MasterImageID.
|
||||
func (lkc ListK8CI) FilterByMasterImageID(masterImageID uint64) ListK8CI {
|
||||
predicate := func(ikc ItemK8CI) bool {
|
||||
return ikc.MasterImageID == masterImageID
|
||||
}
|
||||
|
||||
return lkc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListK8CI based on a user-specified predicate.
|
||||
func (lkc ListK8CI) FilterFunc(predicate func(ItemK8CI) bool) ListK8CI {
|
||||
var result ListK8CI
|
||||
|
||||
for _, item := range lkc {
|
||||
if predicate(item) {
|
||||
result = append(result, item)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemK8CI
|
||||
// If none was found, returns an empty struct.
|
||||
func (lkc ListK8CI) FindOne() ItemK8CI {
|
||||
if len(lkc) == 0 {
|
||||
return ItemK8CI{}
|
||||
}
|
||||
|
||||
return lkc[0]
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
package k8ci
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to K8CI
|
||||
|
||||
43
pkg/cloudbroker/k8ci/serialize.go
Normal file
43
pkg/cloudbroker/k8ci/serialize.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package k8ci
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/serialization"
|
||||
)
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (lkc ListK8CI) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(lkc) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(lkc, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(lkc)
|
||||
}
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (ikc ItemK8CI) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(ikc, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(ikc)
|
||||
}
|
||||
22
pkg/cloudbroker/k8ci/sorting.go
Normal file
22
pkg/cloudbroker/k8ci/sorting.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package k8ci
|
||||
|
||||
import "sort"
|
||||
|
||||
// SortByCreatedTime sorts ListK8CI by the CreatedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lkc ListK8CI) SortByCreatedTime(inverse bool) ListK8CI {
|
||||
if len(lkc) < 2 {
|
||||
return lkc
|
||||
}
|
||||
|
||||
sort.Slice(lkc, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lkc[i].CreatedTime > lkc[j].CreatedTime
|
||||
}
|
||||
|
||||
return lkc[i].CreatedTime < lkc[j].CreatedTime
|
||||
})
|
||||
|
||||
return lkc
|
||||
}
|
||||
Reference in New Issue
Block a user