not proper enum compararison

This commit is contained in:
mr
2026-05-29 10:38:45 +02:00
parent ce110ee634
commit b1429596bb
5 changed files with 25 additions and 5 deletions
+10
View File
@@ -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)
}