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