not proper enum compararison
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package enum
|
||||
|
||||
import "fmt"
|
||||
|
||||
type InfrastructureType int
|
||||
|
||||
const (
|
||||
@@ -18,3 +20,11 @@ func (t InfrastructureType) String() string {
|
||||
func InfrastructureList() []InfrastructureType {
|
||||
return []InfrastructureType{DOCKER, KUBERNETES, SLURM, HW, CONDOR}
|
||||
}
|
||||
|
||||
func (d InfrastructureType) Compare(indexStr interface{}) bool {
|
||||
return fmt.Sprintf("%v", indexStr) == fmt.Sprintf("%v", d.EnumIndex()) || fmt.Sprintf("%v", indexStr) == d.String()
|
||||
}
|
||||
|
||||
func (d InfrastructureType) EnumIndex() int {
|
||||
return int(d)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package enum
|
||||
|
||||
import "fmt"
|
||||
|
||||
type StorageSize int
|
||||
|
||||
// StorageType - Enum that defines the type of storage
|
||||
@@ -54,3 +56,11 @@ func (t StorageType) String() string {
|
||||
func TypeList() []StorageType {
|
||||
return []StorageType{FILE, STREAM, API, DATABASE, S3, MEMORY, HARDWARE, AZURE, GCS}
|
||||
}
|
||||
|
||||
func (d StorageType) Compare(indexStr interface{}) bool {
|
||||
return fmt.Sprintf("%v", indexStr) == fmt.Sprintf("%v", d.EnumIndex()) || fmt.Sprintf("%v", indexStr) == d.String()
|
||||
}
|
||||
|
||||
func (d StorageType) EnumIndex() int {
|
||||
return int(d)
|
||||
}
|
||||
|
||||
@@ -38,8 +38,8 @@ type LiveDatacenter struct {
|
||||
}
|
||||
|
||||
func (r *LiveDatacenter) IsCompatible(service map[string]interface{}) bool {
|
||||
fmt.Println("COMPARE <", service["infrastructure"], "> <", r.Infrastructure, "> AND <", service["architecture"], "> <", r.Architecture, ">")
|
||||
return service["infrastructure"] == r.Infrastructure && service["architecture"] == r.Architecture
|
||||
fmt.Println("COMPARE <", r.Infrastructure.Compare(service["infrastructure"]), "> AND <", service["architecture"], "> <", r.Architecture, ">")
|
||||
return r.Infrastructure.Compare(service["infrastructure"]) && service["architecture"] == r.Architecture
|
||||
}
|
||||
|
||||
func (d *LiveDatacenter) GetAccessor(request *tools.APIRequest) utils.Accessor {
|
||||
|
||||
@@ -42,5 +42,5 @@ func (d *LiveService) GetAccessor(request *tools.APIRequest) utils.Accessor {
|
||||
func (r *LiveService) IsCompatible(service map[string]interface{}) bool {
|
||||
fmt.Println("COMPARE <", service["infrastructure"], "> <", r.Infrastructure, ">")
|
||||
|
||||
return service["infrastructure"] == r.Infrastructure
|
||||
return r.Infrastructure.Compare(service["infrastructure"])
|
||||
}
|
||||
|
||||
@@ -28,9 +28,9 @@ type LiveStorage struct {
|
||||
}
|
||||
|
||||
func (r *LiveStorage) IsCompatible(service map[string]interface{}) bool {
|
||||
fmt.Println("COMPARE <", service["storage_type"], "> <", r.StorageType, ">")
|
||||
fmt.Println("COMPARE <", r.StorageType.Compare(service["storage_type"]), ">")
|
||||
|
||||
return service["storage_type"] == r.StorageType
|
||||
return r.StorageType.Compare(service["storage_type"])
|
||||
}
|
||||
|
||||
func (d *LiveStorage) GetAccessor(request *tools.APIRequest) utils.Accessor {
|
||||
|
||||
Reference in New Issue
Block a user