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 grant access to resource group
|
||||
|
||||
78
pkg/cloudapi/rg/filter.go
Normal file
78
pkg/cloudapi/rg/filter.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package rg
|
||||
|
||||
// FilterByID returns ListResourceGroups with specified ID.
|
||||
func (lrg ListResourceGroups) FilterByID(id uint64) ListResourceGroups {
|
||||
predicate := func(irg ItemResourceGroup) bool {
|
||||
return irg.ID == id
|
||||
}
|
||||
|
||||
return lrg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByName returns ListResourceGroups with specified Name.
|
||||
func (lrg ListResourceGroups) FilterByName(name string) ListResourceGroups {
|
||||
predicate := func(irg ItemResourceGroup) bool {
|
||||
return irg.Name == name
|
||||
}
|
||||
|
||||
return lrg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByCreatedBy return ListResourceGroups created by specified user.
|
||||
func (lrg ListResourceGroups) FilterByCreatedBy(createdBy string) ListResourceGroups {
|
||||
predicate := func(irg ItemResourceGroup) bool {
|
||||
return irg.CreatedBy == createdBy
|
||||
}
|
||||
|
||||
return lrg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByStatus returns ListResourceGroups with specified Status.
|
||||
func (lrg ListResourceGroups) FilterByStatus(status string) ListResourceGroups {
|
||||
predicate := func(irg ItemResourceGroup) bool {
|
||||
return irg.Status == status
|
||||
}
|
||||
|
||||
return lrg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByLockStatus return ListResourceGroups with specified LockStatus.
|
||||
func (lrg ListResourceGroups) FilterByLockStatus(lockStatus string) ListResourceGroups {
|
||||
predicate := func(irg ItemResourceGroup) bool {
|
||||
return irg.LockStatus == lockStatus
|
||||
}
|
||||
|
||||
return lrg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByDefNetType returns ListResourceGroups with specified DefNetType.
|
||||
func (lrg ListResourceGroups) FilterByDefNetType(defNetType string) ListResourceGroups {
|
||||
predicate := func(irg ItemResourceGroup) bool {
|
||||
return irg.DefNetType == defNetType
|
||||
}
|
||||
|
||||
return lrg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListResourceGroups based on a user-specified predicate.
|
||||
func (lrg ListResourceGroups) FilterFunc(predicate func(irg ItemResourceGroup) bool) ListResourceGroups {
|
||||
var result ListResourceGroups
|
||||
|
||||
for _, rgItem := range lrg {
|
||||
if predicate(rgItem) {
|
||||
result = append(result, rgItem)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemResourceGroup.
|
||||
// If none was found, returns an empty struct.
|
||||
func (lrg ListResourceGroups) FindOne() ItemResourceGroup {
|
||||
if len(lrg) == 0 {
|
||||
return ItemResourceGroup{}
|
||||
}
|
||||
|
||||
return lrg[0]
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
package rg
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to resource group
|
||||
|
||||
43
pkg/cloudapi/rg/serialize.go
Normal file
43
pkg/cloudapi/rg/serialize.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package rg
|
||||
|
||||
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 (lrg ListResourceGroups) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(lrg) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(lrg, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(lrg)
|
||||
}
|
||||
|
||||
// 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 (irg ItemResourceGroup) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(irg, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(irg)
|
||||
}
|
||||
@@ -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 set default network
|
||||
|
||||
60
pkg/cloudapi/rg/sorting.go
Normal file
60
pkg/cloudapi/rg/sorting.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package rg
|
||||
|
||||
import "sort"
|
||||
|
||||
// SortByCreatedTime sorts ListResourceGroups by the CreatedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lrg ListResourceGroups) SortByCreatedTime(inverse bool) ListResourceGroups {
|
||||
if len(lrg) < 2 {
|
||||
return lrg
|
||||
}
|
||||
|
||||
sort.Slice(lrg, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lrg[i].CreatedTime > lrg[j].CreatedTime
|
||||
}
|
||||
|
||||
return lrg[i].CreatedTime < lrg[j].CreatedTime
|
||||
})
|
||||
|
||||
return lrg
|
||||
}
|
||||
|
||||
// SortByUpdatedTime sorts ListResourceGroups by the UpdatedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lrg ListResourceGroups) SortByUpdatedTime(inverse bool) ListResourceGroups {
|
||||
if len(lrg) < 2 {
|
||||
return lrg
|
||||
}
|
||||
|
||||
sort.Slice(lrg, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lrg[i].UpdatedTime > lrg[j].UpdatedTime
|
||||
}
|
||||
|
||||
return lrg[i].UpdatedTime < lrg[j].UpdatedTime
|
||||
})
|
||||
|
||||
return lrg
|
||||
}
|
||||
|
||||
// SortByDeletedTime sorts ListResourceGroups by the DeletedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lrg ListResourceGroups) SortByDeletedTime(inverse bool) ListResourceGroups {
|
||||
if len(lrg) < 2 {
|
||||
return lrg
|
||||
}
|
||||
|
||||
sort.Slice(lrg, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lrg[i].DeletedTime > lrg[j].DeletedTime
|
||||
}
|
||||
|
||||
return lrg[i].DeletedTime < lrg[j].DeletedTime
|
||||
})
|
||||
|
||||
return lrg
|
||||
}
|
||||
Reference in New Issue
Block a user