mirror of
https://github.com/safing/portbase
synced 2025-09-04 19:50:18 +00:00
Clean up config package
This commit is contained in:
parent
e0535421e4
commit
78aa2f3986
5 changed files with 14 additions and 16 deletions
|
@ -99,12 +99,12 @@ func (s *StorageInterface) Query(q *query.Query, local, internal bool) (*iterato
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
go s.processQuery(q, it, opts)
|
go s.processQuery(it, opts)
|
||||||
|
|
||||||
return it, nil
|
return it, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StorageInterface) processQuery(q *query.Query, it *iterator.Iterator, opts []*Option) {
|
func (s *StorageInterface) processQuery(it *iterator.Iterator, opts []*Option) {
|
||||||
|
|
||||||
sort.Sort(sortableOptions(opts))
|
sort.Sort(sortableOptions(opts))
|
||||||
|
|
||||||
|
|
|
@ -9,12 +9,6 @@ import (
|
||||||
var (
|
var (
|
||||||
validityFlag = abool.NewBool(true)
|
validityFlag = abool.NewBool(true)
|
||||||
validityFlagLock sync.RWMutex
|
validityFlagLock sync.RWMutex
|
||||||
|
|
||||||
tableLock sync.RWMutex
|
|
||||||
|
|
||||||
stringTable map[string]string
|
|
||||||
intTable map[string]int
|
|
||||||
boolTable map[string]bool
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
|
|
@ -20,7 +20,7 @@ var (
|
||||||
// ErrInvalidOptionType is returned by SetConfigOption and SetDefaultConfigOption if given an unsupported option type.
|
// ErrInvalidOptionType is returned by SetConfigOption and SetDefaultConfigOption if given an unsupported option type.
|
||||||
ErrInvalidOptionType = errors.New("invalid option value type")
|
ErrInvalidOptionType = errors.New("invalid option value type")
|
||||||
|
|
||||||
changedSignal = make(chan struct{}, 0)
|
changedSignal = make(chan struct{})
|
||||||
)
|
)
|
||||||
|
|
||||||
// Changed signals if any config option was changed.
|
// Changed signals if any config option was changed.
|
||||||
|
@ -34,7 +34,7 @@ func Changed() <-chan struct{} {
|
||||||
func triggerChange() {
|
func triggerChange() {
|
||||||
// must be locked!
|
// must be locked!
|
||||||
close(changedSignal)
|
close(changedSignal)
|
||||||
changedSignal = make(chan struct{}, 0)
|
changedSignal = make(chan struct{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// setConfig sets the (prioritized) user defined config.
|
// setConfig sets the (prioritized) user defined config.
|
||||||
|
@ -141,7 +141,7 @@ func setConfigOption(name string, value interface{}, push bool) error {
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
resetValidityFlag()
|
resetValidityFlag()
|
||||||
go saveConfig()
|
go saveConfig() //nolint:errcheck // error is logged
|
||||||
triggerChange()
|
triggerChange()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
//nolint:goconst,errcheck
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
|
@ -39,16 +39,19 @@ func getTypeName(t uint8) string {
|
||||||
|
|
||||||
// Option describes a configuration option.
|
// Option describes a configuration option.
|
||||||
type Option struct {
|
type Option struct {
|
||||||
Name string
|
Name string
|
||||||
Key string // category/sub/key
|
Key string // in path format: category/sub/key
|
||||||
Description string
|
Description string
|
||||||
|
|
||||||
ExpertiseLevel uint8
|
ExpertiseLevel uint8
|
||||||
OptType uint8
|
OptType uint8
|
||||||
|
RequiresRestart bool
|
||||||
DefaultValue interface{}
|
DefaultValue interface{}
|
||||||
|
|
||||||
ExternalOptType string
|
ExternalOptType string
|
||||||
ValidationRegex string
|
ValidationRegex string
|
||||||
RequiresRestart bool
|
|
||||||
compiledRegex *regexp.Regexp
|
compiledRegex *regexp.Regexp
|
||||||
}
|
}
|
||||||
|
|
||||||
// Export expors an option to a Record.
|
// Export expors an option to a Record.
|
||||||
|
|
Loading…
Add table
Reference in a new issue