Documentation ¶
Overview ¶
Package jsval implements an input validator, based on JSON Schema. The main purpose is to validate JSON Schemas (see https://github.com/lestrrat-go/jsschema), and to automatically generate validators from schemas, but jsval can be used independently of JSON Schema.
Index ¶
- Variables
- type AllConstraint
- type AnyConstraint
- type ArrayConstraint
- func (c *ArrayConstraint) AdditionalItems(ac Constraint) *ArrayConstraint
- func (dv ArrayConstraint) DefaultValue() interface{}
- func (dv ArrayConstraint) HasDefault() bool
- func (c *ArrayConstraint) Items(ac Constraint) *ArrayConstraint
- func (c *ArrayConstraint) MaxItems(i int) *ArrayConstraint
- func (c *ArrayConstraint) MinItems(i int) *ArrayConstraint
- func (c *ArrayConstraint) PositionalItems(ac []Constraint) *ArrayConstraint
- func (c *ArrayConstraint) UniqueItems(b bool) *ArrayConstraint
- func (c *ArrayConstraint) Validate(v interface{}) (err error)
- type BooleanConstraint
- type Constraint
- type ConstraintMap
- type EnumConstraint
- type ErrInvalidMaybeValue
- type Generator
- type IntegerConstraint
- func (ic *IntegerConstraint) Default(v interface{}) *IntegerConstraint
- func (dv IntegerConstraint) DefaultValue() interface{}
- func (ic *IntegerConstraint) ExclusiveMaximum(b bool) *IntegerConstraint
- func (ic *IntegerConstraint) ExclusiveMinimum(b bool) *IntegerConstraint
- func (dv IntegerConstraint) HasDefault() bool
- func (ic *IntegerConstraint) Maximum(n float64) *IntegerConstraint
- func (ic *IntegerConstraint) Minimum(n float64) *IntegerConstraint
- func (ic *IntegerConstraint) Validate(v interface{}) (err error)
- type JSVal
- type JSValSlice
- type Maybe
- type MaybeBool
- type MaybeFloat
- type MaybeInt
- type MaybeString
- type MaybeTime
- type MaybeUint
- type NotConstraint
- type NumberConstraint
- func (nc *NumberConstraint) Default(v interface{}) *NumberConstraint
- func (dv NumberConstraint) DefaultValue() interface{}
- func (nc *NumberConstraint) Enum(l ...interface{}) *NumberConstraint
- func (nc *NumberConstraint) ExclusiveMaximum(b bool) *NumberConstraint
- func (nc *NumberConstraint) ExclusiveMinimum(b bool) *NumberConstraint
- func (dv NumberConstraint) HasDefault() bool
- func (nc *NumberConstraint) Maximum(n float64) *NumberConstraint
- func (nc *NumberConstraint) Minimum(n float64) *NumberConstraint
- func (nc *NumberConstraint) MultipleOf(n float64) *NumberConstraint
- func (nc *NumberConstraint) Validate(v interface{}) (err error)
- type ObjectConstraint
- func (o *ObjectConstraint) AddProp(name string, c Constraint) *ObjectConstraint
- func (o *ObjectConstraint) AdditionalProperties(c Constraint) *ObjectConstraint
- func (dv ObjectConstraint) DefaultValue() interface{}
- func (o *ObjectConstraint) GetPropDependencies(from string) []string
- func (o *ObjectConstraint) GetSchemaDependency(from string) Constraint
- func (dv ObjectConstraint) HasDefault() bool
- func (o *ObjectConstraint) IsPropRequired(s string) bool
- func (o *ObjectConstraint) MaxProperties(n int) *ObjectConstraint
- func (o *ObjectConstraint) MinProperties(n int) *ObjectConstraint
- func (o *ObjectConstraint) PatternProperties(key *regexp.Regexp, c Constraint) *ObjectConstraint
- func (o *ObjectConstraint) PatternPropertiesString(key string, c Constraint) *ObjectConstraint
- func (o *ObjectConstraint) PropDependency(from string, to ...string) *ObjectConstraint
- func (o *ObjectConstraint) Required(l ...string) *ObjectConstraint
- func (o *ObjectConstraint) SchemaDependency(from string, c Constraint) *ObjectConstraint
- func (o *ObjectConstraint) Validate(v interface{}) (err error)
- type OneOfConstraint
- type PropInfo
- type RefResolver
- type ReferenceConstraint
- func (r *ReferenceConstraint) Default(_ interface{})
- func (r *ReferenceConstraint) DefaultValue() interface{}
- func (r *ReferenceConstraint) HasDefault() bool
- func (r *ReferenceConstraint) RefersTo(s string) *ReferenceConstraint
- func (r *ReferenceConstraint) Resolved() (c Constraint, err error)
- func (r *ReferenceConstraint) Validate(v interface{}) (err error)
- type StringConstraint
- func (sc *StringConstraint) Default(v interface{}) *StringConstraint
- func (dv StringConstraint) DefaultValue() interface{}
- func (sc *StringConstraint) Enum(l ...interface{}) *StringConstraint
- func (sc *StringConstraint) Format(f string) *StringConstraint
- func (dv StringConstraint) HasDefault() bool
- func (sc *StringConstraint) MaxLength(l int) *StringConstraint
- func (sc *StringConstraint) MinLength(l int) *StringConstraint
- func (sc *StringConstraint) Regexp(rx *regexp.Regexp) *StringConstraint
- func (sc *StringConstraint) RegexpString(pat string) *StringConstraint
- func (sc *StringConstraint) Validate(v interface{}) (err error)
- type StructInfo
- type StructInfoRegistry
- type ValidFlag
Constants ¶
This section is empty.
Variables ¶
var EmptyConstraint = emptyConstraint{}
EmptyConstraint is a constraint that returns true for any value
var NullConstraint = nullConstraint{}
NullConstraint is a constraint that only matches the JSON "null" value, or "nil" in golang
Functions ¶
This section is empty.
Types ¶
type AllConstraint ¶
type AllConstraint struct {
// contains filtered or unexported fields
}
AllConstraint implements a constraint where all of the child constraints' validation must pass in order for this validation to pass.
func (*AllConstraint) Add ¶
func (c *AllConstraint) Add(c2 Constraint) *AllConstraint
Add appends a new Constraint
func (*AllConstraint) Constraints ¶
func (c *AllConstraint) Constraints() []Constraint
func (*AllConstraint) Reduce ¶
func (c *AllConstraint) Reduce() Constraint
Reduce returns the child Constraint, if this constraint has only 1 child constraint.
func (*AllConstraint) Validate ¶
func (c *AllConstraint) Validate(v interface{}) (err error)
Validate validates the value against the input value. For AllConstraints, it will only return success if all of the child Constraints succeeded.
type AnyConstraint ¶
type AnyConstraint struct {
// contains filtered or unexported fields
}
AnyConstraint implements a constraint where at least 1 child constraint must pass in order for this validation to pass.
func (*AnyConstraint) Add ¶
func (c *AnyConstraint) Add(c2 Constraint) *AnyConstraint
Add appends a new Constraint
func (*AnyConstraint) Constraints ¶
func (c *AnyConstraint) Constraints() []Constraint
func (*AnyConstraint) Reduce ¶
func (c *AnyConstraint) Reduce() Constraint
Reduce returns the child Constraint, if this constraint has only 1 child constraint.
func (*AnyConstraint) Validate ¶
func (c *AnyConstraint) Validate(v interface{}) (err error)
Validate validates the value against the input value. For AnyConstraints, it will return success the moment one child Constraint succeeds. It will return an error if none of the child Constraints succeeds
type ArrayConstraint ¶
type ArrayConstraint struct {
// contains filtered or unexported fields
}
ArrayConstraint implements a constraint to match against various aspects of a Array/Slice structure
func (*ArrayConstraint) AdditionalItems ¶
func (c *ArrayConstraint) AdditionalItems(ac Constraint) *ArrayConstraint
AdditionalItems specifies the constraint that additional items must be validated against. Note that if you specify `Items` with this constraint, `AdditionalItems` has no effect. This constraint only makes sense when used along side with the `PositionalItems` constraint.
If you want to allow any additional items, pass `EmptyConstraint` to this method. If unspecified, no extra items are allowed.
func (ArrayConstraint) DefaultValue ¶
func (dv ArrayConstraint) DefaultValue() interface{}
func (ArrayConstraint) HasDefault ¶
func (dv ArrayConstraint) HasDefault() bool
func (*ArrayConstraint) Items ¶
func (c *ArrayConstraint) Items(ac Constraint) *ArrayConstraint
Items specifies the constraint that all items in the array must be validated against
func (*ArrayConstraint) MaxItems ¶
func (c *ArrayConstraint) MaxItems(i int) *ArrayConstraint
MaxItems specifies the maximum number of items in the value. If unspecified, the check is not performed.
func (*ArrayConstraint) MinItems ¶
func (c *ArrayConstraint) MinItems(i int) *ArrayConstraint
MinItems specifies the minimum number of items in the value. If unspecified, the check is not performed.
func (*ArrayConstraint) PositionalItems ¶
func (c *ArrayConstraint) PositionalItems(ac []Constraint) *ArrayConstraint
PositionalItems specifies the constraint that elements in each position of the array being validated. Extra items in the array are validated against the constraint specified for `AdditionalItems`.
func (*ArrayConstraint) UniqueItems ¶
func (c *ArrayConstraint) UniqueItems(b bool) *ArrayConstraint
UniqueItems specifies if the array can hold non-unique items. When set to true, the validation will fail unless all of your elements are unique.
Caveat: Currently we stringify the elements before comparing for uniqueness. This could/should be fixed.
func (*ArrayConstraint) Validate ¶
func (c *ArrayConstraint) Validate(v interface{}) (err error)
Validate validates the given value against this Constraint
type BooleanConstraint ¶
type BooleanConstraint struct {
// contains filtered or unexported fields
}
BooleanConstraint implements a constraint to match against a boolean.
func (*BooleanConstraint) Default ¶
func (bc *BooleanConstraint) Default(v interface{}) *BooleanConstraint
Default specifies the default value to apply
func (BooleanConstraint) DefaultValue ¶
func (dv BooleanConstraint) DefaultValue() interface{}
func (BooleanConstraint) HasDefault ¶
func (dv BooleanConstraint) HasDefault() bool
func (*BooleanConstraint) Validate ¶
func (bc *BooleanConstraint) Validate(v interface{}) error
Validate vaidates the value against the given value
type Constraint ¶
type Constraint interface { DefaultValue() interface{} HasDefault() bool Validate(interface{}) error }
Constraint is an object that know how to validate individual types of input
type ConstraintMap ¶
type ConstraintMap struct {
// contains filtered or unexported fields
}
ConstraintMap is an implementation of RefResolver
func (*ConstraintMap) GetReference ¶
func (cm *ConstraintMap) GetReference(name string) (Constraint, error)
GetReference fetches the Constraint associated with the given name
func (ConstraintMap) Len ¶
func (cm ConstraintMap) Len() int
Len returns the number of references stored in this ConstraintMap
func (*ConstraintMap) SetReference ¶
func (cm *ConstraintMap) SetReference(name string, c Constraint)
SetReference registeres a new Constraint to a name
type EnumConstraint ¶
type EnumConstraint struct {
// contains filtered or unexported fields
}
EnumConstraint implements a constraint where the incoming value must match one of the values enumerated in the constraint. Note that due to various language specific reasons, you should only use simple types where the "==" operator can distinguish between different values
func (EnumConstraint) DefaultValue ¶
func (nc EnumConstraint) DefaultValue() interface{}
func (*EnumConstraint) Enum ¶
func (c *EnumConstraint) Enum(v ...interface{}) *EnumConstraint
Enum method sets the possible enumerations
func (EnumConstraint) HasDefault ¶
func (nc EnumConstraint) HasDefault() bool
func (*EnumConstraint) Validate ¶
func (c *EnumConstraint) Validate(v interface{}) (err error)
Validate validates the value against the list of enumerations
type ErrInvalidMaybeValue ¶
type ErrInvalidMaybeValue struct {
Value interface{}
}
func (ErrInvalidMaybeValue) Error ¶
func (e ErrInvalidMaybeValue) Error() string
type Generator ¶
type Generator struct{}
Generator is responsible for generating Go code that sets up a validator
type IntegerConstraint ¶
type IntegerConstraint struct {
NumberConstraint
}
IntegerConstraint implements a constraint to match against an integer type. Note that after checking if the value is an int (i.e. floor(x) == x), the rest of the logic follows exactly that of NumberConstraint
func (*IntegerConstraint) Default ¶
func (ic *IntegerConstraint) Default(v interface{}) *IntegerConstraint
Default specifies the default value for the given value
func (IntegerConstraint) DefaultValue ¶
func (dv IntegerConstraint) DefaultValue() interface{}
func (*IntegerConstraint) ExclusiveMaximum ¶
func (ic *IntegerConstraint) ExclusiveMaximum(b bool) *IntegerConstraint
ExclusiveMaximum specifies if the maximum value should be considered a valid value
func (*IntegerConstraint) ExclusiveMinimum ¶
func (ic *IntegerConstraint) ExclusiveMinimum(b bool) *IntegerConstraint
ExclusiveMinimum specifies if the minimum value should be considered a valid value
func (IntegerConstraint) HasDefault ¶
func (dv IntegerConstraint) HasDefault() bool
func (*IntegerConstraint) Maximum ¶
func (ic *IntegerConstraint) Maximum(n float64) *IntegerConstraint
Maximum sepcifies the maximum value that the constraint can allow Maximum sepcifies the maximum value that the constraint can allow
func (*IntegerConstraint) Minimum ¶
func (ic *IntegerConstraint) Minimum(n float64) *IntegerConstraint
Minimum sepcifies the minimum value that the constraint can allow
func (*IntegerConstraint) Validate ¶
func (ic *IntegerConstraint) Validate(v interface{}) (err error)
Validate validates the value against integer validation rules. Note that because when Go decodes JSON it FORCES float64 on numbers, this method will return true even if the *type* of the value is float32/64. We just check that `math.Floor(v) == v`
type JSVal ¶
type JSVal struct { *ConstraintMap // Name is the name that will be used to generate code for this validator. // If unspecified, the generator will create variable names like `V0`, `V1`, // `V2`, etc. If you want to generate more meaningful names, you should // set this value manually. For example, if you are using jsval with a // scaffold generator, you might want to set this to a human-readable value Name string // contains filtered or unexported fields }
JSVal is the main validator object.
func (*JSVal) SetConstraintMap ¶
func (v *JSVal) SetConstraintMap(cm *ConstraintMap) *JSVal
SetConstraintMap allows you to set the map that is referred to when resolving JSON references within constraints. By setting this to a common map, for example, you can share the same references to save you some memory space and sanity. See an example in the `generated_validator_test.go` file.
func (*JSVal) SetRoot ¶
func (v *JSVal) SetRoot(c Constraint) *JSVal
SetRoot sets the root Constraint object.
type JSValSlice ¶
type JSValSlice []*JSVal
JSValSlice is a list of JSVal validators. This exists in order to define methods to satisfy the `sort.Interface` interface
func (JSValSlice) Len ¶
func (p JSValSlice) Len() int
func (JSValSlice) Less ¶
func (p JSValSlice) Less(i, j int) bool
func (JSValSlice) Swap ¶
func (p JSValSlice) Swap(i, j int)
type Maybe ¶
type Maybe interface { // Valid should return true if this value has been properly initialized. // If this returns false, JSVal will treat as if the field is has not been // provided at all. Valid() bool // Value should return whatever the underlying value is. Value() interface{} // Set sets a value to this Maybe value, and turns on the Valid flag. // An error may be returned if the value could not be set (e.g. // you provided a value with the wrong type) Set(interface{}) error // Reset clears the Maybe value, and sets the Valid flag to false. Reset() }
Maybe is an interface that can be used for struct fields which want to differentiate between initialized and uninitialized state. For example, a string field, if uninitialized, will contain the zero value of "", but that empty string *could* be a valid value for our validation purposes.
To differentiate between an uninitialized string and an empty string, you should wrap it with a wrapper that implements the Maybe interface and JSVal will do its best to figure this out
type MaybeFloat ¶
func (MaybeFloat) MarshalJSON ¶
func (v MaybeFloat) MarshalJSON() ([]byte, error)
func (*MaybeFloat) Set ¶
func (v *MaybeFloat) Set(x interface{}) error
func (*MaybeFloat) UnmarshalJSON ¶
func (v *MaybeFloat) UnmarshalJSON(data []byte) error
func (MaybeFloat) Value ¶
func (v MaybeFloat) Value() interface{}
type MaybeString ¶
func (MaybeString) MarshalJSON ¶
func (v MaybeString) MarshalJSON() ([]byte, error)
func (*MaybeString) Set ¶
func (v *MaybeString) Set(x interface{}) error
func (*MaybeString) UnmarshalJSON ¶
func (v *MaybeString) UnmarshalJSON(data []byte) error
func (MaybeString) Value ¶
func (v MaybeString) Value() interface{}
type NotConstraint ¶
type NotConstraint struct {
// contains filtered or unexported fields
}
NotConstraint implements a constraint where the result of child constraint is negated -- that is, validation passes only if the child constraint fails.
func Not ¶
func Not(c Constraint) *NotConstraint
Not creates a new NotConstraint. You must pass in the child constraint to be run
func (NotConstraint) DefaultValue ¶
func (nc NotConstraint) DefaultValue() interface{}
DefaultValue is a no op for this constraint
func (NotConstraint) HasDefault ¶
func (nc NotConstraint) HasDefault() bool
HasDefault is a no op for this constraint
func (NotConstraint) Validate ¶
func (nc NotConstraint) Validate(v interface{}) (err error)
Validate runs the validation, and returns an error unless the child constraint fails
type NumberConstraint ¶
type NumberConstraint struct {
// contains filtered or unexported fields
}
NumberConstraint implements a constraint to match against a number (i.e. float) type.
func (*NumberConstraint) Default ¶
func (nc *NumberConstraint) Default(v interface{}) *NumberConstraint
Default specifies the default value for the given value
func (NumberConstraint) DefaultValue ¶
func (dv NumberConstraint) DefaultValue() interface{}
func (*NumberConstraint) Enum ¶
func (nc *NumberConstraint) Enum(l ...interface{}) *NumberConstraint
Enum specifies the values that this constraint can have
func (*NumberConstraint) ExclusiveMaximum ¶
func (nc *NumberConstraint) ExclusiveMaximum(b bool) *NumberConstraint
ExclusiveMaximum specifies if the maximum value should be considered a valid value
func (*NumberConstraint) ExclusiveMinimum ¶
func (nc *NumberConstraint) ExclusiveMinimum(b bool) *NumberConstraint
ExclusiveMinimum specifies if the minimum value should be considered a valid value
func (NumberConstraint) HasDefault ¶
func (dv NumberConstraint) HasDefault() bool
func (*NumberConstraint) Maximum ¶
func (nc *NumberConstraint) Maximum(n float64) *NumberConstraint
Maximum sepcifies the maximum value that the constraint can allow
func (*NumberConstraint) Minimum ¶
func (nc *NumberConstraint) Minimum(n float64) *NumberConstraint
Minimum sepcifies the minimum value that the constraint can allow
func (*NumberConstraint) MultipleOf ¶
func (nc *NumberConstraint) MultipleOf(n float64) *NumberConstraint
MultipleOf specifies the number that the given value must be divisible by. That is, the constraint will return an error unless the given value satisfies `math.Mod(v, n) == 0`
func (*NumberConstraint) Validate ¶
func (nc *NumberConstraint) Validate(v interface{}) (err error)
Validate validates the value against this constraint
type ObjectConstraint ¶
type ObjectConstraint struct { // FieldNameFromName takes a struct wrapped in reflect.Value, and a // field name -- in JSON format (i.e. what you specified in your // JSON struct tags, or the actual field name). It returns the // struct field name to pass to `Value.FieldByName()`. If you do // not specify one, DefaultFieldNameFromName will be used. FieldNameFromName func(reflect.Value, string) string // FieldNamesFromStruct takes a struct wrapped in reflect.Value, and // returns the name of all public fields. Note that the returned // names will be JSON names, which may not necessarily be the same // as the field name. If you do not specify one, DefaultFieldNamesFromStruct // will be used FieldNamesFromStruct func(reflect.Value) []string // contains filtered or unexported fields }
ObjectConstraint implements a constraint to match against various aspects of a Map-like structure.
func (*ObjectConstraint) AddProp ¶
func (o *ObjectConstraint) AddProp(name string, c Constraint) *ObjectConstraint
AddProp adds constraints for a named property.
func (*ObjectConstraint) AdditionalProperties ¶
func (o *ObjectConstraint) AdditionalProperties(c Constraint) *ObjectConstraint
AdditionalProperties specifies the constraint that additional properties should be validated against.
func (ObjectConstraint) DefaultValue ¶
func (dv ObjectConstraint) DefaultValue() interface{}
func (*ObjectConstraint) GetPropDependencies ¶
func (o *ObjectConstraint) GetPropDependencies(from string) []string
GetPropDependencies returns the list of property names that must be present for given property name `from`
func (*ObjectConstraint) GetSchemaDependency ¶
func (o *ObjectConstraint) GetSchemaDependency(from string) Constraint
GetSchemaDependency returns the Constraint that must be used when the property `from` is present.
func (ObjectConstraint) HasDefault ¶
func (dv ObjectConstraint) HasDefault() bool
func (*ObjectConstraint) IsPropRequired ¶
func (o *ObjectConstraint) IsPropRequired(s string) bool
IsPropRequired returns true if the given name is listed under the required properties
func (*ObjectConstraint) MaxProperties ¶
func (o *ObjectConstraint) MaxProperties(n int) *ObjectConstraint
MaxProperties specifies the maximum number of properties this constraint can allow. If unspecified, it is not checked.
func (*ObjectConstraint) MinProperties ¶
func (o *ObjectConstraint) MinProperties(n int) *ObjectConstraint
MinProperties specifies the minimum number of properties this constraint can allow. If unspecified, it is not checked.
func (*ObjectConstraint) PatternProperties ¶
func (o *ObjectConstraint) PatternProperties(key *regexp.Regexp, c Constraint) *ObjectConstraint
PatternProperties specifies constraints that properties matching this pattern must be validated against. Note that properties listed using `AddProp` takes precedence.
func (*ObjectConstraint) PatternPropertiesString ¶
func (o *ObjectConstraint) PatternPropertiesString(key string, c Constraint) *ObjectConstraint
PatternPropertiesString is the same as PatternProperties, but takes a string representing a regular expression. If the regular expression cannot be compiled, a panic occurs.
func (*ObjectConstraint) PropDependency ¶
func (o *ObjectConstraint) PropDependency(from string, to ...string) *ObjectConstraint
PropDependency specifies properties that must be present when `from` is present.
func (*ObjectConstraint) Required ¶
func (o *ObjectConstraint) Required(l ...string) *ObjectConstraint
Required specifies required property names
func (*ObjectConstraint) SchemaDependency ¶
func (o *ObjectConstraint) SchemaDependency(from string, c Constraint) *ObjectConstraint
SchemaDependency specifies a schema that the value being validated must also satisfy. Note that the "object" is the target that needs to be additionally validated, not the value of the `from` property
func (*ObjectConstraint) Validate ¶
func (o *ObjectConstraint) Validate(v interface{}) (err error)
Validate validates the given value against this ObjectConstraint
type OneOfConstraint ¶
type OneOfConstraint struct {
// contains filtered or unexported fields
}
OneOfConstraint implements a constraint where only exactly one of the child constraints' validation can pass. If none of the constraints passes, or more than 1 constraint passes, the expressions deemed to have failed.
func (*OneOfConstraint) Add ¶
func (c *OneOfConstraint) Add(c2 Constraint) *OneOfConstraint
Add appends a new Constraint
func (*OneOfConstraint) Constraints ¶
func (c *OneOfConstraint) Constraints() []Constraint
func (*OneOfConstraint) Reduce ¶
func (c *OneOfConstraint) Reduce() Constraint
Reduce returns the child Constraint, if this constraint has only 1 child constraint.
func (*OneOfConstraint) Validate ¶
func (c *OneOfConstraint) Validate(v interface{}) (err error)
Validate validates the value against the input value. For OneOfConstraints, it will return success only if exactly 1 child Constraint succeeds.
type RefResolver ¶
type RefResolver interface {
GetReference(string) (Constraint, error)
}
RefResolver is a mandatory object that you must pass to a ReferenceConstraint upon its creation. This is responsible for resolving the reference to an actual constraint.
type ReferenceConstraint ¶
type ReferenceConstraint struct {
// contains filtered or unexported fields
}
ReferenceConstraint is a constraint where its actual definition is stored elsewhere.
func Reference ¶
func Reference(resolver RefResolver) *ReferenceConstraint
Reference creates a new ReferenceConstraint object
func (*ReferenceConstraint) Default ¶
func (r *ReferenceConstraint) Default(_ interface{})
Default is a no op for this type
func (*ReferenceConstraint) DefaultValue ¶
func (r *ReferenceConstraint) DefaultValue() interface{}
DefaultValue returns the default value from the constraint pointed by the reference
func (*ReferenceConstraint) HasDefault ¶
func (r *ReferenceConstraint) HasDefault() bool
HasDefault returns true if the constraint pointed by the reference has defaults
func (*ReferenceConstraint) RefersTo ¶
func (r *ReferenceConstraint) RefersTo(s string) *ReferenceConstraint
RefersTo specifies the reference string that this constraint points to
func (*ReferenceConstraint) Resolved ¶
func (r *ReferenceConstraint) Resolved() (c Constraint, err error)
Resolved returns the Constraint obtained by resolving the reference.
func (*ReferenceConstraint) Validate ¶
func (r *ReferenceConstraint) Validate(v interface{}) (err error)
Validate validates the value against the constraint pointed to by the reference.
type StringConstraint ¶
type StringConstraint struct {
// contains filtered or unexported fields
}
StringConstraint implements a constraint to match against a string
func String ¶
func String() *StringConstraint
String creates a new StringConstraint. It unfortunately overlaps the `Stringer` interface :/
func (*StringConstraint) Default ¶
func (sc *StringConstraint) Default(v interface{}) *StringConstraint
Default sets the default value for this constraint.
func (StringConstraint) DefaultValue ¶
func (dv StringConstraint) DefaultValue() interface{}
func (*StringConstraint) Enum ¶
func (sc *StringConstraint) Enum(l ...interface{}) *StringConstraint
Enum specifies the enumeration of the possible values
func (*StringConstraint) Format ¶
func (sc *StringConstraint) Format(f string) *StringConstraint
Format specifies the format that passed value must conform to
func (StringConstraint) HasDefault ¶
func (dv StringConstraint) HasDefault() bool
func (*StringConstraint) MaxLength ¶
func (sc *StringConstraint) MaxLength(l int) *StringConstraint
MaxLength specifies the maximum length the passed value can have
func (*StringConstraint) MinLength ¶
func (sc *StringConstraint) MinLength(l int) *StringConstraint
MinLength specifies the minimum length the passed value must have
func (*StringConstraint) Regexp ¶
func (sc *StringConstraint) Regexp(rx *regexp.Regexp) *StringConstraint
Regexp specifies the `*regexp.Regexp` object that passed value must conform to
func (*StringConstraint) RegexpString ¶
func (sc *StringConstraint) RegexpString(pat string) *StringConstraint
RegexpString is the same as Regexp method, except this one takes a string and compiles it.
func (*StringConstraint) Validate ¶
func (sc *StringConstraint) Validate(v interface{}) (err error)
Validate runs the validation against the incoming value. Note that StringConstraint does not apply default values to the incoming string value, because the Zero value for string ("") can be a perfectly reasonable value.
The caller is the only person who can determine if a string value is "unavailable"
type StructInfo ¶
type StructInfo struct {
// contains filtered or unexported fields
}
type StructInfoRegistry ¶
type StructInfoRegistry struct {
// contains filtered or unexported fields
}
func (*StructInfoRegistry) Lookup ¶
func (r *StructInfoRegistry) Lookup(t reflect.Type) (StructInfo, bool)
func (*StructInfoRegistry) Register ¶
func (r *StructInfoRegistry) Register(t reflect.Type) StructInfo