Files
cloudpods/pkg/cloudcommon/validators/choices.go
T

32 lines
486 B
Go

package validators
import (
"strings"
)
type Empty struct{}
type Choices map[string]Empty
func NewChoices(choices ...string) Choices {
cs := Choices{}
for _, choice := range choices {
cs[choice] = Empty{}
}
return cs
}
func (cs Choices) Has(choice string) bool {
_, ok := cs[choice]
return ok
}
func (cs Choices) String() string {
choices := make([]string, len(cs))
i := 0
for choice, _ := range cs {
choices[i] = choice
i++
}
return strings.Join(choices, "|")
}