-
Notifications
You must be signed in to change notification settings - Fork 4
/
array_spec.go
24 lines (22 loc) · 1.02 KB
/
array_spec.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package vjson
// ArrayFieldSpec is a type used for parsing an ArrayField
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"`
}
// NewArray receives an ArrayFieldSpec and returns and ArrayField
func NewArray(spec ArrayFieldSpec, itemField Field, minLengthValidation, maxLengthValidation bool) *ArrayField {
return &ArrayField{
name: spec.Name,
required: spec.Required,
items: itemField,
minLength: spec.MinLength,
minLengthValidation: minLengthValidation,
maxLength: spec.MaxLength,
maxLengthValidation: maxLengthValidation,
}
}