mirror of
https://github.com/safing/portbase
synced 2025-09-01 10:09:50 +00:00
Add Has fn to config perspective
This commit is contained in:
parent
8a0c3a077c
commit
dbbe556f3c
2 changed files with 10 additions and 1 deletions
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue