model

package
v0.0.0-...-9e0c27b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2012 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

The Model of MVC.

Index

Constants

View Source
const DateFormat = "2006-01-02"
View Source
const DateTimeFormat = "2006-01-02 15:04:05"
View Source
const ShortDateTimeFormat = "2006-01-02 15:04"

Variables

View Source
var DynamicValueType = reflect.TypeOf(DynamicValue{})
View Source
var StructTagKey = "model"

Functions

func CopyFields

func CopyFields(dst, src interface{}) (err error)

CopyFields copies matching struct/array/slice fields that implement the Value interface from src to dst. Matching is done by comparing the MetaData.Selector() of the fields. Copying is done by calling SetString() of dst with the result from String() of src. This way even not exactly matching models can be copied by converting to and from strings if this is possible without errors.

func CopyFieldsIfNotEmpty

func CopyFieldsIfNotEmpty(dst, src interface{}) (err error)

CopyFieldsIfNotEmpty copies matching struct/array/slice fields that implement the Value interface from src to dst, if IsEmpty() of src returns false. Matching is done by comparing the MetaData.Selector() of the fields. Copying is done by calling SetString() of dst with the result from String() of src. This way even not exactly matching models can be copied by converting to and from strings if this is possible without errors.

func GenerateRandomPassword

func GenerateRandomPassword(length int) (string, error)

func Iterate

func Iterate(i Iterator, callback interface{}) error

func IterateToChannel

func IterateToChannel(i Iterator) (docs <-chan interface{}, errs <-chan error)

Channels will be closed after last result

func NormalizePhoneNumber

func NormalizePhoneNumber(number string) string

func ParseTagAttribs

func ParseTagAttribs(tag string) map[string]string

func PasswordHash

func PasswordHash(password string) string

func SetAllSliceLengths

func SetAllSliceLengths(document interface{}, length int)

SetAllSliceLengths sets the length of all slices in document.

func Visit

func Visit(model interface{}, visitor Visitor) error

func VisitMaxDepth

func VisitMaxDepth(model interface{}, maxDepth int, visitor Visitor) error

Types

type Blob

type Blob []byte

Blob is just a bunch of bytes. Struct tag attributes:

`model:"required"`

func NewBlob

func NewBlob(value []byte) *Blob

func (*Blob) Get

func (self *Blob) Get() []byte

func (*Blob) IsEmpty

func (self *Blob) IsEmpty() bool

func (*Blob) Required

func (self *Blob) Required(metaData *MetaData) bool

func (*Blob) Set

func (self *Blob) Set(value []byte)

func (*Blob) SetString

func (self *Blob) SetString(str string) error

func (*Blob) String

func (self *Blob) String() string

func (*Blob) Validate

func (self *Blob) Validate(metaData *MetaData) error

type Bool

type Bool bool

Bool model value. Struct tag attributes:

required

func NewBool

func NewBool(value bool) *Bool

func (*Bool) Get

func (self *Bool) Get() bool

func (*Bool) IsEmpty

func (self *Bool) IsEmpty() bool

func (*Bool) Required

func (self *Bool) Required(metaData *MetaData) bool

func (*Bool) Set

func (self *Bool) Set(value bool)

func (*Bool) SetString

func (self *Bool) SetString(str string) error

func (*Bool) String

func (self *Bool) String() string

func (*Bool) Validate

func (self *Bool) Validate(metaData *MetaData) error

type Choice

type Choice string

Choice can hold one of several string options. The options are defined by the struct tag attribute "options" delimited by colons ",". A colon in an option can be escaped with "\," An empty string can be used as the first option. Choice is required, when the first option in not an empty string. Struct tag attributes:

`model:"options=Red,Green,Blue"`
`model:"options=,Second,Third"` // empty string is a valid value

func NewChoice

func NewChoice(value string) *Choice

func (*Choice) Get

func (self *Choice) Get() string

func (*Choice) IsEmpty

func (self *Choice) IsEmpty() bool

func (*Choice) Options

func (self *Choice) Options(metaData *MetaData) []string

func (*Choice) Required

