<commit_before>package ergo

import (
	"strconv"
)

// Param

type Param struct {
	name        string
	description string
	def      interface{}
	as       int
	required bool
	multiple bool
	strSep   string
	file     bool
	inPath   bool
	inQuery  bool
	inHeader bool
	inBody   bool
}

func NewParam(name string) *Param {
	return &Param{
		name: name,
	}
}

func PathParam(name string) *Param {
	return NewParam(name).In(IN_PATH)
}

func QueryParam(name string) *Param {
	return NewParam(name).In(IN_QUERY)
}

func HeaderParam(name string) *Param {
	return NewParam(name).In(IN_HEADER)
}

func BodyParam(name string) *Param {
	return NewParam(name).In(IN_BODY)
}

func (p *Param) Name(name string) *Param {
	p.name = name
	return p
}

func (p *Param) GetName() string {
	return p.name
}

func (p *Param) Description(description string) *Param {
	p.description = description
	return p
}

func (p *Param) GetDescription() string {
	return p.description
}

func (p *Param) Required() *Param {
	p.required = true
	return p
}

func (p *Param) File() *Param {
	p.file = true
	return p
}

func (p *Param) Multiple() *Param {
	p.multiple = true
	return p
}

// If a Param is in path then it is required.
func (p *Param) In(in ...int) *Param {
	for _, i := range in {
		switch i {
		case IN_PATH:
			p.inPath = true
			p.required = true
		case IN_QUERY:
			p.inQuery = true
		case IN_HEADER:
			p.inHeader = true
		case IN_BODY:
			p.inBody = true
		}
	}
	return p
}

type ParamValue struct {
	name             string
	value            interface{}
	strValue         string
	as               int
	strMultipleValue []string
	multiple         bool
	from             string
}

func NewParamValue(name string, value string, from string) *ParamValue {
	return &ParamValue{
		name:     name,
		strValue: value,
		from:     from,
	}
}

func NewMultipleParamValue(name string, value []string, from string) *ParamValue {
	return &ParamValue{
		name:             name,
		strMultipleValue: value,
		multiple:         true,
		from:             from,<commit_msg>Defined validating functions for Param<commit_after>package ergo

import (
	"strconv"

	"github.com/wlMalk/ergo/validation"
)

// Param

type Param struct {
	name        string
	description string
	validators  []validation.Validator
	def         interface{}
	as          int
	required    bool
	multiple    bool
	strSep      string
	file        bool
	inPath      bool
	inQuery     bool
	inHeader    bool
	inBody      bool
}

func NewParam(name string) *Param {
	return &Param{
		name: name,
	}
}

func PathParam(name string) *Param {
	return NewParam(name).In(IN_PATH)
}

func QueryParam(name string) *Param {
	return NewParam(name).In(IN_QUERY)
}

func HeaderParam(name string) *Param {
	return NewParam(name).In(IN_HEADER)
}

func BodyParam(name string) *Param {
	return NewParam(name).In(IN_BODY)
}

func (p *Param) Name(name string) *Param {
	p.name = name
	return p
}

func (p *Param) GetName() string {
	return p.name
}

func (p *Param) Description(description string) *Param {
	p.description = description
	return p
}

func (p *Param) GetDescription() string {
	return p.description
}

func (p *Param) Required() *Param {
	p.required = true
	return p
}

func (p *Param) File() *Param {
	p.file = true
	return p
}

func (p *Param) Multiple() *Param {
	p.multiple = true
	return p
}

func (p *Param) As(as int) *Param {
	p.as = as
	return p
}

// If a Param is in path then it is required.
func (p *Param) In(in ...int) *Param {
	for _, i := range in {
		switch i {
		case IN_PATH:
			p.inPath = true
			p.required = true
		case IN_QUERY:
			p.inQuery = true
		case IN_HEADER:
			p.inHeader = true
		case IN_BODY:
			p.inBody = true
		}
	}
	return p
}

// Validate returns the first error it encountered
func (p *Param) Validate(pv validation.Valuer, r *Request) error {
	for _, v := range p.validators {
		err := v.Validate(pv, r)
		if err != nil {
			return err
		}
	}
	return nil
}

// ValidateAll returns all the errors it encountered
func (p *Param) ValidateAll(pv validation.Valuer, r *Request) []error {
	var errs []error
	for _, v := range p.validators {
		err := v.Validate(pv, r)
		if err != nil {
			errs = append(errs, err)
		}
	}
	return errs
}

type ParamValue struct {
	name             string
	value            interface{}
	strValue         string
	as               int
	strMultipleValue []string
	multiple         bool
	from             string
}

func NewParamValue(name string, value string, from string) *ParamValue {
	return &ParamValue{
		name:     name,
		strValue: value,
		from:     from,
	}
}

func NewMultipleParamValue(name string, value []string, from string) *ParamValue {
	return &ParamValue{
		name:             name,
		strMultipleValue: value,
		multiple:         true,
		from:             from,
{'fraction_non_alphanumeric': 0.10299979022445983, 'fraction_numerical': 0.0, 'mean_word_length': 2.7901430842607313, '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': '5943794', 'n_tokens_mistral': 1708, 'n_tokens_neox': 1657, 'n_words': 514}