Documentation ¶
Overview ¶
Package net provides RuleSet implementations for dealing with networks and networked services.
Index ¶
- Variables
- type DomainRuleSet
- func (ruleSet *DomainRuleSet) Any() rules.RuleSet[any]
- func (ruleSet *DomainRuleSet) Evaluate(ctx context.Context, value string) (string, errors.ValidationErrorCollection)
- func (ruleSet *DomainRuleSet) Required() bool
- func (ruleSet *DomainRuleSet) String() string
- func (ruleSet *DomainRuleSet) Validate(value any) (string, errors.ValidationErrorCollection)
- func (ruleSet *DomainRuleSet) ValidateWithContext(value any, ctx context.Context) (string, errors.ValidationErrorCollection)
- func (ruleSet *DomainRuleSet) WithRequired() *DomainRuleSet
- func (ruleSet *DomainRuleSet) WithRule(rule rules.Rule[string]) *DomainRuleSet
- func (v *DomainRuleSet) WithRuleFunc(rule rules.RuleFunc[string]) *DomainRuleSet
- func (v *DomainRuleSet) WithSuffix(suffix string, rest ...string) *DomainRuleSet
- func (v *DomainRuleSet) WithTLD() *DomainRuleSet
- type EmailRuleSet
- func (ruleSet *EmailRuleSet) Any() rules.RuleSet[any]
- func (ruleSet *EmailRuleSet) Evaluate(ctx context.Context, value string) (string, errors.ValidationErrorCollection)
- func (ruleSet *EmailRuleSet) Required() bool
- func (ruleSet *EmailRuleSet) String() string
- func (ruleSet *EmailRuleSet) Validate(value any) (string, errors.ValidationErrorCollection)
- func (ruleSet *EmailRuleSet) ValidateWithContext(value any, ctx context.Context) (string, errors.ValidationErrorCollection)
- func (ruleSet *EmailRuleSet) WithDomain(domainRuleSet rules.RuleSet[any]) *EmailRuleSet
- func (ruleSet *EmailRuleSet) WithRequired() *EmailRuleSet
- func (ruleSet *EmailRuleSet) WithRule(rule rules.Rule[string]) *EmailRuleSet
- func (v *EmailRuleSet) WithRuleFunc(rule rules.RuleFunc[string]) *EmailRuleSet
Constants ¶
This section is empty.
Variables ¶
var TLDs = []string{}/* 1464 elements not displayed */
TLDs is an array of valid Top Level Domains
Functions ¶
This section is empty.
Types ¶
type DomainRuleSet ¶
type DomainRuleSet struct { rules.NoConflict[string] // contains filtered or unexported fields }
DomainRuleSet implements the RuleSet interface for the domain names.
func (*DomainRuleSet) Any ¶
func (ruleSet *DomainRuleSet) Any() rules.RuleSet[any]
Any returns a new RuleSet that wraps the domain RuleSet in any Any rule set which can then be used in nested validation.
func (*DomainRuleSet) Evaluate ¶
func (ruleSet *DomainRuleSet) Evaluate(ctx context.Context, value string) (string, errors.ValidationErrorCollection)
Evaluate performs a validation of a RuleSet against a string and returns an object value of the same type or a ValidationErrorCollection.
func (*DomainRuleSet) Required ¶
func (ruleSet *DomainRuleSet) Required() bool
Required returns a boolean indicating if the value is allowed to be omitted when included in a nested object.
func (*DomainRuleSet) String ¶
func (ruleSet *DomainRuleSet) String() string
String returns a string representation of the rule set suitable for debugging.
func (*DomainRuleSet) Validate ¶
func (ruleSet *DomainRuleSet) Validate(value any) (string, errors.ValidationErrorCollection)
Validate performs a validation of a RuleSet against a value and returns a string value or a ValidationErrorCollection.
func (*DomainRuleSet) ValidateWithContext ¶
func (ruleSet *DomainRuleSet) ValidateWithContext(value any, ctx context.Context) (string, errors.ValidationErrorCollection)
Validate performs a validation of a RuleSet against a value and returns a string value or a ValidationErrorCollection.
Also, takes a Context which can be used by rules and error formatting.
func (*DomainRuleSet) WithRequired ¶
func (ruleSet *DomainRuleSet) WithRequired() *DomainRuleSet
WithRequired returns a new rule set with the required flag set. Use WithRequired when nesting a RuleSet and the a value is not allowed to be omitted.
func (*DomainRuleSet) WithRule ¶
func (ruleSet *DomainRuleSet) WithRule(rule rules.Rule[string]) *DomainRuleSet
WithRule returns a new child rule set with a rule added to the list of rules to evaluate. WithRule takes an implementation of the Rule interface for the string type.
Use this when implementing custom rules.
func (*DomainRuleSet) WithRuleFunc ¶
func (v *DomainRuleSet) WithRuleFunc(rule rules.RuleFunc[string]) *DomainRuleSet
WithRuleFunc returns a new child rule set with a rule added to the list of rules to evaluate. WithRuleFunc takes an implementation of the Rule interface for the string type.
Use this when implementing custom rules.
func (*DomainRuleSet) WithSuffix ¶
func (v *DomainRuleSet) WithSuffix(suffix string, rest ...string) *DomainRuleSet
WithSuffix returns a new child RuleSet that test to see if the domain has a matching suffix.
This method takes one or more domain suffixes which will be used to validate against the domain. Suffix matching is case insensitive.
The validated domain cannot be only the suffix, at least one additional subdomain must be included.
This rule only performs tests against the text of the domain. It does not check if the domain is actually registered or if the DNS is correctly configured. Network access is not required.
WithSuffix will panic is any of the suffix values are not valid domains themselves.
func (*DomainRuleSet) WithTLD ¶
func (v *DomainRuleSet) WithTLD() *DomainRuleSet
WithTLD returns a new child RuleSet that ensures that the domain ends in a valid Top Level Domain (TLD).
The domain is validated against the IANA list of Top Level Domains: http://data.iana.org/TLD/tlds-alpha-by-domain.txt
Actively maintained versions will receive minor updates when the list of TLDs changes so if you use this method it is recommended that you periodically check for updates.
type EmailRuleSet ¶
type EmailRuleSet struct { rules.NoConflict[string] // contains filtered or unexported fields }
EmailRuleSet implements the RuleSet interface for the domain names.
func (*EmailRuleSet) Any ¶
func (ruleSet *EmailRuleSet) Any() rules.RuleSet[any]
Any returns a new RuleSet that wraps the domain RuleSet in any Any rule set which can then be used in nested validation.
func (*EmailRuleSet) Evaluate ¶
func (ruleSet *EmailRuleSet) Evaluate(ctx context.Context, value string) (string, errors.ValidationErrorCollection)
Evaluate performs a validation of a RuleSet against a string and returns an object value of the same type or a ValidationErrorCollection.
func (*EmailRuleSet) Required ¶
func (ruleSet *EmailRuleSet) Required() bool
Required returns a boolean indicating if the value is allowed to be omitted when included in a nested object.
func (*EmailRuleSet) String ¶
func (ruleSet *EmailRuleSet) String() string
String returns a string representation of the rule set suitable for debugging.
func (*EmailRuleSet) Validate ¶
func (ruleSet *EmailRuleSet) Validate(value any) (string, errors.ValidationErrorCollection)
Validate performs a validation of a RuleSet against a value and returns a string value or a ValidationErrorCollection.
func (*EmailRuleSet) ValidateWithContext ¶
func (ruleSet *EmailRuleSet) ValidateWithContext(value any, ctx context.Context) (string, errors.ValidationErrorCollection)
Validate performs a validation of a RuleSet against a value and returns a string value or a ValidationErrorCollection.
Also, takes a Context which can be used by rules and error formatting.
func (*EmailRuleSet) WithDomain ¶
func (ruleSet *EmailRuleSet) WithDomain(domainRuleSet rules.RuleSet[any]) *EmailRuleSet
WithDomain returns a new child rule set with the domain validator assigned to the provided RuleSet instead of the default domain rule set.
The default domain rule set for email validation is the equivalent of:
NewDomain().WithTLD()
func (*EmailRuleSet) WithRequired ¶
func (ruleSet *EmailRuleSet) WithRequired() *EmailRuleSet
WithRequired returns a new rule set with the required flag set. Use WithRequired when nesting a RuleSet and the a value is not allowed to be omitted.
func (*EmailRuleSet) WithRule ¶
func (ruleSet *EmailRuleSet) WithRule(rule rules.Rule[string]) *EmailRuleSet
WithRule returns a new child rule set with a rule added to the list of rules to evaluate. WithRule takes an implementation of the Rule interface for the string type.
Use this when implementing custom rules.
func (*EmailRuleSet) WithRuleFunc ¶
func (v *EmailRuleSet) WithRuleFunc(rule rules.RuleFunc[string]) *EmailRuleSet
WithRuleFunc returns a new child rule set with a rule added to the list of rules to evaluate. WithRuleFunc takes an implementation of the Rule interface for the string type.
Use this when implementing custom rules.