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) Apply(ctx context.Context, input any, output any) errors.ValidationErrorCollection
- func (ruleSet *DomainRuleSet) Evaluate(ctx context.Context, value string) errors.ValidationErrorCollection
- func (ruleSet *DomainRuleSet) Required() bool
- func (ruleSet *DomainRuleSet) String() string
- 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) Apply(ctx context.Context, input any, output any) errors.ValidationErrorCollection
- func (ruleSet *EmailRuleSet) Evaluate(ctx context.Context, value string) errors.ValidationErrorCollection
- func (ruleSet *EmailRuleSet) Required() bool
- func (ruleSet *EmailRuleSet) String() string
- func (ruleSet *EmailRuleSet) WithDomain(domainRuleSet rules.RuleSet[string]) *EmailRuleSet
- func (ruleSet *EmailRuleSet) WithRequired() *EmailRuleSet
- func (ruleSet *EmailRuleSet) WithRule(rule rules.Rule[string]) *EmailRuleSet
- func (v *EmailRuleSet) WithRuleFunc(rule rules.RuleFunc[string]) *EmailRuleSet
- type URIRuleSet
- func (ruleSet *URIRuleSet) Any() rules.RuleSet[any]
- func (ruleSet *URIRuleSet) Apply(ctx context.Context, input any, output any) errors.ValidationErrorCollection
- func (ruleSet *URIRuleSet) DeepErrors() bool
- func (ruleSet *URIRuleSet) Evaluate(ctx context.Context, value string) errors.ValidationErrorCollection
- func (ruleSet *URIRuleSet) Relative() bool
- func (ruleSet *URIRuleSet) Required() bool
- func (ruleSet *URIRuleSet) String() string
- func (ruleSet *URIRuleSet) WithAllowedPorts(value int, rest ...int) *URIRuleSet
- func (ruleSet *URIRuleSet) WithAllowedSchemes(value string, rest ...string) *URIRuleSet
- func (ruleSet *URIRuleSet) WithDeepErrors() *URIRuleSet
- func (ruleSet *URIRuleSet) WithFragmentRequired() *URIRuleSet
- func (ruleSet *URIRuleSet) WithHostRequired() *URIRuleSet
- func (ruleSet *URIRuleSet) WithMaxPort(max int) *URIRuleSet
- func (ruleSet *URIRuleSet) WithMinPort(min int) *URIRuleSet
- func (ruleSet *URIRuleSet) WithPasswordRequired() *URIRuleSet
- func (ruleSet *URIRuleSet) WithPortRequired() *URIRuleSet
- func (ruleSet *URIRuleSet) WithQueryRequired() *URIRuleSet
- func (ruleSet *URIRuleSet) WithRelative() *URIRuleSet
- func (ruleSet *URIRuleSet) WithRequired() *URIRuleSet
- func (ruleSet *URIRuleSet) WithRule(rule rules.Rule[string]) *URIRuleSet
- func (ruleSet *URIRuleSet) WithRuleFunc(rule rules.RuleFunc[string]) *URIRuleSet
- func (ruleSet *URIRuleSet) WithUserRequired() *URIRuleSet
Constants ¶
This section is empty.
Variables ¶
var TLDs = []string{}/* 1446 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) Apply ¶ added in v0.3.0
func (ruleSet *DomainRuleSet) Apply(ctx context.Context, input any, output any) errors.ValidationErrorCollection
Apply performs a validation of a RuleSet against a value and assigns the result to the output parameter. It returns a ValidationErrorCollection if any validation errors occur.
func (*DomainRuleSet) Evaluate ¶
func (ruleSet *DomainRuleSet) Evaluate(ctx context.Context, value 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) 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) Apply ¶ added in v0.3.0
func (ruleSet *EmailRuleSet) Apply(ctx context.Context, input any, output any) errors.ValidationErrorCollection
Apply performs a validation of a RuleSet against a value and assigns the result to the output parameter. It returns a ValidationErrorCollection if any validation errors occur.
func (*EmailRuleSet) Evaluate ¶
func (ruleSet *EmailRuleSet) Evaluate(ctx context.Context, value 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) WithDomain ¶
func (ruleSet *EmailRuleSet) WithDomain(domainRuleSet rules.RuleSet[string]) *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.
type URIRuleSet ¶ added in v0.3.0
type URIRuleSet struct { rules.NoConflict[string] // contains filtered or unexported fields }
URIRuleSet implements the RuleSet interface for URIs.
It is slightly less efficient than other URI validators because it focuses on being able to evaluate each part of the URI independently and return very specific errors rather than simple regular expressions. This leads to the ability to have modular and testable rules for individual parts of the URL.
func (*URIRuleSet) Any ¶ added in v0.3.0
func (ruleSet *URIRuleSet) Any() rules.RuleSet[any]
Any returns a new RuleSet that wraps the URI RuleSet in any Any rule set which can then be used in nested validation.
func (*URIRuleSet) Apply ¶ added in v0.3.0
func (ruleSet *URIRuleSet) Apply(ctx context.Context, input any, output any) errors.ValidationErrorCollection
Apply performs a validation of a RuleSet against a value and assigns the result to the output parameter. It returns a ValidationErrorCollection if any validation errors occur.
func (*URIRuleSet) DeepErrors ¶ added in v0.3.0
func (ruleSet *URIRuleSet) DeepErrors() bool
DeepErrors returns a boolean indicating if the the rule set is set to return deep errors. If deep errors are not set then the paths returned in validation errors should point to the string itself and not the segment within the string.
See WithDeepErrors for examples.
func (*URIRuleSet) Evaluate ¶ added in v0.3.0
func (ruleSet *URIRuleSet) Evaluate(ctx context.Context, value 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 (*URIRuleSet) Relative ¶ added in v0.3.0
func (ruleSet *URIRuleSet) Relative() bool
Relative returns a boolean indicating if the the rule set is set to allow relative URIs.
func (*URIRuleSet) Required ¶ added in v0.3.0
func (ruleSet *URIRuleSet) Required() bool
Required returns a boolean indicating if the value is allowed to be omitted when included in a nested object.
func (*URIRuleSet) String ¶ added in v0.3.0
func (ruleSet *URIRuleSet) String() string
String returns a string representation of the rule set suitable for debugging.
func (*URIRuleSet) WithAllowedPorts ¶ added in v0.3.0
func (ruleSet *URIRuleSet) WithAllowedPorts(value int, rest ...int) *URIRuleSet
WithAllowedPorts returns a new child RuleSet that is checked against the provided list of allowed values.
This method can be called more than once and the allowed values are cumulative. Allowed values must still pass all other rules.
func (*URIRuleSet) WithAllowedSchemes ¶ added in v0.3.0
func (ruleSet *URIRuleSet) WithAllowedSchemes(value string, rest ...string) *URIRuleSet
WithAllowedSchemes returns a new child RuleSet that is checked against the provided list of allowed values.
This method can be called more than once and the allowed values are cumulative. Allowed values must still pass all other rules.
func (*URIRuleSet) WithDeepErrors ¶ added in v0.3.0
func (ruleSet *URIRuleSet) WithDeepErrors() *URIRuleSet
WithDeepErrors returns a new rule set with the deep errors flag set. By default URIRuleSet will return the path to the string itself when returning errors. Setting deep errors will tell the rules to return the rull path to the error nested inside the string.
For example,the URI https://example.com:-1/ has an invalid port numbers (ports can not be negative). By default the path may look like this: `/myobj/some_uri` With deep errors the path may look like this: `/myobj/some_uri/port`
func (*URIRuleSet) WithFragmentRequired ¶ added in v0.3.0
func (ruleSet *URIRuleSet) WithFragmentRequired() *URIRuleSet
WithFragmentRequired returns a new rule set with the fragment set to required. The fragment must be in the URI, however, it may be empty.
func (*URIRuleSet) WithHostRequired ¶ added in v0.3.0
func (ruleSet *URIRuleSet) WithHostRequired() *URIRuleSet
WithHostRequired returns a new rule set with the host set to required. The host must be in the URI, however, it may be empty.
func (*URIRuleSet) WithMaxPort ¶ added in v0.3.0
func (ruleSet *URIRuleSet) WithMaxPort(max int) *URIRuleSet
WithPortMax returns a new rule set with the port maximum set.
func (*URIRuleSet) WithMinPort ¶ added in v0.3.0
func (ruleSet *URIRuleSet) WithMinPort(min int) *URIRuleSet
WithPortMin returns a new rule set with the port minimum set.
func (*URIRuleSet) WithPasswordRequired ¶ added in v0.3.0
func (ruleSet *URIRuleSet) WithPasswordRequired() *URIRuleSet
WithPasswordRequired returns a new rule set with the password set to required. The password must be in the URI, however, it may be empty.
func (*URIRuleSet) WithPortRequired ¶ added in v0.3.0
func (ruleSet *URIRuleSet) WithPortRequired() *URIRuleSet
WithPortRequired returns a new rule set with the port set to required. The port must be in the URI, however, it may be empty.
func (*URIRuleSet) WithQueryRequired ¶ added in v0.3.0
func (ruleSet *URIRuleSet) WithQueryRequired() *URIRuleSet
WithQueryRequired returns a new rule set with the query set to required. The query must be in the URI, however, it may be empty.
func (*URIRuleSet) WithRelative ¶ added in v0.3.0
func (ruleSet *URIRuleSet) WithRelative() *URIRuleSet
WithRelative returns a new rule set with the relative flag set. By default URIRuleSet requires all parts of the URI to be specified. WithRelative will allow some parts of the URI to be omitted.
Scheme is normally required for URIs but is optional if relative URIs are enabled.
func (*URIRuleSet) WithRequired ¶ added in v0.3.0
func (ruleSet *URIRuleSet) WithRequired() *URIRuleSet
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 (*URIRuleSet) WithRule ¶ added in v0.3.0
func (ruleSet *URIRuleSet) WithRule(rule rules.Rule[string]) *URIRuleSet
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.
In addition to the normal context values available to all rules, for URI rules the following values will always be set (but may be empty strings): - scheme - authority - path - query - fragment - port - userinfo - user - password
func (*URIRuleSet) WithRuleFunc ¶ added in v0.3.0
func (ruleSet *URIRuleSet) WithRuleFunc(rule rules.RuleFunc[string]) *URIRuleSet
WithRuleFunc returns a new child rule set with a rule added to the list of rules to evaluate. WithRuleFunc takes an implementation of the RuleFunc interface for the string type.
Use this when implementing custom rules.
In addition to the normal context values available to all rules, for URI rules the following values will always be set (but may be empty strings): - scheme - authority - path - query - fragment - port - userinfo - user - password
func (*URIRuleSet) WithUserRequired ¶ added in v0.3.0
func (ruleSet *URIRuleSet) WithUserRequired() *URIRuleSet
WithUserRequired returns a new rule set with the user set to required. The user must be in the URI, however, it may be empty.