func (self *Choice) Required(metaData *MetaData) bool

func (*Choice) Set

func (self *Choice) Set(value string)

func (*Choice) SetString

func (self *Choice) SetString(str string) error

func (*Choice) String

func (self *Choice) String() string

func (*Choice) Validate

func (self *Choice) Validate(metaData *MetaData) error

type Color

type Color string

Color holds a hex web-color with the # prefix. The Set method accepts all valid web color syntaxes except for color names. Struct tag attributes:

`model:"required"`

func NewColor

func NewColor(value string) *Color

func (*Color) EqualsColor

func (self *Color) EqualsColor(c color.Color) bool

func (*Color) GetOrDefault

func (self *Color) GetOrDefault(defaultColor string) string

func (*Color) IsEmpty

func (self *Color) IsEmpty() bool

func (*Color) IsValid

func (self *Color) IsValid() bool

func (*Color) RGBA

func (self *Color) RGBA() color.RGBA

RGBA returns the color as image/color.RGBA struct. If the color is empty, a default zero struct will be returned.

func (*Color) Required

func (self *Color) Required(metaData *MetaData) bool

func (*Color) SetString

func (self *Color) SetString(s string)

func (*Color) String

func (self *Color) String() string

func (*Color) Validate

func (self *Color) Validate(metaData *MetaData) error

type Configuration

type Configuration struct {
	Debug bool
}
var Config Configuration

func (*Configuration) Close

func (self *Configuration) Close() error

func (*Configuration) Init

func (self *Configuration) Init() error

func (*Configuration) Name

func (self *Configuration) Name() string

type Country

type Country string

func NewCountry

func NewCountry(value string) *Country

func (*Country) EnglishName

func (self *Country) EnglishName() string

func (*Country) FixValue

func (self *Country) FixValue(metaData *MetaData)

func (*Country) Get

func (self *Country) Get() string

func (*Country) IsEmpty

func (self *Country) IsEmpty() bool

func (*Country) Required

func (self *Country) Required(metaData *MetaData) bool

func (*Country) Set

func (self *Country) Set(value string) error

func (*Country) SetString

func (self *Country) SetString(str string) error

func (*Country) String

func (self *Country) String() string

func (*Country) Validate

func (self *Country) Validate(metaData *MetaData) error

type Date

type Date string

func NewDate

func NewDate(value string) *Date

func (*Date) FixValue

func (self *Date) FixValue(metaData *MetaData)

func (*Date) Format

func (self *Date) Format(format string) string

func (*Date) Get

func (self *Date) Get() string

func (*Date) IsEmpty

func (self *Date) IsEmpty() bool

func (*Date) Required

func (self *Date) Required(metaData *MetaData) bool

func (*Date) Set

func (self *Date) Set(value string) error

func (*Date) SetEmpty

func (self *Date) SetEmpty()

func (*Date) SetString

func (self *Date) SetString(str string) error

func (*Date) SetTime

func (self *Date) SetTime(t time.Time)

func (*Date) SetTodayUTC

func (self *Date) SetTodayUTC()

func (*Date) SetUnixNanoseconds

func (self *Date) SetUnixNanoseconds(nanos int64)

func (*Date) String

func (self *Date) String() string

func (*Date) Time

func (self *Date) Time() time.Time

func (*Date) UnixNanoseconds

func (self *Date) UnixNanoseconds() int64

func (*Date) Validate

func (self *Date) Validate(metaData *MetaData) error

todo min max

type DateTime

type DateTime string

DateTime

func NewDateTime

func NewDateTime(value string) *DateTime

func (*DateTime) FixValue

func (self *DateTime) FixValue(metaData *MetaData)

func (*DateTime) Format

func (self *DateTime) Format(format string) string

func (*DateTime) Get

func (self *DateTime) Get() string

func (*DateTime) IsEmpty

func (self *DateTime) IsEmpty() bool

func (*DateTime) Required

func (self *DateTime) Required(metaData *MetaData) bool

func (*DateTime) Set

func (self *DateTime) Set(value string) (err error)

