diff --git a/config/option.go b/config/option.go index 0a5ac5c..e391768 100644 --- a/config/option.go +++ b/config/option.go @@ -16,6 +16,7 @@ type OptionType uint8 // Various attribute options. Use ExternalOptType for extended types in the frontend. const ( + optTypeAny OptionType = 0 OptTypeString OptionType = 1 OptTypeStringArray OptionType = 2 OptTypeInt OptionType = 3 @@ -24,6 +25,8 @@ const ( func getTypeName(t OptionType) string { switch t { + case optTypeAny: + return "any" case OptTypeString: return "string" case OptTypeStringArray: diff --git a/config/perspective.go b/config/perspective.go index ea2b25d..ba4b428 100644 --- a/config/perspective.go +++ b/config/perspective.go @@ -75,7 +75,7 @@ func (p *Perspective) getPerspectiveValueCache(name string, requestedType Option } // check type - if requestedType != pOption.option.OptType { + if requestedType != pOption.option.OptType && requestedType != optTypeAny { log.Errorf("config: bad type: requested %s as %s, but is %s", name, getTypeName(requestedType), getTypeName(pOption.option.OptType)) return nil } @@ -88,6 +88,12 @@ func (p *Perspective) getPerspectiveValueCache(name string, requestedType Option return pOption.valueCache } +// Has returns whether the given option is set in the perspective. +func (p *Perspective) Has(name string) bool { + valueCache := p.getPerspectiveValueCache(name, optTypeAny) + return valueCache != nil +} + // GetAsString returns a function that returns the wanted string with high performance. func (p *Perspective) GetAsString(name string) (value string, ok bool) { valueCache := p.getPerspectiveValueCache(name, OptTypeString)