Documentation
¶
Overview ¶
Package validation is used to define entry validators and rules. It contains a few general rule types (see validation/rules/rules.go), and you can also create new rules using the Rule interface.
To create a validating rule suite, initialize the Validator struct using a slice of Rule instances. Use the Validator.Validate or ValidateEntry functions to have one or more entries validated. Implemented validators are found in sub package validation/validators.
Index ¶
- func ToString(r Rule) string
- type Result
- type Rule
- type TestResult
- type TestResultContainer
- type Validator
- func (v Validator) AllTests() ([]lex.Entry, []lex.Entry)
- func (v Validator) IsDefined() bool
- func (v Validator) NumberOfTests() int
- func (v Validator) RunTests() (TestResultContainer, error)
- func (v Validator) String() string
- func (v Validator) ValidateEntries(entries []lex.Entry) ([]lex.Entry, bool)
- func (v Validator) ValidateEntry(e *lex.Entry)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Result ¶
Result is a validation result with the following fields:
RuleName - arbitrary string Level - typically indicating severity (e.g. Info/Warning/Fatal/Format/Severe) Messages - arbitrary strings representing validation messages to the user
type Rule ¶
type Rule interface {
Validate(lex.Entry) (Result, error)
ShouldAccept() []lex.Entry
ShouldReject() []lex.Entry
Name() string
Level() string
}
Rule interface. To create a validation.Rule, make a struct implementing Validate, ShouldAccept and ShouldReject as defined in this interface.
type TestResult ¶
TestResult holds the test result for a tested rule suite (accept, reject, or cross tests result)
func (TestResult) String ¶ added in v0.4.1
func (tr TestResult) String() string
type TestResultContainer ¶
type TestResultContainer struct {
AcceptErrors []TestResult
RejectErrors []TestResult
CrossErrors []TestResult
}
TestResultContainer is a container class for accept/reject/crosscheck test result
func (TestResultContainer) AllErrors ¶
func (tc TestResultContainer) AllErrors() []TestResult
AllErrors returns all errors in the TestResultContainer
func (TestResultContainer) Size ¶
func (tc TestResultContainer) Size() int
Size returns the total number of errors in the TestResultContainer
type Validator ¶
Validator is a struct containing a slice of rules
func (Validator) IsDefined ¶
IsDefined is used to check if the validator is initialized (by checking that the validator has a non-empty name).
func (Validator) NumberOfTests ¶ added in v0.4.1
func (Validator) RunTests ¶
func (v Validator) RunTests() (TestResultContainer, error)
RunTests runs accept/reject tests for all individual rules, and cross checks all accept tests against the other rules
func (Validator) ValidateEntries ¶
ValidateEntries is used to validate a slice of entries. Any validation errors are added to each entry's EntryValidations field. The function returns true if the entry is valid (i.e., no validation issues are found), otherwise false.
func (Validator) ValidateEntry ¶
ValidateEntry is used to validate single entries. Any validation errors are added to the entry's EntryValidations field.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package locale is meant to be used to validate a locale specified for a lexicon.
|
Package locale is meant to be used to validate a locale specified for a lexicon. |
|
Package rules contains a few general validation rule types.
|
Package rules contains a few general validation rule types. |
|
Package validators contains a validator service for caching loaded validators, and it contains language and project specific validators.
|
Package validators contains a validator service for caching loaded validators, and it contains language and project specific validators. |