v1.2.1
This commit is contained in:
60
pkg/cloudapi/lb/filter.go
Normal file
60
pkg/cloudapi/lb/filter.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package lb
|
||||
|
||||
// FilterByID returns ListLB with specified ID.
|
||||
func (ll ListLB) FilterByID(id uint64) ListLB {
|
||||
predicate := func(ill ItemLoadBalancer) bool {
|
||||
return ill.ID == id
|
||||
}
|
||||
|
||||
return ll.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByName returns ListLB with specified Name.
|
||||
func (ll ListLB) FilterByName(name string) ListLB {
|
||||
predicate := func(ill ItemLoadBalancer) bool {
|
||||
return ill.Name == name
|
||||
}
|
||||
|
||||
return ll.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByExtNetID returns ListLB with specified ExtNetID.
|
||||
func (ll ListLB) FilterByExtNetID(extNetID uint64) ListLB {
|
||||
predicate := func(ill ItemLoadBalancer) bool {
|
||||
return ill.ExtNetID == extNetID
|
||||
}
|
||||
|
||||
return ll.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByImageID returns ListLB with specified ImageID.
|
||||
func (ll ListLB) FilterByImageID(imageID uint64) ListLB {
|
||||
predicate := func(ill ItemLoadBalancer) bool {
|
||||
return ill.ImageID == imageID
|
||||
}
|
||||
|
||||
return ll.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListLB based on a user-specified predicate.
|
||||
func (ll ListLB) FilterFunc(predicate func(ItemLoadBalancer) bool) ListLB {
|
||||
var result ListLB
|
||||
|
||||
for _, item := range ll {
|
||||
if predicate(item) {
|
||||
result = append(result, item)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemLoadBalancer
|
||||
// If none was found, returns an empty struct.
|
||||
func (ll ListLB) FindOne() ItemLoadBalancer {
|
||||
if len(ll) == 0 {
|
||||
return ItemLoadBalancer{}
|
||||
}
|
||||
|
||||
return ll[0]
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to load balancer
|
||||
|
||||
43
pkg/cloudapi/lb/serialize.go
Normal file
43
pkg/cloudapi/lb/serialize.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package lb
|
||||
|
||||
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 (ll ListLB) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(ll) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(ll, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(ll)
|
||||
}
|
||||
|
||||
// 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 (ill ItemLoadBalancer) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(ill, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(ill)
|
||||
}
|
||||
60
pkg/cloudapi/lb/sorting.go
Normal file
60
pkg/cloudapi/lb/sorting.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package lb
|
||||
|
||||
import "sort"
|
||||
|
||||
// SortByCreatedTime sorts ListLB by the CreatedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (ll ListLB) SortByCreatedTime(inverse bool) ListLB {
|
||||
if len(ll) < 2 {
|
||||
return ll
|
||||
}
|
||||
|
||||
sort.Slice(ll, func(i, j int) bool {
|
||||
if inverse {
|
||||
return ll[i].CreatedTime > ll[j].CreatedTime
|
||||
}
|
||||
|
||||
return ll[i].CreatedTime < ll[j].CreatedTime
|
||||
})
|
||||
|
||||
return ll
|
||||
}
|
||||
|
||||
// SortByUpdatedTime sorts ListLB by the UpdatedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (ll ListLB) SortByUpdatedTime(inverse bool) ListLB {
|
||||
if len(ll) < 2 {
|
||||
return ll
|
||||
}
|
||||
|
||||
sort.Slice(ll, func(i, j int) bool {
|
||||
if inverse {
|
||||
return ll[i].UpdatedTime > ll[j].UpdatedTime
|
||||
}
|
||||
|
||||
return ll[i].UpdatedTime < ll[j].UpdatedTime
|
||||
})
|
||||
|
||||
return ll
|
||||
}
|
||||
|
||||
// SortByDeletedTime sorts ListLB by the DeletedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (ll ListLB) SortByDeletedTime(inverse bool) ListLB {
|
||||
if len(ll) < 2 {
|
||||
return ll
|
||||
}
|
||||
|
||||
sort.Slice(ll, func(i, j int) bool {
|
||||
if inverse {
|
||||
return ll[i].DeletedTime > ll[j].DeletedTime
|
||||
}
|
||||
|
||||
return ll[i].DeletedTime < ll[j].DeletedTime
|
||||
})
|
||||
|
||||
return ll
|
||||
}
|
||||
Reference in New Issue
Block a user