mirror of
https://github.com/safing/portbase
synced 2025-09-01 01:59:48 +00:00
Fix linter errors and update deps
This commit is contained in:
parent
3f3305d8c2
commit
8a0c3a077c
9 changed files with 20 additions and 22 deletions
|
@ -177,7 +177,7 @@ type Option struct {
|
||||||
// been created.
|
// been created.
|
||||||
Description string
|
Description string
|
||||||
// Help may hold a long version of the description providing
|
// Help may hold a long version of the description providing
|
||||||
// assistence with the configuration option.
|
// assistance with the configuration option.
|
||||||
// Help is considered immutable after the option has
|
// Help is considered immutable after the option has
|
||||||
// been created.
|
// been created.
|
||||||
Help string
|
Help string
|
||||||
|
|
|
@ -45,7 +45,7 @@ func isAllowedPossibleValue(opt *Option, value interface{}) error {
|
||||||
compareAgainst := val.Value
|
compareAgainst := val.Value
|
||||||
valueType := reflect.TypeOf(value)
|
valueType := reflect.TypeOf(value)
|
||||||
|
|
||||||
// loading int's from the configuration JSON does not perserve the correct type
|
// loading int's from the configuration JSON does not preserve the correct type
|
||||||
// as we get float64 instead. Make sure to convert them before.
|
// as we get float64 instead. Make sure to convert them before.
|
||||||
if reflect.TypeOf(val.Value).ConvertibleTo(valueType) {
|
if reflect.TypeOf(val.Value).ConvertibleTo(valueType) {
|
||||||
compareAgainst = reflect.ValueOf(val.Value).Convert(valueType).Interface()
|
compareAgainst = reflect.ValueOf(val.Value).Convert(valueType).Interface()
|
||||||
|
|
|
@ -17,7 +17,7 @@ type Hook interface {
|
||||||
// the underlying storage. A PreGet hookd may be used to
|
// the underlying storage. A PreGet hookd may be used to
|
||||||
// implement more advanced access control on database keys.
|
// implement more advanced access control on database keys.
|
||||||
PreGet(dbKey string) error
|
PreGet(dbKey string) error
|
||||||
// UsesPostGet should returnd true if the hook's PostGet
|
// UsesPostGet should return true if the hook's PostGet
|
||||||
// should be called after loading a database record from
|
// should be called after loading a database record from
|
||||||
// the underlying storage.
|
// the underlying storage.
|
||||||
UsesPostGet() bool
|
UsesPostGet() bool
|
||||||
|
|
|
@ -21,7 +21,7 @@ var (
|
||||||
printGraphFlag bool
|
printGraphFlag bool
|
||||||
)
|
)
|
||||||
|
|
||||||
// Register registeres a new subsystem. It's like Manager.Register
|
// Register registers a new subsystem. It's like Manager.Register
|
||||||
// but uses DefaultManager and panics on error.
|
// but uses DefaultManager and panics on error.
|
||||||
func Register(id, name, description string, module *modules.Module, configKeySpace string, option *config.Option) {
|
func Register(id, name, description string, module *modules.Module, configKeySpace string, option *config.Option) {
|
||||||
err := DefaultManager.Register(id, name, description, module, configKeySpace, option)
|
err := DefaultManager.Register(id, name, description, module, configKeySpace, option)
|
||||||
|
@ -92,7 +92,7 @@ func prep() error {
|
||||||
|
|
||||||
func start() error {
|
func start() error {
|
||||||
// Registration of subsystems is only allowed during
|
// Registration of subsystems is only allowed during
|
||||||
// preperation. Make sure any further call to Register()
|
// preparation. Make sure any further call to Register()
|
||||||
// panics.
|
// panics.
|
||||||
if err := DefaultManager.Start(); err != nil {
|
if err := DefaultManager.Start(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -104,9 +104,9 @@ func start() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrintGraph prints the subsystem and module graph.
|
// PrintGraph prints the subsystem and module graph.
|
||||||
func (reg *Manager) PrintGraph() {
|
func (mng *Manager) PrintGraph() {
|
||||||
reg.l.RLock()
|
mng.l.RLock()
|
||||||
defer reg.l.RUnlock()
|
defer mng.l.RUnlock()
|
||||||
|
|
||||||
fmt.Println("subsystems dependency graph:")
|
fmt.Println("subsystems dependency graph:")
|
||||||
|
|
||||||
|
@ -114,17 +114,17 @@ func (reg *Manager) PrintGraph() {
|
||||||
module.Disable()
|
module.Disable()
|
||||||
|
|
||||||
// mark roots
|
// mark roots
|
||||||
for _, sub := range reg.subsys {
|
for _, sub := range mng.subsys {
|
||||||
sub.module.Enable() // mark as tree root
|
sub.module.Enable() // mark as tree root
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, sub := range reg.subsys {
|
for _, sub := range mng.subsys {
|
||||||
printModuleGraph("", sub.module, true)
|
printModuleGraph("", sub.module, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("\nsubsystem module groups:")
|
fmt.Println("\nsubsystem module groups:")
|
||||||
_ = start() // no errors for what we need here
|
_ = start() // no errors for what we need here
|
||||||
for _, sub := range reg.subsys {
|
for _, sub := range mng.subsys {
|
||||||
fmt.Printf("├── %s\n", sub.Name)
|
fmt.Printf("├── %s\n", sub.Name)
|
||||||
for _, mod := range sub.Modules[1:] {
|
for _, mod := range sub.Modules[1:] {
|
||||||
fmt.Printf("│ ├── %s\n", mod.Name)
|
fmt.Printf("│ ├── %s\n", mod.Name)
|
||||||
|
|
|
@ -36,7 +36,7 @@ type Manager struct {
|
||||||
runtime *runtime.Registry
|
runtime *runtime.Registry
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewManager returns a new subsystem manager that registeres
|
// NewManager returns a new subsystem manager that registers
|
||||||
// itself at rtReg.
|
// itself at rtReg.
|
||||||
func NewManager(rtReg *runtime.Registry) (*Manager, error) {
|
func NewManager(rtReg *runtime.Registry) (*Manager, error) {
|
||||||
mng := &Manager{
|
mng := &Manager{
|
||||||
|
@ -71,7 +71,7 @@ func (mng *Manager) Start() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// aggregate all modules dependencies (and the subsystem module itself)
|
// aggregate all modules dependencies (and the subsystem module itself)
|
||||||
// into the Modules slice. Configuration options form dependened modules
|
// into the Modules slice. Configuration options form dependent modules
|
||||||
// will be marked using config.SubsystemAnnotation if not already set.
|
// will be marked using config.SubsystemAnnotation if not already set.
|
||||||
for _, sub := range mng.subsys {
|
for _, sub := range mng.subsys {
|
||||||
sub.Modules = append(sub.Modules, statusFromModule(sub.module))
|
sub.Modules = append(sub.Modules, statusFromModule(sub.module))
|
||||||
|
@ -118,7 +118,7 @@ func (mng *Manager) Get(keyOrPrefix string) ([]record.Record, error) {
|
||||||
return records, nil
|
return records, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register registeres a new subsystem. The given option must be a bool option.
|
// Register registers a new subsystem. The given option must be a bool option.
|
||||||
// Should be called in init() directly after the modules.Register() function.
|
// Should be called in init() directly after the modules.Register() function.
|
||||||
// The config option must not yet be registered and will be registered for
|
// The config option must not yet be registered and will be registered for
|
||||||
// you. Pass a nil option to force enable.
|
// you. Pass a nil option to force enable.
|
||||||
|
|
|
@ -28,7 +28,7 @@ type Subsystem struct { //nolint:maligned // not worth the effort
|
||||||
// FailureStatus is the worst failure status that is currently
|
// FailureStatus is the worst failure status that is currently
|
||||||
// set in one of the subsystem's dependencies.
|
// set in one of the subsystem's dependencies.
|
||||||
FailureStatus uint8
|
FailureStatus uint8
|
||||||
// ToggleOptionKey holds the key of the configuraiton option
|
// ToggleOptionKey holds the key of the configuration option
|
||||||
// that is used to completely enable or disable this subsystem.
|
// that is used to completely enable or disable this subsystem.
|
||||||
ToggleOptionKey string
|
ToggleOptionKey string
|
||||||
// ExpertiseLevel defines the complexity of the subsystem and is
|
// ExpertiseLevel defines the complexity of the subsystem and is
|
||||||
|
|
|
@ -9,12 +9,10 @@ var (
|
||||||
// DefaultRegistry is the default registry
|
// DefaultRegistry is the default registry
|
||||||
// that is used by the module-level API.
|
// that is used by the module-level API.
|
||||||
DefaultRegistry = NewRegistry()
|
DefaultRegistry = NewRegistry()
|
||||||
|
|
||||||
module *modules.Module
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
module = modules.Register("runtime", nil, startModule, nil, "database")
|
modules.Register("runtime", nil, startModule, nil, "database")
|
||||||
}
|
}
|
||||||
|
|
||||||
func startModule() error {
|
func startModule() error {
|
||||||
|
|
|
@ -36,7 +36,7 @@ var (
|
||||||
// package but may consider creating a dedicated
|
// package but may consider creating a dedicated
|
||||||
// runtime registry on their own. Registry uses
|
// runtime registry on their own. Registry uses
|
||||||
// a radix tree for value providers and their
|
// a radix tree for value providers and their
|
||||||
// choosen database key/prefix.
|
// chosen database key/prefix.
|
||||||
type Registry struct {
|
type Registry struct {
|
||||||
l sync.RWMutex
|
l sync.RWMutex
|
||||||
providers *radix.Tree
|
providers *radix.Tree
|
||||||
|
|
|
@ -43,7 +43,7 @@ func getTestRegistry(t *testing.T) *Registry {
|
||||||
r := NewRegistry()
|
r := NewRegistry()
|
||||||
|
|
||||||
providers := []testProvider{
|
providers := []testProvider{
|
||||||
testProvider{
|
{
|
||||||
k: "p1/",
|
k: "p1/",
|
||||||
r: []record.Record{
|
r: []record.Record{
|
||||||
makeTestRecord("p1/f1/v1", "p1.1"),
|
makeTestRecord("p1/f1/v1", "p1.1"),
|
||||||
|
@ -51,7 +51,7 @@ func getTestRegistry(t *testing.T) *Registry {
|
||||||
makeTestRecord("p1/v3", "p1.3"),
|
makeTestRecord("p1/v3", "p1.3"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
testProvider{
|
{
|
||||||
k: "p2/f1",
|
k: "p2/f1",
|
||||||
r: []record.Record{
|
r: []record.Record{
|
||||||
makeTestRecord("p2/f1/v1", "p2.1"),
|
makeTestRecord("p2/f1/v1", "p2.1"),
|
||||||
|
@ -104,7 +104,7 @@ func TestRegistryQuery(t *testing.T) {
|
||||||
iter, err := reg.Query(q, true, true)
|
iter, err := reg.Query(q, true, true)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, iter)
|
require.NotNil(t, iter)
|
||||||
var records []record.Record
|
var records []record.Record //nolint:prealloc
|
||||||
for r := range iter.Next {
|
for r := range iter.Next {
|
||||||
records = append(records, r)
|
records = append(records, r)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue