website/pkg/utility/enum.go
2024-11-23 23:51:01 -08:00

16 lines
440 B
Go

package utility
import "code.nonshy.com/nonshy/website/pkg/config"
// StringInOptions constrains a string value (posted by the user) to only be one
// of the available values in the Option list enum. Returns the string if OK, or
// else the default string.
func StringInOptions(v string, options []config.Option, orDefault string) string {
for _, option := range options {
if v == option.Value {
return v
}
}
return orDefault
}