model

package
v0.0.0-...-9012c6e Latest Latest
Warning

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

Go to latest
Published: May 22, 2012 License: MIT Imports: 18 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 NoValidationErrors []*ValidationError = []*ValidationError{}

Functions

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 PasswordHash

func PasswordHash(password string) (hash string)

func WalkStructure

func WalkStructure(data interface{}, maxDepth int, callback WalkStructureCallback)

If maxDepth is zero, no limit will be used

Types

type Bool

type Bool bool

Attributes: * label

func (*Bool) Get

func (self *Bool) Get() bool

func (*Bool) IsEmpty

func (self *Bool) IsEmpty() 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) []*ValidationError

type Choice

type Choice string

Separate options with ',' escape ',' in options with '\,'

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) 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) []*ValidationError

type Country

type Country string

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) []*ValidationError

type Date

type Date string

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) []*ValidationError

todo min max

type DateTime

type DateTime 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) []*ValidationError

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) 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) []*ValidationError

type Email

type Email string

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) []*ValidationError

type EmptyIterator

type EmptyIterator struct {
}

func (*EmptyIterator) Err

func (self *EmptyIterator) Err() error

func (*EmptyIterator) Next

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

type ErrorIterator

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

func (*ErrorIterator) Err

func (self *ErrorIterator) Err() error

func (*ErrorIterator) Next

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

type FilterFunc

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

type FilterIterator

type FilterIterator struct {
	Iterator   Iterator
	PassFilter FilterFunc
}

func (*FilterIterator) Err

func (self *FilterIterator) Err() error

func (*FilterIterator) Next

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

type Float

type Float float64

Attributes: * label * min * max * valid

func (*Float) Get

func (self *Float) Get() float64

func (*Float) Hidden

func (self *Float) Hidden(metaData *MetaData) (hidden bool)

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) 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) []*ValidationError

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, Latitude float64
}

func (*GeoLocation) IsEmpty

func (self *GeoLocation) IsEmpty() 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) []*ValidationError

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 (*Int) Get

func (self *Int) Get() int64

func (*Int) Hidden

func (self *Int) Hidden(metaData *MetaData) (hidden bool)

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) Set

func (self *Int) Set(value int64)

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) []*ValidationError

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 NewErrorIterator

func NewErrorIterator(err error) Iterator

func NewIndexedObjectIterator

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

func NewObjectIterator

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

func NewObjectOrErrorIterator

func NewObjectOrErrorIterator(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 Language

type Language string

Attributes:

label
required

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) []*ValidationError

type LimitedIterator

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

func NewLimitedIterator

func NewLimitedIterator(iter Iterator, limit int) *LimitedIterator

func (*LimitedIterator) Err

func (self *LimitedIterator) Err() error

func (*LimitedIterator) Next

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

type MetaData

type MetaData struct {
	ParentStruct reflect.Value
	Parent       *MetaData
	Depth        int
	Name         string
	Index        int
	// contains filtered or unexported fields
}

func (*MetaData) ArrayWildcardSelector

func (self *MetaData) ArrayWildcardSelector() string

func (*MetaData) Attrib

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

func (*MetaData) BoolAttrib

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

func (*MetaData) IsIndex

func (self *MetaData) IsIndex() bool

func (*MetaData) Selector

func (self *MetaData) Selector() string

type MultipleChoice

type MultipleChoice []string

func (*MultipleChoice) IsEmpty

func (self *MultipleChoice) IsEmpty() bool

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) []*ValidationError

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 (*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) Set

func (self *Password) Set(value string)

func (*Password) SetHashed

func (self *Password) SetHashed(value string)

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) []*ValidationError

type Phone

type Phone string

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) 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) []*ValidationError

type Reference

type Reference interface {
	Value
	Reference()
}

type String

type 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) Hidden

func (self *String) Hidden(metaData *MetaData) (hidden bool)

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) 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) []*ValidationError

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 (*Text) Cols

func (self *Text) Cols(metaData *MetaData) (cols int, ok bool, err error)

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) Rows

func (self *Text) Rows(metaData *MetaData) (rows int, ok bool, err error)

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) []*ValidationError

type Time

type Time int64

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

func (*Time) Get

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

func (*Time) IsEmpty

func (self *Time) IsEmpty() bool

func (*Time) Set

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

type Url

type Url string

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) []*ValidationError

type ValidationError

type ValidationError struct {
	WrappedError error
	MetaData     *MetaData
}

func NewRequiredValidationError

func NewRequiredValidationError(metaData *MetaData) *ValidationError

func NewValidationErrors

func NewValidationErrors(error error, metaData *MetaData) []*ValidationError

func Validate

func Validate(data interface{}, maxDepth int) []*ValidationError

func (*ValidationError) Error

func (self *ValidationError) Error() string

type Validator

type Validator interface {
	Validate(metaData *MetaData) []*ValidationError
}

type Value

type Value interface {
	String() string
	SetString(str string) error
	IsEmpty() bool
	Validator
}

type WalkStructureCallback

type WalkStructureCallback func(data interface{}, metaData *MetaData)

Jump to

Keyboard shortcuts

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