mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
32 lines
486 B
Go
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, "|")
|
|
}
|