lncfg/interface: define Validator iface + variadic Validate
This commit introduces the Validator interface, which is intended to be implemented by any sub configs. It specifies a Validate() error method that should fail if a sub configuration contains any invalid or insane parameters. In addition, a package-level Validate method can be used to check a variadic number of sub configs implementing the Validator interface. This allows the primary config struct to be extended via targeted and/or specialized sub configs, and validate all of them in sequence without bloating the main package with the actual validation logic.
This commit is contained in:
2 files changed
+24
No files matched your search
@@ -47,3 +47,6 @@ func (w *Workers) Validate() error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Compile-time constraint to ensure Workers implements the Validator interface.
|
||||
var _ Validator = (*Workers)(nil)
|
||||
Reference in new issue
Block a user