func (*DateTime) SetEmpty

func (self *DateTime) SetEmpty()

func (*DateTime) SetNowUTC

func (self *DateTime) SetNowUTC()

func (*DateTime) SetString

func (self *DateTime) SetString(str string) error

func (*DateTime) SetTime

func (self *DateTime) SetTime(t time.Time)

func (*DateTime) SetUnixNanoseconds

func (self *DateTime) SetUnixNanoseconds(nanos int64)

func (*DateTime) String

func (self *DateTime) String() string

func (*DateTime) Time

func (self *DateTime) Time() time.Time

func (*DateTime) UnixNanoseconds

func (self *DateTime) UnixNanoseconds() int64

func (*DateTime) Validate

func (self *DateTime) Validate(metaData *MetaData) error

todo min max

type DynamicChoice

type DynamicChoice struct {
	// contains filtered or unexported fields
}

func (*DynamicChoice) CheckIndex

func (self *DynamicChoice) CheckIndex(index int) error

func (*DynamicChoice) GetBSON

func (self *DynamicChoice) GetBSON() (interface{}, error)

func (*DynamicChoice) Index

func (self *DynamicChoice) Index() int

func (*DynamicChoice) IsEmpty

func (self *DynamicChoice) IsEmpty() bool

func (*DynamicChoice) Options

func (self *DynamicChoice) Options() []string

func (*DynamicChoice) Required

func (self *DynamicChoice) Required(metaData *MetaData) bool

func (*DynamicChoice) SetBSON

func (self *DynamicChoice) SetBSON(raw bson.Raw) (err error)

func (*DynamicChoice) SetIndex

func (self *DynamicChoice) SetIndex(index int) error

func (*DynamicChoice) SetOptions

func (self *DynamicChoice) SetOptions(options []string)

func (*DynamicChoice) SetString

func (self *DynamicChoice) SetString(str string) error

func (*DynamicChoice) String

func (self *DynamicChoice) String() string

func (*DynamicChoice) Validate

func (self *DynamicChoice) Validate(metaData *MetaData) error

type DynamicValue

type DynamicValue struct {
	Name string
	Value
	Attribs map[string]map[string]string
}

DynamicValue can be used to build a model dynamically instead of using a static typed struct. See DynamicValues

func (*DynamicValue) Attrib

func (self *DynamicValue) Attrib(tagKey, name string) string

func (*DynamicValue) GetBSON

func (self *DynamicValue) GetBSON() (interface{}, error)

func (*DynamicValue) SetAttrib

func (self *DynamicValue) SetAttrib(tagKey, name, value string)

func (*DynamicValue) SetBSON

func (self *DynamicValue) SetBSON(raw bson.Raw) error

type DynamicValues

type DynamicValues []DynamicValue

DynamicValues is used to create a model dynamically instead of using a static typed struct.

func (DynamicValues) Get

func (self DynamicValues) Get(name string) (value *DynamicValue, found bool)

func (DynamicValues) GetValue

func (self DynamicValues) GetValue(name string) (value Value, found bool)

type Email

type Email string

func NewEmail

func NewEmail(value string) *Email

func (*Email) EqualsCaseinsensitive

func (self *Email) EqualsCaseinsensitive(address string) bool

func (*Email) FixValue

func (self *Email) FixValue(metaData *MetaData)

func (*Email) Get

func (self *Email) Get() string

func (*Email) IsEmpty

func (self *Email) IsEmpty() bool

func (*Email) Required

func (self *Email) Required(metaData *MetaData) bool

func (*Email) Set

func (self *Email) Set(value string) (err error)

func (*Email) SetString

func (self *Email) SetString(str string) (err error)

func (*Email) String

func (self *Email) String() string

func (*Email) Validate

func (self *Email) Validate(metaData *MetaData) error

type EmptyIterator

type EmptyIterator struct {
}

func (*EmptyIterator) Err

func (self *EmptyIterator) Err() error

func (*EmptyIterator) Next

func (self *EmptyIterator) Next() interface{}

type ErrorOnlyIterator

