mirror of
https://github.com/speatzle/nfsense.git
synced 2025-05-11 19:08:20 +00:00
Add Config Clone
This commit is contained in:
parent
29bfd7f708
commit
f6bcffd8df
1 changed files with 15 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
|||
package definitions
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
|
@ -14,6 +15,20 @@ type Config struct {
|
|||
Network Network `json:"network" validate:"required,dive"`
|
||||
}
|
||||
|
||||
// Clone TODO find a better way to deep copy
|
||||
func (c *Config) Clone() *Config {
|
||||
data, err := json.Marshal(c)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("Marshal Error: %w", err))
|
||||
}
|
||||
var clone Config
|
||||
err = json.Unmarshal(data, &clone)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("Unmarshal Error: %w", err))
|
||||
}
|
||||
return &clone
|
||||
}
|
||||
|
||||
func ValidateConfig(conf *Config) error {
|
||||
val := validator.New()
|
||||
val.RegisterValidation("test", nilIfOtherNil)
|
||||
|
|
Loading…
Add table
Reference in a new issue