Skip to content

Commit

Permalink
Add Validate method.
Browse files Browse the repository at this point in the history
  • Loading branch information
onrik committed Sep 28, 2023
1 parent 741d724 commit c9b7229
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions yaconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ func Read(filename string, config interface{}) error {
return err
}

errors := validate(config, "")
if len(errors) > 0 {
return fmt.Errorf(strings.Join(errors, ", "))
err = Validate(config)
if err != nil {
return err
}

if v, ok := config.(validator); ok {
Expand All @@ -36,3 +36,12 @@ func Read(filename string, config interface{}) error {

return nil
}

func Validate(config interface{}) error {
errors := validate(config, "")
if len(errors) > 0 {
return fmt.Errorf(strings.Join(errors, ", "))
}

return nil
}

0 comments on commit c9b7229

Please sign in to comment.