type ErrorOnlyIterator struct {
	// contains filtered or unexported fields
}

func (*ErrorOnlyIterator) Err

func (self *ErrorOnlyIterator) Err() error

func (*ErrorOnlyIterator) Next

func (self *ErrorOnlyIterator) Next() interface{}

type FieldOnlyVisitor

type FieldOnlyVisitor func(field *MetaData) error

FieldOnlyVisitor calls its function for every struct, array and slice field.

func (FieldOnlyVisitor) BeginIndexedFields

func (self FieldOnlyVisitor) BeginIndexedFields(*MetaData) error

func (FieldOnlyVisitor) BeginNamedFields

func (self FieldOnlyVisitor) BeginNamedFields(*MetaData) error

func (FieldOnlyVisitor) EndIndexedFields

func (self FieldOnlyVisitor) EndIndexedFields(*MetaData) error

func (FieldOnlyVisitor) EndNamedFields

func (self FieldOnlyVisitor) EndNamedFields(*MetaData) error

func (FieldOnlyVisitor) IndexedField

func (self FieldOnlyVisitor) IndexedField(field *MetaData) error

func (FieldOnlyVisitor) NamedField

func (self FieldOnlyVisitor) NamedField(field *MetaData) error

type File

type File struct {
	Name string
	Data []byte
}

func (*File) IsEmpty

func (self *File) IsEmpty() bool

func (*File) Required

func (self *File) Required(metaData *MetaData) bool

func (*File) SetString

func (self *File) SetString(str string) error

func (*File) String

func (self *File) String() string

func (*File) Validate

func (self *File) Validate(metaData *MetaData) error

type FilterFunc

type FilterFunc func(doc interface{}) (ok bool)

type FilterIterator

type FilterIterator struct {
	Iterator
	PassFilter FilterFunc
}

func (*FilterIterator) Next

func (self *FilterIterator) Next() interface{}

type Float

type Float float64

Attributes: * label * min * max * valid

func NewFloat

func NewFloat(value float64) *Float

func (*Float) Get

func (self *Float) Get() float64

func (*Float) IsEmpty

func (self *Float) IsEmpty() bool

func (*Float) IsValid

func (self *Float) IsValid() bool

func (*Float) Max

func (self *Float) Max(metaData *MetaData) (max float64, ok bool, err error)

func (*Float) Min

func (self *Float) Min(metaData *MetaData) (min float64, ok bool, err error)

func (*Float) Required

func (self *Float) Required(metaData *MetaData) bool

func (*Float) Set

func (self *Float) Set(value float64)

func (*Float) SetString

func (self *Float) SetString(str string) error

func (*Float) String

func (self *Float) String() string

func (*Float) Valid

func (self *Float) Valid(metaData *MetaData) bool

func (*Float) Validate

func (self *Float) Validate(metaData *MetaData) error

type FloatAboveMax

type FloatAboveMax struct {
	Value float64
	Max   float64
}

func (*FloatAboveMax) Error

func (self *FloatAboveMax) Error() string

type FloatBelowMin

type FloatBelowMin struct {
	Value float64
	Min   float64
}

func (*FloatBelowMin) Error

func (self *FloatBelowMin) Error() string

type FloatNotReal

type FloatNotReal struct {
	Value float64
}

func (*FloatNotReal) Error

func (self *FloatNotReal) Error() string

type GeoLocation

type GeoLocation struct {
	Longitude Float
	Latitude  Float
}

func (*GeoLocation) IsEmpty

func (self *GeoLocation) IsEmpty() bool

func (*GeoLocation) Required

func (self *GeoLocation) Required(metaData *MetaData) bool

func (*GeoLocation) SetString

func (self *GeoLocation) SetString(str string) error

func (*GeoLocation) String

func (self *GeoLocation) String() string

func (*GeoLocation) Validate

func (self *GeoLocation) Validate(metaData *MetaData) error

type IndexedObjectIterator

type IndexedObjectIterator struct {
	// contains filtered or unexported fields
}

func (*IndexedObjectIterator) Err

func (self *IndexedObjectIterator) Err() error

