mirror of
https://codeberg.org/cunicu/cunicu.git
synced 2025-09-26 21:01:14 +08:00
41 lines
907 B
Go
41 lines
907 B
Go
// SPDX-FileCopyrightText: 2023-2025 Steffen Vogel <post@steffenvogel.de>
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package config
|
|
|
|
import (
|
|
"slices"
|
|
"strings"
|
|
|
|
"cunicu.li/cunicu/pkg/types"
|
|
)
|
|
|
|
type ChangedHandler interface {
|
|
OnConfigChanged(key string, oldValue, newValue any) error
|
|
}
|
|
|
|
func (c *Config) InvokeChangedHandlers(key string, change types.Change) error {
|
|
if err := c.Meta.InvokeChangedHandlers(key, change); err != nil {
|
|
return err
|
|
}
|
|
|
|
// Invoke handlers for per-interface settings
|
|
if keyParts := strings.Split(key, "."); len(keyParts) > 0 && keyParts[0] == "interfaces" {
|
|
pattern := keyParts[1]
|
|
|
|
for name, meta := range c.onInterfaceChanged {
|
|
pats := c.InterfaceOrderByName(name)
|
|
|
|
if slices.Contains(pats, pattern) {
|
|
key := strings.Join(keyParts[2:], ".")
|
|
|
|
if err := meta.InvokeChangedHandlers(key, change); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|