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