v1.5.0-gamma
This commit is contained in:
@@ -58,21 +58,23 @@ func (lrg ListResourceGroups) FilterByDefNetType(defNetType string) ListResource
|
||||
func (lrg ListResourceGroups) FilterFunc(predicate func(irg ItemResourceGroup) bool) ListResourceGroups {
|
||||
var result ListResourceGroups
|
||||
|
||||
for _, rgItem := range lrg {
|
||||
for _, rgItem := range lrg.Data {
|
||||
if predicate(rgItem) {
|
||||
result = append(result, rgItem)
|
||||
result.Data = append(result.Data, rgItem)
|
||||
}
|
||||
}
|
||||
|
||||
result.EntryCount = uint64(len(result.Data))
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemResourceGroup.
|
||||
// If none was found, returns an empty struct.
|
||||
func (lrg ListResourceGroups) FindOne() ItemResourceGroup {
|
||||
if len(lrg) == 0 {
|
||||
if len(lrg.Data) == 0 {
|
||||
return ItemResourceGroup{}
|
||||
}
|
||||
|
||||
return lrg[0]
|
||||
return lrg.Data[0]
|
||||
}
|
||||
|
||||
@@ -3,137 +3,140 @@ package rg
|
||||
import "testing"
|
||||
|
||||
var rgs = ListResourceGroups{
|
||||
{
|
||||
AccountID: 1,
|
||||
AccountName: "std",
|
||||
ACL: ListACL{
|
||||
{
|
||||
Explicit: true,
|
||||
GUID: "",
|
||||
Right: "ARCXDU",
|
||||
Status: "CONFIRMED",
|
||||
Type: "U",
|
||||
UserGroupID: "sample_user_1@decs3o",
|
||||
Data: []ItemResourceGroup{
|
||||
{
|
||||
AccountID: 1,
|
||||
AccountName: "std",
|
||||
ACL: ListACL{
|
||||
{
|
||||
Explicit: true,
|
||||
GUID: "",
|
||||
Right: "ARCXDU",
|
||||
Status: "CONFIRMED",
|
||||
Type: "U",
|
||||
UserGroupID: "sample_user_1@decs3o",
|
||||
},
|
||||
},
|
||||
},
|
||||
CreatedBy: "sample_user_1@decs3o",
|
||||
CreatedTime: 1676645305,
|
||||
DefNetID: 1,
|
||||
DefNetType: "NONE",
|
||||
DeletedBy: "",
|
||||
DeletedTime: 0,
|
||||
Description: "",
|
||||
GID: 212,
|
||||
GUID: 7971,
|
||||
ID: 7971,
|
||||
LockStatus: "UNLOCKED",
|
||||
Milestones: 363459,
|
||||
Name: "rg_1",
|
||||
RegisterComputes: false,
|
||||
ResourceLimits: ResourceLimits{
|
||||
CUC: -1,
|
||||
CUI: -1,
|
||||
CUM: -1,
|
||||
CUNP: -1,
|
||||
GPUUnits: -1,
|
||||
},
|
||||
Secret: "",
|
||||
Status: "CREATED",
|
||||
UpdatedBy: "",
|
||||
UpdatedTime: 0,
|
||||
VINS: []uint64{},
|
||||
Computes: []uint64{},
|
||||
ResTypes: []string{},
|
||||
UniqPools: []string{},
|
||||
},
|
||||
{
|
||||
AccountID: 2,
|
||||
AccountName: "std_2",
|
||||
ACL: ListACL{
|
||||
{
|
||||
Explicit: true,
|
||||
GUID: "",
|
||||
Right: "ARCXDU",
|
||||
Status: "CONFIRMED",
|
||||
Type: "U",
|
||||
UserGroupID: "sample_user_1@decs3o",
|
||||
CreatedBy: "sample_user_1@decs3o",
|
||||
CreatedTime: 1676645305,
|
||||
DefNetID: 1,
|
||||
DefNetType: "NONE",
|
||||
DeletedBy: "",
|
||||
DeletedTime: 0,
|
||||
Description: "",
|
||||
GID: 212,
|
||||
GUID: 7971,
|
||||
ID: 7971,
|
||||
LockStatus: "UNLOCKED",
|
||||
Milestones: 363459,
|
||||
Name: "rg_1",
|
||||
RegisterComputes: false,
|
||||
ResourceLimits: ResourceLimits{
|
||||
CUC: -1,
|
||||
CUI: -1,
|
||||
CUM: -1,
|
||||
CUNP: -1,
|
||||
GPUUnits: -1,
|
||||
},
|
||||
Secret: "",
|
||||
Status: "CREATED",
|
||||
UpdatedBy: "",
|
||||
UpdatedTime: 0,
|
||||
VINS: []uint64{},
|
||||
Computes: []uint64{},
|
||||
ResTypes: []string{},
|
||||
UniqPools: []string{},
|
||||
},
|
||||
CreatedBy: "sample_user_1@decs3o",
|
||||
CreatedTime: 1676645461,
|
||||
DefNetID: 2,
|
||||
DefNetType: "NONE",
|
||||
DeletedBy: "",
|
||||
DeletedTime: 0,
|
||||
Description: "",
|
||||
GID: 212,
|
||||
GUID: 7972,
|
||||
ID: 7972,
|
||||
LockStatus: "UNLOCKED",
|
||||
Milestones: 363468,
|
||||
Name: "rg_2",
|
||||
RegisterComputes: false,
|
||||
ResourceLimits: ResourceLimits{
|
||||
CUC: -1,
|
||||
CUI: -1,
|
||||
CUM: -1,
|
||||
CUNP: -1,
|
||||
GPUUnits: -1,
|
||||
},
|
||||
Secret: "",
|
||||
Status: "CREATED",
|
||||
UpdatedBy: "",
|
||||
UpdatedTime: 0,
|
||||
VINS: []uint64{},
|
||||
Computes: []uint64{},
|
||||
ResTypes: []string{},
|
||||
UniqPools: []string{},
|
||||
},
|
||||
{
|
||||
AccountID: 3,
|
||||
AccountName: "std_3",
|
||||
ACL: ListACL{
|
||||
{
|
||||
Explicit: true,
|
||||
GUID: "",
|
||||
Right: "ARCXDU",
|
||||
Status: "CONFIRMED",
|
||||
Type: "U",
|
||||
UserGroupID: "sample_user_2@decs3o",
|
||||
{
|
||||
AccountID: 2,
|
||||
AccountName: "std_2",
|
||||
ACL: ListACL{
|
||||
{
|
||||
Explicit: true,
|
||||
GUID: "",
|
||||
Right: "ARCXDU",
|
||||
Status: "CONFIRMED",
|
||||
Type: "U",
|
||||
UserGroupID: "sample_user_1@decs3o",
|
||||
},
|
||||
},
|
||||
CreatedBy: "sample_user_1@decs3o",
|
||||
CreatedTime: 1676645461,
|
||||
DefNetID: 2,
|
||||
DefNetType: "NONE",
|
||||
DeletedBy: "",
|
||||
DeletedTime: 0,
|
||||
Description: "",
|
||||
GID: 212,
|
||||
GUID: 7972,
|
||||
ID: 7972,
|
||||
LockStatus: "UNLOCKED",
|
||||
Milestones: 363468,
|
||||
Name: "rg_2",
|
||||
RegisterComputes: false,
|
||||
ResourceLimits: ResourceLimits{
|
||||
CUC: -1,
|
||||
CUI: -1,
|
||||
CUM: -1,
|
||||
CUNP: -1,
|
||||
GPUUnits: -1,
|
||||
},
|
||||
Secret: "",
|
||||
Status: "CREATED",
|
||||
UpdatedBy: "",
|
||||
UpdatedTime: 0,
|
||||
VINS: []uint64{},
|
||||
Computes: []uint64{},
|
||||
ResTypes: []string{},
|
||||
UniqPools: []string{},
|
||||
},
|
||||
CreatedBy: "sample_user_2@decs3o",
|
||||
CreatedTime: 1676645548,
|
||||
DefNetID: 3,
|
||||
DefNetType: "NONE",
|
||||
DeletedBy: "",
|
||||
DeletedTime: 0,
|
||||
Description: "",
|
||||
GID: 212,
|
||||
GUID: 7973,
|
||||
ID: 7973,
|
||||
LockStatus: "kjLOCKED",
|
||||
Milestones: 363471,
|
||||
Name: "rg_3",
|
||||
RegisterComputes: false,
|
||||
ResourceLimits: ResourceLimits{
|
||||
CUC: -1,
|
||||
CUI: -1,
|
||||
CUM: -1,
|
||||
CUNP: -1,
|
||||
GPUUnits: -1,
|
||||
{
|
||||
AccountID: 3,
|
||||
AccountName: "std_3",
|
||||
ACL: ListACL{
|
||||
{
|
||||
Explicit: true,
|
||||
GUID: "",
|
||||
Right: "ARCXDU",
|
||||
Status: "CONFIRMED",
|
||||
Type: "U",
|
||||
UserGroupID: "sample_user_2@decs3o",
|
||||
},
|
||||
},
|
||||
CreatedBy: "sample_user_2@decs3o",
|
||||
CreatedTime: 1676645548,
|
||||
DefNetID: 3,
|
||||
DefNetType: "NONE",
|
||||
DeletedBy: "",
|
||||
DeletedTime: 0,
|
||||
Description: "",
|
||||
GID: 212,
|
||||
GUID: 7973,
|
||||
ID: 7973,
|
||||
LockStatus: "kjLOCKED",
|
||||
Milestones: 363471,
|
||||
Name: "rg_3",
|
||||
RegisterComputes: false,
|
||||
ResourceLimits: ResourceLimits{
|
||||
CUC: -1,
|
||||
CUI: -1,
|
||||
CUM: -1,
|
||||
CUNP: -1,
|
||||
GPUUnits: -1,
|
||||
},
|
||||
Secret: "",
|
||||
Status: "DISABLED",
|
||||
UpdatedBy: "",
|
||||
UpdatedTime: 0,
|
||||
VINS: []uint64{},
|
||||
Computes: []uint64{
|
||||
48500,
|
||||
},
|
||||
ResTypes: []string{},
|
||||
UniqPools: []string{},
|
||||
},
|
||||
Secret: "",
|
||||
Status: "DISABLED",
|
||||
UpdatedBy: "",
|
||||
UpdatedTime: 0,
|
||||
VINS: []uint64{},
|
||||
Computes: []uint64{
|
||||
48500,
|
||||
},
|
||||
ResTypes: []string{},
|
||||
UniqPools: []string{},
|
||||
},
|
||||
EntryCount: 3,
|
||||
}
|
||||
|
||||
func TestFilterByID(t *testing.T) {
|
||||
@@ -155,11 +158,11 @@ func TestFilterByName(t *testing.T) {
|
||||
func TestFilterByCreatedBy(t *testing.T) {
|
||||
actual := rgs.FilterByCreatedBy("sample_user_1@decs3o")
|
||||
|
||||
if len(actual) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual))
|
||||
if len(actual.Data) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual {
|
||||
for _, item := range actual.Data {
|
||||
if item.CreatedBy != "sample_user_1@decs3o" {
|
||||
t.Fatal("expected CreatedBy 'sample_user_1@decs3o', found: ", item.CreatedBy)
|
||||
}
|
||||
@@ -169,11 +172,11 @@ func TestFilterByCreatedBy(t *testing.T) {
|
||||
func TestFilterByStatus(t *testing.T) {
|
||||
actual := rgs.FilterByStatus("CREATED")
|
||||
|
||||
if len(actual) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual))
|
||||
if len(actual.Data) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual {
|
||||
for _, item := range actual.Data {
|
||||
if item.Status != "CREATED" {
|
||||
t.Fatal("expected Status 'ENABLED', found: ", item.Status)
|
||||
}
|
||||
@@ -183,11 +186,11 @@ func TestFilterByStatus(t *testing.T) {
|
||||
func TestFilterByLockStatus(t *testing.T) {
|
||||
actual := rgs.FilterByLockStatus("UNLOCKED")
|
||||
|
||||
if len(actual) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual))
|
||||
if len(actual.Data) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual {
|
||||
for _, item := range actual.Data {
|
||||
if item.LockStatus != "UNLOCKED" {
|
||||
t.Fatal("expected LockStatus 'UNLOCKED', found: ", item.LockStatus)
|
||||
}
|
||||
@@ -197,11 +200,11 @@ func TestFilterByLockStatus(t *testing.T) {
|
||||
func TestFilterByDefNetType(t *testing.T) {
|
||||
actual := rgs.FilterByDefNetType("NONE")
|
||||
|
||||
if len(actual) != 3 {
|
||||
t.Fatal("expected 3 found, actual: ", len(actual))
|
||||
if len(actual.Data) != 3 {
|
||||
t.Fatal("expected 3 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual {
|
||||
for _, item := range actual.Data {
|
||||
if item.DefNetType != "NONE" {
|
||||
t.Fatal("expected DefNetType 'NONE', found: ", item.DefNetType)
|
||||
}
|
||||
@@ -213,11 +216,11 @@ func TestFilterFunc(t *testing.T) {
|
||||
return len(ir.Computes) > 0
|
||||
})
|
||||
|
||||
if len(actual) < 1 {
|
||||
t.Fatal("expected 1 found, actual: ", len(actual))
|
||||
if len(actual.Data) < 1 {
|
||||
t.Fatal("expected 1 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual {
|
||||
for _, item := range actual.Data {
|
||||
if len(item.Computes) < 1 {
|
||||
t.Fatal("expected VMs to contain at least 1 element, found empty")
|
||||
}
|
||||
@@ -227,7 +230,7 @@ func TestFilterFunc(t *testing.T) {
|
||||
func TestSortByCreatedTime(t *testing.T) {
|
||||
actual := rgs.SortByCreatedTime(true)
|
||||
|
||||
if actual[0].CreatedTime != 1676645548 || actual[2].CreatedTime != 1676645305 {
|
||||
if actual.Data[0].CreatedTime != 1676645548 || actual.Data[2].CreatedTime != 1676645305 {
|
||||
t.Fatal("expected descending order, found ascending")
|
||||
}
|
||||
}
|
||||
|
||||
42
pkg/cloudapi/rg/get_resource_consumption.go
Normal file
42
pkg/cloudapi/rg/get_resource_consumption.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package rg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get detailed information about resource consumption for ResGroup
|
||||
type GetResourceConsumptionRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
}
|
||||
|
||||
// GetResourceConsumption gets resource consumption of the resource group
|
||||
func (r RG) GetResourceConsumption(ctx context.Context, req GetResourceConsumptionRequest) (*ItemResourceConsumption, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/getResourceConsumption"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := ItemResourceConsumption{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
@@ -8,6 +8,38 @@ import (
|
||||
|
||||
// Request struct for get list of resource groups
|
||||
type ListRequest struct {
|
||||
// Find by ID
|
||||
// Required: false
|
||||
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
||||
|
||||
// Find by name
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// Find by account ID
|
||||
// Required: false
|
||||
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
|
||||
|
||||
// Find by name account
|
||||
// Required: false
|
||||
AccountName string `url:"accountName,omitempty" json:"accountName,omitempty"`
|
||||
|
||||
// Find by created after time (unix timestamp)
|
||||
// Required: false
|
||||
CreatedAfter uint64 `url:"createdAfter,omitempty" json:"createdAfter,omitempty"`
|
||||
|
||||
// Find by created before time (unix timestamp)
|
||||
// Required: false
|
||||
CreatedBefore uint64 `url:"createdBefore,omitempty" json:"createdBefore,omitempty"`
|
||||
|
||||
// Find by status
|
||||
// Required: false
|
||||
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||
|
||||
// Find by status lock
|
||||
// Required: false
|
||||
LockStatus string `url:"lockStatus,omitempty" json:"lockStatus,omitempty"`
|
||||
|
||||
// Included deleted resource groups
|
||||
// Required: false
|
||||
IncludeDeleted bool `url:"includedeleted,omitempty" json:"includedeleted,omitempty"`
|
||||
@@ -22,7 +54,7 @@ type ListRequest struct {
|
||||
}
|
||||
|
||||
// List gets list of all resource groups the user has access to
|
||||
func (r RG) List(ctx context.Context, req ListRequest) (ListResourceGroups, error) {
|
||||
func (r RG) List(ctx context.Context, req ListRequest) (*ListResourceGroups, error) {
|
||||
url := "/cloudapi/rg/list"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
@@ -37,5 +69,5 @@ func (r RG) List(ctx context.Context, req ListRequest) (ListResourceGroups, erro
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ type ListDeletedRequest struct {
|
||||
}
|
||||
|
||||
// ListDeleted gets list all deleted resource groups the user has access to
|
||||
func (r RG) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListResourceGroups, error) {
|
||||
func (r RG) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListResourceGroups, error) {
|
||||
url := "/cloudapi/rg/listDeleted"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
@@ -33,5 +33,5 @@ func (r RG) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListResour
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
26
pkg/cloudapi/rg/list_resource_consumption.go
Normal file
26
pkg/cloudapi/rg/list_resource_consumption.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package rg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// ListResourceConsumption gets resource consumptions of the resource groups
|
||||
func (r RG) ListResourceConsumption(ctx context.Context) (*ListResourceConsumption, error) {
|
||||
url := "/cloudapi/rg/listResourceConsumption"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListResourceConsumption{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &list, nil
|
||||
}
|
||||
@@ -9,7 +9,7 @@ type Resource struct {
|
||||
DiskSize float64 `json:"disksize"`
|
||||
|
||||
// Max disk size
|
||||
DiskSizeMax uint64 `json:"disksizemax"`
|
||||
DiskSizeMax float64 `json:"disksizemax"`
|
||||
|
||||
// Number of External IPs
|
||||
ExtIPs int64 `json:"extips"`
|
||||
@@ -33,7 +33,7 @@ type DiskUsage struct {
|
||||
DiskSize float64 `json:"disksize"`
|
||||
|
||||
// Disk size max
|
||||
DiskSizeMax uint64 `json:"disksizemax"`
|
||||
DiskSizeMax float64 `json:"disksizemax"`
|
||||
}
|
||||
|
||||
// Information about resources
|
||||
@@ -45,11 +45,26 @@ type Resources struct {
|
||||
Reserved Resource `json:"Reserved"`
|
||||
}
|
||||
|
||||
// Detailed information about resource consumption
|
||||
type ItemResourceConsumption struct {
|
||||
// Consumed information about resources
|
||||
Consumed Resource `json:"Consumed"`
|
||||
|
||||
// Reserved information about resources
|
||||
Reserved Resource `json:"Reserved"`
|
||||
|
||||
// Resource group ID
|
||||
RGID uint64 `json:"rgid"`
|
||||
}
|
||||
|
||||
type ListResourceConsumption struct {
|
||||
Data []ItemResourceConsumption `json:"data"`
|
||||
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
// Detailed information about resource group
|
||||
type RecordResourceGroup struct {
|
||||
// Resources
|
||||
Resources Resources `json:"Resources"`
|
||||
|
||||
// Account ID
|
||||
AccountID uint64 `json:"accountId"`
|
||||
|
||||
@@ -232,7 +247,11 @@ type ItemResourceGroup struct {
|
||||
}
|
||||
|
||||
// List of resource groups
|
||||
type ListResourceGroups []ItemResourceGroup
|
||||
type ListResourceGroups struct {
|
||||
Data []ItemResourceGroup `json:"data"`
|
||||
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
// Main information about Access Control List
|
||||
type ItemACL struct {
|
||||
@@ -266,6 +285,9 @@ type ResourceLimits struct {
|
||||
// CUD
|
||||
CUD float64 `json:"CU_D"`
|
||||
|
||||
// CUDM
|
||||
CUDM float64 `json:"CU_DM"`
|
||||
|
||||
// CUI
|
||||
CUI float64 `json:"CU_I"`
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (lrg ListResourceGroups) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(lrg) == 0 {
|
||||
if len(lrg.Data) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -6,16 +6,16 @@ import "sort"
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lrg ListResourceGroups) SortByCreatedTime(inverse bool) ListResourceGroups {
|
||||
if len(lrg) < 2 {
|
||||
if len(lrg.Data) < 2 {
|
||||
return lrg
|
||||
}
|
||||
|
||||
sort.Slice(lrg, func(i, j int) bool {
|
||||
sort.Slice(lrg.Data, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lrg[i].CreatedTime > lrg[j].CreatedTime
|
||||
return lrg.Data[i].CreatedTime > lrg.Data[j].CreatedTime
|
||||
}
|
||||
|
||||
return lrg[i].CreatedTime < lrg[j].CreatedTime
|
||||
return lrg.Data[i].CreatedTime < lrg.Data[j].CreatedTime
|
||||
})
|
||||
|
||||
return lrg
|
||||
@@ -25,16 +25,16 @@ func (lrg ListResourceGroups) SortByCreatedTime(inverse bool) ListResourceGroups
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lrg ListResourceGroups) SortByUpdatedTime(inverse bool) ListResourceGroups {
|
||||
if len(lrg) < 2 {
|
||||
if len(lrg.Data) < 2 {
|
||||
return lrg
|
||||
}
|
||||
|
||||
sort.Slice(lrg, func(i, j int) bool {
|
||||
sort.Slice(lrg.Data, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lrg[i].UpdatedTime > lrg[j].UpdatedTime
|
||||
return lrg.Data[i].UpdatedTime > lrg.Data[j].UpdatedTime
|
||||
}
|
||||
|
||||
return lrg[i].UpdatedTime < lrg[j].UpdatedTime
|
||||
return lrg.Data[i].UpdatedTime < lrg.Data[j].UpdatedTime
|
||||
})
|
||||
|
||||
return lrg
|
||||
@@ -44,16 +44,16 @@ func (lrg ListResourceGroups) SortByUpdatedTime(inverse bool) ListResourceGroups
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lrg ListResourceGroups) SortByDeletedTime(inverse bool) ListResourceGroups {
|
||||
if len(lrg) < 2 {
|
||||
if len(lrg.Data) < 2 {
|
||||
return lrg
|
||||
}
|
||||
|
||||
sort.Slice(lrg, func(i, j int) bool {
|
||||
sort.Slice(lrg.Data, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lrg[i].DeletedTime > lrg[j].DeletedTime
|
||||
return lrg.Data[i].DeletedTime > lrg.Data[j].DeletedTime
|
||||
}
|
||||
|
||||
return lrg[i].DeletedTime < lrg[j].DeletedTime
|
||||
return lrg.Data[i].DeletedTime < lrg.Data[j].DeletedTime
|
||||
})
|
||||
|
||||
return lrg
|
||||
|
||||
Reference in New Issue
Block a user