v1.2.1
This commit is contained in:
42
pkg/cloudapi/sizes/filter.go
Normal file
42
pkg/cloudapi/sizes/filter.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package sizes
|
||||
|
||||
// FilterByID returns ListSizes with specified ID.
|
||||
func (ls ListSizes) FilterByID(id uint64) ListSizes {
|
||||
predicate := func(is ItemSize) bool {
|
||||
return is.ID == id
|
||||
}
|
||||
|
||||
return ls.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByName returns ListSizes with specified Name.
|
||||
func (ls ListSizes) FilterByName(name string) ListSizes {
|
||||
predicate := func(is ItemSize) bool {
|
||||
return is.Name == name
|
||||
}
|
||||
|
||||
return ls.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListSizes based on a user-specified predicate.
|
||||
func (ls ListSizes) FilterFunc(predicate func(ItemSize) bool) ListSizes {
|
||||
var result ListSizes
|
||||
|
||||
for _, item := range ls {
|
||||
if predicate(item) {
|
||||
result = append(result, item)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemSize
|
||||
// If none was found, returns an empty struct.
|
||||
func (ls ListSizes) FindOne() ItemSize {
|
||||
if len(ls) == 0 {
|
||||
return ItemSize{}
|
||||
}
|
||||
|
||||
return ls[0]
|
||||
}
|
||||
43
pkg/cloudapi/sizes/serialize.go
Normal file
43
pkg/cloudapi/sizes/serialize.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package sizes
|
||||
|
||||
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 (ls ListSizes) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(ls) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(ls, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(ls)
|
||||
}
|
||||
|
||||
// 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 (is ItemSize) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(is, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(is)
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
package sizes
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creatig request to sizes
|
||||
|
||||
Reference in New Issue
Block a user