Documentation
¶
Index ¶
Constants ¶
const ( FailLenMin = 1 << iota FailLenMax FailValMin FailValMax FailEmpty FailRegexp FailEmail FailZero )
values for invalid field flags
const ( ValMinNotNil = 1 << iota ValMaxNotNil Required Email )
values used with flags
const TypeEmail = 4
const TypePassword = 3
const TypeText = 1
const TypeTextarea = 2
const VERSION = "0.6.1"
Variables ¶
This section is empty.
Functions ¶
func GenerateHTML ¶
func GenerateHTML(obj interface{}, options *HTMLOptions) map[string]string
GenerateHTMLInput takes a struct and generates HTML inputs for each of the fields, eg. <input> or <textarea>
func Validate ¶
func Validate(obj interface{}, options *ValidationOptions) (bool, map[string]int)
Validate validates fields of a struct. Currently only fields which are string or int (any) are validated. Func returns boolean value that determines whether value is true or false, and a map of fields that failed validation. See Fail* constants for the values.
Types ¶
type HTMLOptions ¶
type HTMLOptions struct { RestrictFields map[string]bool ExcludeFields map[string]bool OverwriteFieldTags map[string]map[string]string OverwriteTagName string ValidateWhenSuffix bool IDPrefix string NamePrefix string OverwriteValues map[string]string FieldValues bool }
Optional configuration for validation: * RestrictFields defines what struct fields should be generated * ExcludeFields defines fields that should be skipped (also from RestrictFields) * OverwriteFieldTags can be used to overwrite tags for specific fields * OverwriteTagName sets tag used to define validation (default is "validation") * ValidateWhenSuffix will validate certain fields based on their name, eg. "PrimaryEmail" field will need to be a valid email * OverwriteFieldValues is to use overwrite values for fields, so these values are validated not the ones in struct * IDPrefix - if added, an element will contain an 'id' attribute in form of prefix + field name * NamePrefix - use this to put a prefix in the 'name' attribute * OverwriteValues - fill inputs with the specified values * FieldValues - when true then fill inputs with struct instance values
type ValidationOptions ¶
type ValidationOptions struct { RestrictFields map[string]bool OverwriteFieldTags map[string]map[string]string OverwriteTagName string ValidateWhenSuffix bool OverwriteFieldValues map[string]interface{} }
Optional configuration for validation: * RestrictFields defines what struct fields should be validated * OverwriteFieldTags can be used to overwrite tags for specific fields * OverwriteTagName sets tag used to define validation (default is "validation") * ValidateWhenSuffix will validate certain fields based on their name, eg. "PrimaryEmail" field will need to be a valid email * OverwriteFieldValues is to use overwrite values for fields, so these values are validated not the ones in struct
type ValueValidation ¶
type ValueValidation struct { LenMin int LenMax int ValMin int64 ValMax int64 Regexp *regexp.Regexp Flags int64 }
func NewValueValidation ¶
func NewValueValidation() *ValueValidation
func (*ValueValidation) ValidateReflectValue ¶
func (v *ValueValidation) ValidateReflectValue(value reflect.Value) (ok bool, failureFlags int)