func (*IndexedObjectIterator) Next

func (self *IndexedObjectIterator) Next() interface{}

type Int

type Int int64

Attributes: * min * max * label

func NewInt

func NewInt(value int64) *Int

func (*Int) Get

func (self *Int) Get() int64

func (*Int) GetInt

func (self *Int) GetInt() int

func (*Int) IsEmpty

func (self *Int) IsEmpty() bool

func (*Int) Max

func (self *Int) Max(metaData *MetaData) (max int64, ok bool, err error)

func (*Int) Min

func (self *Int) Min(metaData *MetaData) (min int64, ok bool, err error)

func (*Int) Required

func (self *Int) Required(metaData *MetaData) bool

func (*Int) Set

func (self *Int) Set(value int64)

func (*Int) SetInt

func (self *Int) SetInt(value int)

func (*Int) SetString

func (self *Int) SetString(str string) error

func (*Int) String

func (self *Int) String() string

func (*Int) Validate

func (self *Int) Validate(metaData *MetaData) error

type IntAboveMax

type IntAboveMax struct {
	Value int64
	Max   int64
}

func (*IntAboveMax) Error

func (self *IntAboveMax) Error() string

type IntBelowMin

type IntBelowMin struct {
	Value int64
	Min   int64
}

func (*IntBelowMin) Error

func (self *IntBelowMin) Error() string

type InvalidChoice

type InvalidChoice struct {
	Value   string
	Options []string
}

func (*InvalidChoice) Error

func (self *InvalidChoice) Error() string

type InvalidCountryCode

type InvalidCountryCode struct {
	CountryCode string
}

func (*InvalidCountryCode) String

func (self *InvalidCountryCode) String() string

type InvalidLanguageCode

type InvalidLanguageCode struct {
	Language string
}

func (*InvalidLanguageCode) String

func (self *InvalidLanguageCode) String() string

type Iterator

type Iterator interface {
	Next() interface{}
	Err() error
}

Iteration stops with Next() == nil, check Err() afterwards

func ConvertIterator

func ConvertIterator(from Iterator, convertFunc func(interface{}) interface{}) Iterator

ConvertIterator returns an Iterator that calls convertFunc for every non nil from.Next() result and returns the result of convertFunc for every Next().

func NewErrorOnlyIterator

func NewErrorOnlyIterator(err error) Iterator

func NewIndexedObjectIterator

func NewIndexedObjectIterator(objects []interface{}, indices []int) Iterator

func NewObjectIterator

func NewObjectIterator(objects ...interface{}) Iterator

func NewObjectOrErrorOnlyIterator

func NewObjectOrErrorOnlyIterator(object interface{}, err error) Iterator

func RandomIterator

func RandomIterator(i Iterator) Iterator

func SortIterator

func SortIterator(i Iterator, lessFunc func(a, b interface{}) (less bool)) Iterator

type IteratorFunc

type IteratorFunc func() interface{}

func (IteratorFunc) Err

func (self IteratorFunc) Err() error

func (IteratorFunc) Next

func (self IteratorFunc) Next() interface{}

type Language

type Language string

Attributes:

label
required

func NewLanguage

func NewLanguage(value string) *Language

func (*Language) EnglishName

func (self *Language) EnglishName() string

func (*Language) FixValue

func (self *Language) FixValue(metaData *MetaData)

func (*Language) Get

func (self *Language) Get() string

func (*Language) IsEmpty

func (self *Language) IsEmpty() bool

func (*Language) Required

func (self *Language) Required(metaData *MetaData) bool

func (*Language) Set

func (self *Language) Set(value string) error

func (*Language) SetString

func (self *Language) SetString(str string) error

func (*Language) String

func (self *Language) String() string

func (*Language) Validate

func (self *Language) Validate(metaData *MetaData) error

type LimitedIterator

type LimitedIterator struct {
	Iterator
	// contains filtered or unexported fields
}

func NewLimitedIterator

func NewLimitedIterator(iter Iterator, limit int) *LimitedIterator

func (*LimitedIterator) Next

func (self *LimitedIterator) Next() interface{}

