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 create image
|
||||
|
||||
60
pkg/cloudapi/image/filter.go
Normal file
60
pkg/cloudapi/image/filter.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package image
|
||||
|
||||
// FilterByID returns ListImages with specified ID.
|
||||
func (li ListImages) FilterByID(id uint64) ListImages {
|
||||
predicate := func(ii ItemImage) bool {
|
||||
return ii.ID == id
|
||||
}
|
||||
|
||||
return li.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByName returns ListImages with specified Name.
|
||||
func (li ListImages) FilterByName(name string) ListImages {
|
||||
predicate := func(ii ItemImage) bool {
|
||||
return ii.Name == name
|
||||
}
|
||||
|
||||
return li.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByStatus returns ListImages with specified Status.
|
||||
func (li ListImages) FilterByStatus(status string) ListImages {
|
||||
predicate := func(ii ItemImage) bool {
|
||||
return ii.Status == status
|
||||
}
|
||||
|
||||
return li.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByBootType returns ListImages with specified BootType.
|
||||
func (li ListImages) FilterByBootType(bootType string) ListImages {
|
||||
predicate := func(ii ItemImage) bool {
|
||||
return ii.BootType == bootType
|
||||
}
|
||||
|
||||
return li.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListImages based on a user-specified predicate.
|
||||
func (li ListImages) FilterFunc(predicate func(ItemImage) bool) ListImages {
|
||||
var result ListImages
|
||||
|
||||
for _, item := range li {
|
||||
if predicate(item) {
|
||||
result = append(result, item)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemImage
|
||||
// If none was found, returns an empty struct.
|
||||
func (li ListImages) FindOne() ItemImage {
|
||||
if len(li) == 0 {
|
||||
return ItemImage{}
|
||||
}
|
||||
|
||||
return li[0]
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to image
|
||||
|
||||
43
pkg/cloudapi/image/serialize.go
Normal file
43
pkg/cloudapi/image/serialize.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package image
|
||||
|
||||
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 (li ListImages) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(li) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(li, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(li)
|
||||
}
|
||||
|
||||
// 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 (ii ItemImage) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(ii, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(ii)
|
||||
}
|
||||
Reference in New Issue
Block a user