From f462d95ad76e252bfe2632f8d3f717c31aef240c Mon Sep 17 00:00:00 2001 From: Dwi Siswanto Date: Sat, 24 Feb 2024 21:03:42 +0700 Subject: [PATCH] refactor: remove custom YAML validator (#159) Signed-off-by: Dwi Siswanto --- yaml.go | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/yaml.go b/yaml.go index a7458aed..bb6ef649 100644 --- a/yaml.go +++ b/yaml.go @@ -28,37 +28,12 @@ type yamlRule struct { Rules []*yamlCondition `yaml:"rules" validate:"required,dive"` } -func validateYAMLRules(fl validator.FieldLevel) bool { - // Retrieve the YAML string from the field - yamlString, ok := fl.Field().Interface().(string) - if !ok { - return false - } - - // Unmarshal the YAML string into a yamlRule struct - var data yamlRule - err := yaml.Unmarshal([]byte(yamlString), &data) - if err != nil { - return false - } - - // Create a new validator instance - validate := validator.New() - - // Validate the yamlRule struct - err = validate.Struct(data) - return err == nil -} - func yamlToRule(file *os.File) (Rule, error) { defer file.Close() // Create a new validator instance validate := validator.New() - // Register the custom validation function - _ = validate.RegisterValidation("yaml", validateYAMLRules) - // Initialize Rule and slice of yamlRule pointer var rule Rule var yamlRules []*yamlRule