<commit_before>package multiconfig

import (
	"fmt"
	"reflect"

	"github.com/fatih/structs"
)

// Validator validates the config against any predefined rules, those predefined
// rules should be given to this package. The implementer will be responsible
// about the logic
type Validator interface {
	// Validate validates the config struct
	Validate(s interface{}) error
}

// DefaultValidator implements the Validator interface
type DefaultValidator struct {
	Validators []Validator
}

func (d *DefaultValidator) Validate(s interface{}) error {
	if len(d.Validators) == 0 {
		return nil
	}

	for _, validator := range d.Validators {
		if err := validator.Validate(s); err != nil {
			return err
		}
	}

	return nil
}

func NewValidator(validators ...Validator) *DefaultValidator {
	return &DefaultValidator{
		Validators: validators,
	}
}

type RequiredValidator struct {
	TagName  string
	TagValue string
}

// Validate validates the given struct agaist field's zero values. By
// If intentionaly, the value of a field is `zero-valued`(e.g false, 0, "")
// required tag should not be set for that field.
func (e *RequiredValidator) Validate(s interface{}) error {
	if e.TagName == "" {
		e.TagName = "required"
	}

	if e.TagValue == "" {<commit_msg>Multiconfig: add documentation<commit_after>package multiconfig

import (
	"fmt"
	"reflect"

	"github.com/fatih/structs"
)

// Validator validates the config against any predefined rules, those predefined
// rules should be given to this package. The implementer will be responsible
// about the logic
type Validator interface {
	// Validate validates the config struct
	Validate(s interface{}) error
}

// DefaultValidator implements the Validator interface
type DefaultValidator struct {
	Validators []Validator
}

// Validate tries to validate given struct with all the validators. If it doesnt
// have any Validator it will simply skip the validation step. If any of the
// given validators return err, it will stop validating and return it.
func (d *DefaultValidator) Validate(s interface{}) error {
	if len(d.Validators) == 0 {
		return nil
	}

	for _, validator := range d.Validators {
		if err := validator.Validate(s); err != nil {
			return err
		}
	}

	return nil
}

// NewValidator accepts variadic validators and satisfies Validator interface.
func NewValidator(validators ...Validator) *DefaultValidator {
	return &DefaultValidator{
		Validators: validators,
	}
}

// RequiredValidator validates the struct against zero values
type RequiredValidator struct {
	//  TagName holds the validator tag name
	TagName string

	// TagValue holds the expected value of the validator
	TagValue string
}

// Validate validates the given struct agaist field's zero values. By
// If intentionaly, the value of a field is `zero-valued`(e.g false, 0, "")
// required tag should not be set for that field.
func (e *RequiredValidator) Validate(s interface{}) error {
	if e.TagName == "" {
		e.TagName = "required"
	}

	if e.TagValue == "" {
{'fraction_non_alphanumeric': 0.09236947791164658, 'fraction_numerical': 0.0013386880856760374, 'mean_word_length': 3.9983277591973243, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2300751', 'n_tokens_mistral': 883, 'n_tokens_neox': 854, 'n_words': 335}