type MetaData

type MetaData struct {
	Kind    MetaDataKind
	Value   reflect.Value
	Depth   int    // number of steps up to the root parent
	Name    string // empty for array and slice fields
	Index   int    // will also be set for struct fields
	Parent  *MetaData
	Dynamic bool
	// contains filtered or unexported fields
}

MetaData holds meta data about an model data item.

func (*MetaData) Attrib

func (self *MetaData) Attrib(tagKey, name string) (value string, ok bool)

Attrib returns the value of a tag attribute if available. Array and slice fields inherit the attributes of their named parent fields. The meaning of attributes is interpreted by the package that reads them. Attributes are defined in a struct tag named "gostart", "model" or "view" and written as name=value. Multiple attributes are separated by '|'. Example:

type Struct {
	X int `model:"min=0|max=10"`
	S []int `model:"maxlen=3|min=0|max=10"
	hidden int
	Ignore int `gostart:"-"`
	Z int `view:"lable=A longer label for display"`
}

func (*MetaData) BoolAttrib

func (self *MetaData) BoolAttrib(tagKey, name string) bool

BoolAttrib uses Attrib() to check if the value of an attribute is "true". A non existing attribibute is considered to be false.

func (*MetaData) IsIndexedValue

func (self *MetaData) IsIndexedValue() bool

func (*MetaData) IsModelValue

func (self *MetaData) IsModelValue() bool

func (*MetaData) IsModelValueOrChild

func (self *MetaData) IsModelValueOrChild() bool

func (*MetaData) IsNamed

func (self *MetaData) IsNamed() bool

func (*MetaData) IsNamedValue

func (self *MetaData) IsNamedValue() bool

func (*MetaData) ModelValidator

func (self *MetaData) ModelValidator() (val Validator, ok bool)

func (*MetaData) ModelValue

func (self *MetaData) ModelValue() (val Value, ok bool)

func (*MetaData) NameOrIndex

func (self *MetaData) NameOrIndex() string

NameOrIndex returns self.Name if not empty or else self.Index.

func (*MetaData) NameOrWildcard

func (self *MetaData) NameOrWildcard() string

NameOrWildcard returns self.Name if not empty or else the wildcard "$".

func (*MetaData) Path

func (self *MetaData) Path() []*MetaData

Path returns a slice of *MetaData that holds all parents from the root parent up to (and including) self.

func (*MetaData) RootParent

func (self *MetaData) RootParent() *MetaData

func (*MetaData) Selector

func (self *MetaData) Selector() string

Selector returns the field names or indices for array/slice fields from the root parent up the the current data item concatenated with with '.'.

func (*MetaData) SelectorsMatch

func (self *MetaData) SelectorsMatch(list []string) bool

func (*MetaData) String

func (self *MetaData) String() string

func (*MetaData) WildcardSelector

func (self *MetaData) WildcardSelector() string

WildcardSelector returns the field names or the wildcard '$' for array/slice fields from the root parent up the the current data item concatenated with with '.'.

type MetaDataKind

type MetaDataKind int

MetaDataKind is the kind of a data item described by MetaData.

const (
	StructKind MetaDataKind = iota
	MapKind
	DynamicKind
	ArrayKind
	SliceKind
	ValueKind // everything else, no children
)

func GetMetaDataKind

func GetMetaDataKind(v reflect.Value) MetaDataKind

func (MetaDataKind) HasIndexedFields

func (self MetaDataKind) HasIndexedFields() bool

func (MetaDataKind) HasNamedFields

func (self MetaDataKind) HasNamedFields() bool

func (MetaDataKind) String

func (self MetaDataKind) String() string

type MultipleChoice

type MultipleChoice []string

func (*MultipleChoice) Get

func (self *MultipleChoice) Get() []string

func (*MultipleChoice) IsEmpty

func (self *MultipleChoice) IsEmpty() bool

func (*MultipleChoice) IsSet

func (self *MultipleChoice) IsSet(option string) bool

func (*MultipleChoice) Options

func (self *MultipleChoice) Options(metaData *MetaData) []string

func (*MultipleChoice) Required

func (self *MultipleChoice) Required(metaData *MetaData) bool

func (*MultipleChoice) Set

func (self *MultipleChoice) Set(value ...string)

func (*MultipleChoice) SetString

func (self *MultipleChoice) SetString(str string) error

func (*MultipleChoice) String

func (self *MultipleChoice) String() string

func (*MultipleChoice) Validate

func (self *MultipleChoice) Validate(metaData *MetaData) error

type ObjectIterator

type ObjectIterator struct {
	// contains filtered or unexported fields
}

func (*ObjectIterator) Err

func (self *ObjectIterator) Err() error

func (*ObjectIterator) Next

func (self *ObjectIterator) Next() interface{}

type Password

type Password string

func NewPassword

func NewPassword(value string) *Password

func (*Password) EqualsHashed

func (self *Password) EqualsHashed(value string) bool

func (*Password) FixValue

func (self *Password) FixValue(metaData *MetaData)

func (*Password) Get

func (self *Password) Get() string

func (*Password) IsEmpty

func (self *Password) IsEmpty() bool

func (*Password) Maxlen

func (self *Password) Maxlen(metaData *MetaData) (maxlen int, ok bool, err error)

func (*Password) Minlen

func (self *Password) Minlen(metaData *MetaData) (minlen int, ok bool, err error)

func (*Password) Required

func (self *Password) Required(metaData *MetaData) bool

func (*Password) Set

func (self *Password) Set(value string)

func (*Password) SetHashed

func (self *Password) SetHashed(value string)

todo salt

func (*Password) SetString

func (self *Password) SetString(str string) error

func (*Password) String

func (self *Password) String() string

func (*Password) Validate

func (self *Password) Validate(metaData *MetaData) error

type Phone

type Phone string

func NewPhone

func NewPhone(value string) *Phone

func (*Phone) FixValue

func (self *Phone) FixValue(metaData *MetaData)

func (*Phone) Get

func (self *Phone) Get() string

func (*Phone) IsEmpty

func (self *Phone) IsEmpty() bool

func (*Phone) Required

func (self *Phone) Required(metaData *MetaData) bool

func (*Phone) Set

func (self *Phone) Set(value string)

func (*Phone) SetString

func (self *Phone) SetString(str string) error

func (*Phone) String

func (self *Phone) String() string

func (*Phone) Validate

func (self *Phone) Validate(metaData *MetaData) error

type Reference

type Reference interface {
	Value
	Reference()
}

type RequiredError

type RequiredError struct {
	// contains filtered or unexported fields
}

func NewRequiredError

func NewRequiredError(metaData *MetaData) *RequiredError

func (RequiredError) Error

func (self RequiredError) Error() string

type String

type String string

func NewString

func NewString(value string) *String

func (*String) FixValue

func (self *String) FixValue(metaData *MetaData)

func (*String) Get

func (self *String) Get() string

func (*String) GetOrDefault

func (self *String) GetOrDefault(defaultString string) string

func (*String) IsEmpty

func (self *String) IsEmpty() bool

func (*String) Maxlen

func (self *String) Maxlen(metaData *MetaData) (maxlen int, ok bool, err error)

func (*String) Minlen

func (self *String) Minlen(metaData *MetaData) (minlen int, ok bool, err error)

func (*String) Required

func (self *String) Required(metaData *MetaData) bool

func (*String) Set

func (self *String) Set(value string)

func (*String) SetString

func (self *String) SetString(str string) error

func (*String) String

func (self *String) String() string

func (*String) Validate

func (self *String) Validate(metaData *MetaData) error

type StringTooLong

type StringTooLong struct {
	Str    string
	Maxlen int
}

func (*StringTooLong) Error

func (self *StringTooLong) Error() string

type StringTooShort

type StringTooShort struct {
	Str    string
	Minlen int
}

func (*StringTooShort) Error

func (self *StringTooShort) Error() string

type Text

type Text string

func NewText

func NewText(value string) *Text

func (*Text) FixValue

func (self *Text) FixValue(metaData *MetaData)

func (*Text) Get

func (self *Text) Get() string

func (*Text) GetOrDefault

func (self *Text) GetOrDefault(defaultText string) string

func (*Text) IsEmpty

func (self *Text) IsEmpty() bool

func (*Text) Maxlen

func (self *Text) Maxlen(metaData *MetaData) (maxlen int, ok bool, err error)

func (*Text) Minlen

func (self *Text) Minlen(metaData *MetaData) (minlen int, ok bool, err error)

func (*Text) Required

func (self *Text) Required(metaData *MetaData) bool

func (*Text) Set

func (self *Text) Set(value string)

func (*Text) SetString

func (self *Text) SetString(str string) error

func (*Text) String

func (self *Text) String() string

func (*Text) Validate

func (self *Text) Validate(metaData *MetaData) error

type Time

type Time int64

Time in milliseconds since January 1, year 1 00:00:00 UTC. Time values are always in UTC.

func NewTime

func NewTime(value int64) *Time

func (*Time) Get

func (self *Time) Get() time.Time

func (*Time) IsEmpty

func (self *Time) IsEmpty() bool

func (*Time) Required

func (self *Time) Required(metaData *MetaData) bool

func (*Time) Set

func (self *Time) Set(t time.Time)

func (*Time) Validate

func (self *Time) Validate(metaData *MetaData) error

type Url

type Url string

func NewUrl

func NewUrl(value string) *Url

func (*Url) FixValue

func (self *Url) FixValue(metaData *MetaData)

func (*Url) Get

func (self *Url) Get() string

func (*Url) GetOrDefault

func (self *Url) GetOrDefault(defaultURL string) string

func (*Url) IsEmpty

func (self *Url) IsEmpty() bool

func (*Url) Required

func (self *Url) Required(metaData *MetaData) bool

func (*Url) Set

func (self *Url) Set(value string) error

func (*Url) SetString

func (self *Url) SetString(str string) error

func (*Url) String

func (self *Url) String() string

func (*Url) Validate

func (self *Url) Validate(metaData *MetaData) error

type Validator

type Validator interface {
	// Validate returns an error if metaData is not valid.
	// In case of multiple errors errs.ErrSlice is returned.
	Validate(metaData *MetaData) error
}

type Value

type Value interface {
	//Init(metaData *MetaData)
	String() string
	// SetString returns only error from converting str to the
	// underlying value type.
	// It does not return validation errors of the converted value.
	SetString(str string) (strconvErr error)
	IsEmpty() bool
	Required(metaData *MetaData) bool
	Validator
}

type Visitor

type Visitor interface {
	BeginNamedFields(namedFields *MetaData) error
	NamedField(field *MetaData) error
	EndNamedFields(namedFields *MetaData) error

	BeginIndexedFields(indexedFields *MetaData) error
	IndexedField(field *MetaData) error
	EndIndexedFields(indexedFields *MetaData) error
}

func FieldTypeVisitor

func FieldTypeVisitor(callback interface{}) Visitor

FieldTypeVisitor calls callback for every struct field whose type is asignable to the type of the callback's first argument. callback can have a second, optional argument of type *MetaData. callback can return one error value or no result.

type VisitorFunc

type VisitorFunc func(data *MetaData) error

VisitorFunc calls its function for every Visitor method call, thus mapping all Visitor methods on a single function.

func (VisitorFunc) BeginIndexedFields

func (self VisitorFunc) BeginIndexedFields(indexedFields *MetaData) error

func (VisitorFunc) BeginNamedFields

func (self VisitorFunc) BeginNamedFields(namedFields *MetaData) error

func (VisitorFunc) EndIndexedFields

func (self VisitorFunc) EndIndexedFields(indexedFields *MetaData) error

func (VisitorFunc) EndNamedFields

func (self VisitorFunc) EndNamedFields(namedFields *MetaData) error

func (VisitorFunc) IndexedField

func (self VisitorFunc) IndexedField(field *MetaData) error

func (VisitorFunc) NamedField

func (self VisitorFunc) NamedField(field *MetaData) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL