Documentation ¶
Index ¶
- type ArrayField
- type ArrayFieldSpec
- type BooleanField
- type BooleanFieldSpec
- type Field
- type FloatField
- func (f *FloatField) GetName() string
- func (f *FloatField) MarshalJSON() ([]byte, error)
- func (f *FloatField) Max(value float64) *FloatField
- func (f *FloatField) Min(value float64) *FloatField
- func (f *FloatField) Negative() *FloatField
- func (f *FloatField) Positive() *FloatField
- func (f *FloatField) Range(start, end float64) *FloatField
- func (f *FloatField) Required() *FloatField
- func (f *FloatField) Validate(v interface{}) error
- type FloatFieldSpec
- type FloatRangeSpec
- type IntRangeSpec
- type IntegerField
- func (i *IntegerField) GetName() string
- func (i *IntegerField) MarshalJSON() ([]byte, error)
- func (i *IntegerField) Max(value int) *IntegerField
- func (i *IntegerField) Min(value int) *IntegerField
- func (i *IntegerField) Negative() *IntegerField
- func (i *IntegerField) Positive() *IntegerField
- func (i *IntegerField) Range(start, end int) *IntegerField
- func (i *IntegerField) Required() *IntegerField
- func (i *IntegerField) Validate(v interface{}) error
- type IntegerFieldSpec
- type NullField
- type NullFieldSpec
- type ObjectField
- type ObjectFieldSpec
- type Schema
- type SchemaSpec
- type StringField
- func (s *StringField) Choices(choices ...string) *StringField
- func (s *StringField) Format(format string) *StringField
- func (s *StringField) GetName() string
- func (s *StringField) MarshalJSON() ([]byte, error)
- func (s *StringField) MaxLength(length int) *StringField
- func (s *StringField) MinLength(length int) *StringField
- func (s *StringField) Required() *StringField
- func (s *StringField) Validate(value interface{}) error
- type StringFieldSpec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ArrayField ¶
type ArrayField struct {
// contains filtered or unexported fields
}
ArrayField is the type for validating arrays in a JSON
func Array ¶
func Array(name string, itemField Field) *ArrayField
Array is the constructor of an array field.
func FixArray ¶
func FixArray(name string, itemFields []Field) *ArrayField
Array is the constructor of an array field.
func NewArray ¶
func NewArray(spec ArrayFieldSpec, itemField Field, fixItemsField []Field, minLengthValidation, maxLengthValidation bool) *ArrayField
NewArray receives an ArrayFieldSpec and returns and ArrayField
func (*ArrayField) GetName ¶
func (a *ArrayField) GetName() string
GetName returns name of the field
func (*ArrayField) MarshalJSON ¶
func (a *ArrayField) MarshalJSON() ([]byte, error)
func (*ArrayField) MaxLength ¶
func (a *ArrayField) MaxLength(length int) *ArrayField
MaxLength is called to set maximum length for an array field in a JSON
func (*ArrayField) MinLength ¶
func (a *ArrayField) MinLength(length int) *ArrayField
MinLength is called to set minimum length for an array field in a JSON
func (*ArrayField) Required ¶
func (a *ArrayField) Required() *ArrayField
Required is called to make a field required in a JSON
func (*ArrayField) Validate ¶
func (a *ArrayField) Validate(v interface{}) error
Validate is used for validating a value. it returns an error if the value is invalid.
type ArrayFieldSpec ¶
type ArrayFieldSpec struct { Name string `mapstructure:"name" json:"name"` Type fieldType `json:"type"` Required bool `mapstructure:"required" json:"required,omitempty"` Items map[string]interface{} `mapstructure:"items" json:"items,omitempty"` MinLength int `mapstructure:"min_length" json:"minLength,omitempty"` MaxLength int `mapstructure:"max_length" json:"maxLength,omitempty"` FixItems []map[string]interface{} `mapstructure:"fix_items" json:"fix_items,omitempty"` }
ArrayFieldSpec is a type used for parsing an ArrayField
type BooleanField ¶
type BooleanField struct {
// contains filtered or unexported fields
}
BooleanField is the type for validating booleans in a JSON
func Boolean ¶
func Boolean(name string) *BooleanField
Boolean is the constructor of a boolean field
func NewBoolean ¶
func NewBoolean(spec BooleanFieldSpec, valueValidation bool) *BooleanField
NewBoolean receives an BooleanFieldSpec and returns and BooleanField
func (*BooleanField) GetName ¶
func (b *BooleanField) GetName() string
GetName returns name of the field
func (*BooleanField) MarshalJSON ¶
func (b *BooleanField) MarshalJSON() ([]byte, error)
func (*BooleanField) Required ¶
func (b *BooleanField) Required() *BooleanField
Required is called to make a field required in a JSON
func (*BooleanField) ShouldBe ¶
func (b *BooleanField) ShouldBe(value bool) *BooleanField
ShouldBe is called for setting a value for checking a boolean.
func (*BooleanField) Validate ¶
func (b *BooleanField) Validate(v interface{}) error
Validate is used for validating a value. it returns an error if the value is invalid.
type BooleanFieldSpec ¶
type BooleanFieldSpec struct { Name string `mapstructure:"name" json:"name"` Type fieldType `json:"type"` Required bool `mapstructure:"required" json:"required,omitempty"` Value bool `mapstructure:"value" json:"value,omitempty"` }
BooleanFieldSpec is a type used for parsing an BooleanField
type Field ¶
Field is the abstraction on a field in a json. different field types can be implemented with implementing this interface.
type FloatField ¶
type FloatField struct {
// contains filtered or unexported fields
}
FloatField is the type for validating floats in a JSON
func NewFloat ¶
func NewFloat(spec FloatFieldSpec, minValidation, maxValidation, signValidation, rangeValidation bool) *FloatField
NewFloat receives an FloatFieldSpec and returns and FloatField
func (*FloatField) GetName ¶
func (f *FloatField) GetName() string
GetName returns name of the field
func (*FloatField) MarshalJSON ¶
func (f *FloatField) MarshalJSON() ([]byte, error)
func (*FloatField) Max ¶
func (f *FloatField) Max(value float64) *FloatField
Max is called when we want to set a maximum value for a float value in validation.
func (*FloatField) Min ¶
func (f *FloatField) Min(value float64) *FloatField
Min is called when we want to set a minimum value for a float value in validation.
func (*FloatField) Negative ¶
func (f *FloatField) Negative() *FloatField
Negative is called when we want to force the value to be negative in validation.
func (*FloatField) Positive ¶
func (f *FloatField) Positive() *FloatField
Positive is called when we want to force the value to be positive in validation.
func (*FloatField) Range ¶
func (f *FloatField) Range(start, end float64) *FloatField
Range is called when we want to define valid ranges for a float value in validation.
func (*FloatField) Required ¶
func (f *FloatField) Required() *FloatField
Required is called to make a field required in a JSON
func (*FloatField) Validate ¶
func (f *FloatField) Validate(v interface{}) error
Validate is used for validating a value. it returns an error if the value is invalid.
type FloatFieldSpec ¶
type FloatFieldSpec struct { Name string `mapstructure:"name" json:"name"` Type fieldType `json:"type"` Required bool `mapstructure:"required" json:"required,omitempty"` Min float64 `mapstructure:"min" json:"min,omitempty"` Max float64 `mapstructure:"max" json:"max,omitempty"` Positive bool `mapstructure:"positive" json:"positive,omitempty"` Ranges []FloatRangeSpec `mapstructure:"ranges" json:"ranges,omitempty"` }
FloatFieldSpec is a type used for parsing an FloatField
type FloatRangeSpec ¶
type FloatRangeSpec struct { Start float64 `mapstructure:"start" json:"start"` End float64 `mapstructure:"end" json:"end"` }
FloatRangeSpec is a type for parsing a float field range
type IntRangeSpec ¶
type IntRangeSpec struct { Start int `mapstructure:"start" json:"start"` End int `mapstructure:"end" json:"end"` }
IntRangeSpec is a type for parsing an integer field range
type IntegerField ¶
type IntegerField struct {
// contains filtered or unexported fields
}
IntegerField is the type for validating integers in a JSON
func Integer ¶
func Integer(name string) *IntegerField
Integer is the constructor of an integer field
func NewInteger ¶
func NewInteger(spec IntegerFieldSpec, minValidation, maxValidation, signValidation, rangeValidation bool) *IntegerField
NewInteger receives an IntegerFieldSpec and returns and IntegerField
func (*IntegerField) GetName ¶
func (i *IntegerField) GetName() string
GetName returns name of the field
func (*IntegerField) MarshalJSON ¶
func (i *IntegerField) MarshalJSON() ([]byte, error)
func (*IntegerField) Max ¶
func (i *IntegerField) Max(value int) *IntegerField
Max is called when we want to set a maximum value for an integer value in validation.
func (*IntegerField) Min ¶
func (i *IntegerField) Min(value int) *IntegerField
Min is called when we want to set a minimum value for an integer value in validation.
func (*IntegerField) Negative ¶
func (i *IntegerField) Negative() *IntegerField
Negative is called when we want to force the value to be negative in validation.
func (*IntegerField) Positive ¶
func (i *IntegerField) Positive() *IntegerField
Positive is called when we want to force the value to be positive in validation.
func (*IntegerField) Range ¶
func (i *IntegerField) Range(start, end int) *IntegerField
Range is called when we want to define valid ranges for an integer value in validation.
func (*IntegerField) Required ¶
func (i *IntegerField) Required() *IntegerField
Required is called to make a field required in a JSON
func (*IntegerField) Validate ¶
func (i *IntegerField) Validate(v interface{}) error
Validate is used for validating a value. it returns an error if the value is invalid.
type IntegerFieldSpec ¶
type IntegerFieldSpec struct { Name string `mapstructure:"name" json:"name"` Type fieldType `json:"type"` Required bool `mapstructure:"required" json:"required,omitempty"` Min int `mapstructure:"min" json:"min,omitempty"` Max int `mapstructure:"max" json:"max,omitempty"` Positive bool `mapstructure:"positive" json:"positive,omitempty"` Ranges []IntRangeSpec `mapstructure:"ranges" json:"ranges,omitempty"` }
IntegerFieldSpec is a type used for parsing an IntegerField
type NullField ¶
type NullField struct {
// contains filtered or unexported fields
}
NullField is the type for validating floats in a JSON
func NewNull ¶
func NewNull(spec NullFieldSpec) *NullField
NewNull receives an NullFieldSpec and returns and NullField
func (*NullField) MarshalJSON ¶
type NullFieldSpec ¶
type NullFieldSpec struct { Name string `mapstructure:"name" json:"name"` Type fieldType `json:"type"` }
NullFieldSpec is a type used for parsing an NullField
type ObjectField ¶
type ObjectField struct {
// contains filtered or unexported fields
}
ObjectField is the type for validating another JSON object in a JSON
func NewObject ¶
func NewObject(spec ObjectFieldSpec, schema Schema) *ObjectField
NewObject receives an ObjectFieldSpec and returns and ObjectField
func Object ¶
func Object(name string, schema Schema) *ObjectField
Object is the constructor of an object field
func (*ObjectField) GetName ¶
func (o *ObjectField) GetName() string
GetName returns name of the field
func (*ObjectField) MarshalJSON ¶
func (o *ObjectField) MarshalJSON() ([]byte, error)
func (*ObjectField) Required ¶
func (o *ObjectField) Required() *ObjectField
Required is called to make a field required in a JSON
func (*ObjectField) Strict ¶
func (o *ObjectField) Strict() *ObjectField
func (*ObjectField) Validate ¶
func (o *ObjectField) Validate(v interface{}) error
Validate is used for validating a value. it returns an error if the value is invalid.
type ObjectFieldSpec ¶
type ObjectFieldSpec struct { Name string `mapstructure:"name" json:"name"` Type fieldType `json:"type"` Required bool `mapstructure:"required" json:"required,omitempty"` Schema map[string]interface{} `mapstructure:"schema" json:"schema,omitempty"` }
ObjectFieldSpec is a type used for parsing an ObjectField
type Schema ¶
Schema is the type for declaring a JSON schema and validating a json object.
func NewSchema ¶
NewSchema is the constructor for Schema. it receives a list of Field in its arguments.
func ReadFromBytes ¶
ReadFromBytes is for parsing a Schema from a byte array input.
func ReadFromFile ¶
ReadFromFile is for parsing a Schema from a file input.
func ReadFromString ¶
ReadFromString is for parsing a Schema from a string input.
func (*Schema) UnmarshalJSON ¶
UnmarshalJSON is implemented for parsing a Schema. it overrides json.Unmarshal behaviour.
func (*Schema) ValidateBytes ¶
ValidateBytes receives a byte array of a json object and validates it according to the specified Schema. it returns an error if the input is invalid.
func (*Schema) ValidateString ¶
ValidateString is like ValidateBytes but it receives the json object as string input.
type SchemaSpec ¶
type SchemaSpec struct { Fields []map[string]interface{} `json:"fields"` StrictMode bool `json:"strict"` }
SchemaSpec is used for parsing a Schema
type StringField ¶
type StringField struct {
// contains filtered or unexported fields
}
StringField is the type for validating strings in a JSON
func NewString ¶
func NewString(spec StringFieldSpec, minLengthValidation, maxLengthValidation, formatValidation, choiceValidation bool) *StringField
NewString receives an StringFieldSpec and returns and StringField
func (*StringField) Choices ¶
func (s *StringField) Choices(choices ...string) *StringField
Choices function is called to set valid choices of a string field in validation
func (*StringField) Format ¶
func (s *StringField) Format(format string) *StringField
Format is called to set a regex format for validation of a string field
func (*StringField) GetName ¶
func (s *StringField) GetName() string
GetName returns name of the field
func (*StringField) MarshalJSON ¶
func (s *StringField) MarshalJSON() ([]byte, error)
func (*StringField) MaxLength ¶
func (s *StringField) MaxLength(length int) *StringField
MaxLength is called to set a maximum length to a string field
func (*StringField) MinLength ¶
func (s *StringField) MinLength(length int) *StringField
MinLength is called to set a minimum length to a string field
func (*StringField) Required ¶
func (s *StringField) Required() *StringField
Required is called to make a field required in a JSON
func (*StringField) Validate ¶
func (s *StringField) Validate(value interface{}) error
Validate is used for validating a value. it returns an error if the value is invalid.
type StringFieldSpec ¶
type StringFieldSpec struct { Name string `mapstructure:"name" json:"name"` Type fieldType `json:"type"` Required bool `mapstructure:"required" json:"required,omitempty"` MinLength int `mapstructure:"min_length" json:"minLength,omitempty"` MaxLength int `mapstructure:"max_length" json:"maxLength,omitempty"` Format string `mapstructure:"format" json:"format,omitempty"` Choices []string `mapstructure:"choices" json:"choices,omitempty"` }
StringFieldSpec is a type used for parsing an StringField