<commit_before>// Package check allows data validation of values in different types
package check

import (
	"fmt"
	"reflect"
	"strings"
)

var (
	// ErrorMessages contains default error messages
	ErrorMessages = map[string]string{
		"nonZero":     "value cannot be empty",
		"before":      "%v is not before %v",
		"after":       "%v is not after %v",
		"lowerThan":   "%v is not lower than %v",
		"greaterThan": "%v is not greater than %v",
		"minChar":     "too short, minimum %v characters",
		"maxChar":     "too long, minimum %v characters",
		"email":       "'%v' is an invalid email address",
		"regex":       "'%v' does not match '%v'",
		"uuid":        "'%v' is an invalid uuid",
	}
)

// Validator is an interface for constraint types with a method of validate()
type Validator interface {
	// Validate check value against constraints
	Validate(v interface{}) Error
}

// Struct allows validation of structs
type Struct map[string]Validator

// Validate execute validation using the validators.
func (s Struct) Validate(v interface{}) StructError {
	val := reflect.ValueOf(v)

	if val.Kind() == reflect.Ptr {
		val = val.Elem()
	}

	if val.Kind() != reflect.Struct {
		panic("not a struct")
	}

	e := StructError{}
	for fieldname, validator := range s {
		field := val.FieldByName(fieldname)
		if err := validator.Validate(field.Interface()); err != nil {
			if _, ok := e[fieldname]; !ok {
				e[fieldname] = make([]Error, 0)
			}
<commit_msg>Struct: Now checks if the field name is invalid, panics<commit_after>// Package check allows data validation of values in different types
package check

import (
	"fmt"
	"reflect"
	"strings"
)

var (
	// ErrorMessages contains default error messages
	ErrorMessages = map[string]string{
		"nonZero":     "value cannot be empty",
		"before":      "%v is not before %v",
		"after":       "%v is not after %v",
		"lowerThan":   "%v is not lower than %v",
		"greaterThan": "%v is not greater than %v",
		"minChar":     "too short, minimum %v characters",
		"maxChar":     "too long, minimum %v characters",
		"email":       "'%v' is an invalid email address",
		"regex":       "'%v' does not match '%v'",
		"uuid":        "'%v' is an invalid uuid",
	}
)

// Validator is an interface for constraint types with a method of validate()
type Validator interface {
	// Validate check value against constraints
	Validate(v interface{}) Error
}

// Struct allows validation of structs
type Struct map[string]Validator

// Validate execute validation using the validators.
func (s Struct) Validate(v interface{}) StructError {
	val := reflect.ValueOf(v)

	if val.Kind() == reflect.Ptr {
		val = val.Elem()
	}

	if val.Kind() != reflect.Struct {
		panic("not a struct")
	}

	e := StructError{}
	for fieldname, validator := range s {
		field := val.FieldByName(fieldname)

		if field.Kind() == reflect.Invalid {
			panic("invalid struct field name \""+fieldname+"\".")
		}

		if err := validator.Validate(field.Interface()); err != nil {
			if _, ok := e[fieldname]; !ok {
				e[fieldname] = make([]Error, 0)
			}

{'fraction_non_alphanumeric': 0.14047151277013753, 'fraction_numerical': 0.0006548788474132286, 'mean_word_length': 3.45985401459854, 'pattern_counts': {'":': 20, '<': 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': '2506252', 'n_tokens_mistral': 990, 'n_tokens_neox': 953, 'n_words': 347}