Skip to content

Commit

Permalink
refactor: remove custom YAML validator (#159)
Browse files Browse the repository at this point in the history
Signed-off-by: Dwi Siswanto <[email protected]>
  • Loading branch information
dwisiswant0 authored Feb 24, 2024
1 parent 9b5a9d3 commit f462d95
Showing 1 changed file with 0 additions and 25 deletions.
25 changes: 0 additions & 25 deletions yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f462d95

Please sign in to comment.