Documentation ¶
Index ¶
- func MakeNDLVRError(msg, code string) error
- type ArgumentParser
- type DefaultArgumentParser
- func (parser *DefaultArgumentParser) ParseLen(ctx context.Context, v interface{}) (res int, err error)
- func (parser *DefaultArgumentParser) ParseListValue(ctx context.Context, v interface{}) (lv value.ListValue, err error)
- func (parser *DefaultArgumentParser) ParsePrimitiveValue(ctx context.Context, v interface{}) (pv *value.PrimitiveValue, err error)
- func (parser *DefaultArgumentParser) ParseRulesSource(ctx context.Context, arg interface{}) (rules RulesSource, err error)
- func (parser *DefaultArgumentParser) ParseTopRulesSource(ctx context.Context, arg interface{}) (rules TopRulesSource, err error)
- type DefaultValidator
- type Engine
- type ErrorBag
- type Options
- type Parser
- type RuleData
- type RuleParseError
- type RuleReceiver
- type RulesMap
- type RulesSource
- type SliceRules
- type TopLevelRuleData
- type TopLevelRuleReceiver
- type TopRulesSource
- type Validation
- type ValidationAsFactory
- type ValidationBuildContext
- type ValidationBuildData
- type ValidationCreateError
- type ValidationFactory
- type ValidationFactoryFunc
- type ValidationFactoryRegistry
- type ValidationFunc
- type ValidationNameMismatchError
- type ValidationNotSupportedError
- type ValidationTarget
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MakeNDLVRError ¶
Types ¶
type ArgumentParser ¶
type ArgumentParser interface { // Parses length from argument given. ParseLen(ctx context.Context, arg interface{}) (sz int, err error) ParsePrimitiveValue(ctx context.Context, arg interface{}) (pv *value.PrimitiveValue, err error) ParseListValue(ctx context.Context, arg interface{}) (lv value.ListValue, err error) ParseRulesSource(ctx context.Context, arg interface{}) (rules RulesSource, err error) ParseTopRulesSource(ctx context.Context, arg interface{}) (rules TopRulesSource, err error) }
Helper, which makes parsing incoming validation's argument simpler.
type DefaultArgumentParser ¶
type DefaultArgumentParser struct{}
func (*DefaultArgumentParser) ParseLen ¶
func (parser *DefaultArgumentParser) ParseLen(ctx context.Context, v interface{}) (res int, err error)
func (*DefaultArgumentParser) ParseListValue ¶
func (*DefaultArgumentParser) ParsePrimitiveValue ¶
func (parser *DefaultArgumentParser) ParsePrimitiveValue(ctx context.Context, v interface{}) (pv *value.PrimitiveValue, err error)
func (*DefaultArgumentParser) ParseRulesSource ¶ added in v0.0.2
func (parser *DefaultArgumentParser) ParseRulesSource(ctx context.Context, arg interface{}) (rules RulesSource, err error)
func (*DefaultArgumentParser) ParseTopRulesSource ¶ added in v0.0.2
func (parser *DefaultArgumentParser) ParseTopRulesSource(ctx context.Context, arg interface{}) (rules TopRulesSource, err error)
type DefaultValidator ¶
type Options ¶
type Options struct {
ValidationFactory ValidationFactory
}
func (*Options) NewEngineWithTarget ¶ added in v0.0.2
func (opts *Options) NewEngineWithTarget(ctx context.Context, rules RulesSource, target ValidationTarget) (v Engine, err error)
This is used to compile embedded validations - validations in validations. It *should* not be used by user code, unless user is implementing custom validation.
type Parser ¶
type Parser struct{}
Parser, which is used to parse LIVR rules into immediate representation, which can be used to construct Validations and Validators. For now it has no options.
func (*Parser) ParseInnerEntry ¶
func (p *Parser) ParseInnerEntry(rawRule interface{}, recv RuleReceiver) (err error)
Just like ParseTopLevelRules, but disallows list. This way nested lists in rules are not allowed.
Think of: ``` ... "asdf": [ ["required"] ] // Not allowed "fdsa": [ "required", { "list_of_objects" : { ... }}] // Ok ... ```
func (*Parser) ParseTopLevelEntry ¶
func (p *Parser) ParseTopLevelEntry(rawRule interface{}, recv RuleReceiver) (err error)
type RuleParseError ¶
type RuleParseError struct {
Rule interface{}
}
func (*RuleParseError) Error ¶
func (e *RuleParseError) Error() string
type RuleReceiver ¶
type RulesMap ¶
type RulesMap map[string]interface{}
RulesMap defines type to deserialize from JSON when parsing is required.
type RulesSource ¶
Returns set of rules for single field.
type SliceRules ¶ added in v0.0.2
type SliceRules []interface{}
func (SliceRules) GetRules ¶ added in v0.0.2
func (srs SliceRules) GetRules(recv func(rawRule interface{}) (err error)) (err error)
type TopLevelRuleData ¶ added in v0.0.2
type TopLevelRuleReceiver ¶ added in v0.0.2
type TopLevelRuleReceiver = func(rd TopLevelRuleData) (err error)
type TopRulesSource ¶ added in v0.0.2
type TopRulesSource interface { // Note: each key may be yielded only once. GetRules(recv func(fieldName string, rawRule interface{}) (err error)) (err error) }
TopRulesSource is top-level source of rules. For each key it returns rules.
Usually, it's JSON parsed map but in future go tags probably will be supported.
type Validation ¶
type Validation interface { // Note: validate MUST NOT modify value. Validate(ctx context.Context, parentValue value.Value) (err error) }
Validation validates specified key, but has access to whole value, so things like checking if fields are same work.
type ValidationAsFactory ¶
type ValidationAsFactory func(bctx ValidationBuildContext, value value.Value) (err error)
func (ValidationAsFactory) BuildValidation ¶
func (f ValidationAsFactory) BuildValidation(bctx ValidationBuildContext) (val Validation, err error)
type ValidationBuildContext ¶
type ValidationBuildContext struct { Ctx context.Context Options *Options Parser *Parser OPs value.OPs ArgumentParser ArgumentParser Data ValidationBuildData }
type ValidationBuildData ¶
type ValidationBuildData struct { Target ValidationTarget ValidationName string Argument interface{} }
type ValidationCreateError ¶
type ValidationCreateError struct {
Msg string
}
func (*ValidationCreateError) Error ¶
func (e *ValidationCreateError) Error() string
type ValidationFactory ¶
type ValidationFactory interface {
BuildValidation(bctx ValidationBuildContext) (val Validation, err error)
}
func SimpleFieldValidation ¶
func SimpleFieldValidation( require bool, inner func(bctx ValidationBuildContext, parentValue value.Value, fieldValue value.Value) (err error), ) ValidationFactory
SimpleFieldValidation, which accesses value of field passed in build data.
func WrapNamed ¶
func WrapNamed(name string, factory ValidationFactory) ValidationFactory
Wraps specified factory, in one which verifies validaton name and returns error on mismatch.
type ValidationFactoryFunc ¶
type ValidationFactoryFunc func(bctx ValidationBuildContext) (val Validation, err error)
func (ValidationFactoryFunc) BuildValidation ¶
func (f ValidationFactoryFunc) BuildValidation(bctx ValidationBuildContext) (val Validation, err error)
type ValidationFactoryRegistry ¶
type ValidationFactoryRegistry map[string]ValidationFactory
ValidationFactoryRegistry is registry of factories, which always directs same validation name to same factory.
func (ValidationFactoryRegistry) BuildValidation ¶
func (reg ValidationFactoryRegistry) BuildValidation(bctx ValidationBuildContext) (val Validation, err error)
func (ValidationFactoryRegistry) MustPut ¶
func (reg ValidationFactoryRegistry) MustPut(name string, valFac ValidationFactory)
MustPut puts ValidationFactory with given name. Fails if one with given name is already set. Registry must not be nil map.
func (ValidationFactoryRegistry) Set ¶
func (reg ValidationFactoryRegistry) Set(name string, valFac ValidationFactory)
Sets ValidationFactory with given name. Overrides one if was set already. Registry must not be nil map.
type ValidationFunc ¶
type ValidationNameMismatchError ¶
func (*ValidationNameMismatchError) Error ¶
func (e *ValidationNameMismatchError) Error() string
type ValidationNotSupportedError ¶
type ValidationNotSupportedError struct {
Name string
}
func (*ValidationNotSupportedError) Error ¶
func (e *ValidationNotSupportedError) Error() string
type ValidationTarget ¶ added in v0.0.2
type ValidationTarget struct { FunctionalTarget func(v value.Value, recv func(child value.Value) (err error)) (err error) IsOrphanValue bool // ignored when FunctionalTarget IsListValue bool // ignored when FunctionalTarget or IsOrphanValue is set FieldName string // ignored when FunctionalTarget or IsOrphanValue or IsListValue is set }
Defines what this validation is running on.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
internal
|
|
Package value defined Values that LIVR operate on to mimic all kinds of strange behaviour like eq changing value type.
|
Package value defined Values that LIVR operate on to mimic all kinds of strange behaviour like eq changing value type. |