model

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

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

Go to latest
Published: Jul 7, 2015 License: GPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrProfileEmpty  = logex.Define("profile is empty")
	ErrInvalidObject = logex.Define("Invalid input to ObjectIdHex")
)
View Source
var (
	RegexpUserEmail     = regexp.MustCompile(`\w+@(\w+\.)+\w+`)
	ErrUserEmailInvalid = logex.Define("email '%v' is invalid")
	ErrUserPswdEmpty    = logex.Define("password is empty")
	ErrUserLoginFail    = logex.Define("incorrect username or password")
	ErrUserInvalidUid   = logex.Define("invalid uid")
	ErrUserIdNotFound   = logex.Define("user not found")

	ErrUserEmailAlreadyTaken = logex.Define("email '%v' is already taken")
)
View Source
var (
	ErrSessionInvalidId = logex.Define("invalid session id")
)
View Source
var Models *models

Functions

func BsonObjectId

func BsonObjectId(id string) (bson.ObjectId, bool)

func DialUrl

func DialUrl(url_ string) (string, *mgo.Session, error)

func Init

func Init(url_ string) (err error)

func IsPanicError

func IsPanicError(err error) bool

Types

type BaseModel

type BaseModel struct {
	Name string
	// contains filtered or unexported fields
}

func NewBaseModel

func NewBaseModel(mdb *Mdb, ins interface{}) *BaseModel

func (*BaseModel) All

func (b *BaseModel) All(query M, result interface{}) error

func (*BaseModel) Count

func (b *BaseModel) Count(query M) (n int, err error)

func (*BaseModel) Distinct

func (b *BaseModel) Distinct(key string, query M, result interface{}) error

func (*BaseModel) Has

func (b *BaseModel) Has(query M) (bool, error)

func (*BaseModel) Insert

func (b *BaseModel) Insert(data ...interface{}) error

func (*BaseModel) One

func (b *BaseModel) One(query M, result interface{}) error

func (*BaseModel) Remove

func (b *BaseModel) Remove(selector M) error

func (*BaseModel) Update

func (b *BaseModel) Update(selector, change M) error

func (*BaseModel) Upsert

func (b *BaseModel) Upsert(selector, change M) error

type Indexer

type Indexer interface {
	Index() []mgo.Index
}

type M

type M bson.M

type Mdb

type Mdb struct {
	DBName string
	// contains filtered or unexported fields
}

func NewMdb

func NewMdb(dbname string, mdb *mgo.Session) *Mdb

func (*Mdb) All

func (m *Mdb) All(c string, query M, result interface{}) error

func (*Mdb) Close

func (m *Mdb) Close()

func (*Mdb) Count

func (m *Mdb) Count(c string, query M) (int, error)

func (*Mdb) Distinct

func (m *Mdb) Distinct(c string, key string, query M, result interface{}) error

func (*Mdb) Insert

func (m *Mdb) Insert(c string, docs ...interface{}) error

func (*Mdb) One

func (m *Mdb) One(c string, query M, result interface{}) error

func (*Mdb) Remove

func (m *Mdb) Remove(c string, selector M) error

func (*Mdb) Update

func (m *Mdb) Update(c string, selector, update M) error

func (*Mdb) Upsert

func (m *Mdb) Upsert(c string, selector, update M) error

type Relation

type Relation struct {
	Uids     [2]string `bson:"uids"`
	Approved [2]bool   `bson:"approved"`
	Source   string    `bson:"source"`
	Date     time.Time `bson:"date"`
}

func (Relation) Index

func (r Relation) Index() []mgo.Index

type RelationModel

type RelationModel struct {
	*BaseModel
}

func NewRelationModel

func NewRelationModel(mdb *Mdb) *RelationModel

func (*RelationModel) Add

func (r *RelationModel) Add()

type Session

type Session struct {
	Id       bson.ObjectId `bson:"_id" json:"id"`
	UserId   string        `bson:"userid" json:"userid"`
	ToUid    string        `bson:"touid" json:"touid"`
	LastDate time.Time     `bson:"lastDate" json:"lastDate"`
}

type SessionModel

type SessionModel struct {
	*BaseModel
}

func NewSessionModel

func NewSessionModel(mdb *Mdb) *SessionModel

func (*SessionModel) Get

func (sm *SessionModel) Get(sessionId string) (s *Session, err error)

func (*SessionModel) GetList

func (s *SessionModel) GetList(uid string) (list []*Session, err error)

func (*SessionModel) New

func (sm *SessionModel) New(uid, toUid string) (s *Session, err error)

type User

type User struct {
	Id     bson.ObjectId `bson:"_id"`
	Email  string        `bson:"email"`
	Secret string        `bson:"secret"`
	Token  string        `bson:"token"`
	Valid  bool          `bson:"valid"`
}

func (User) Index

func (u User) Index() []mgo.Index

type UserModel

type UserModel struct {
	*BaseModel
}

func NewUserModel

func NewUserModel(mdb *Mdb) *UserModel

func (*UserModel) CheckToken

func (um *UserModel) CheckToken(uid, token string) (bool, error)

func (*UserModel) Find

func (um *UserModel) Find(email string) (bool, error)

func (*UserModel) GetToken

func (um *UserModel) GetToken(uid string) (token string, err error)

func (*UserModel) HasUid

func (um *UserModel) HasUid(uid string) (bool, error)

func (*UserModel) Login

func (um *UserModel) Login(email, secret string) (uid, token string, err error)

func (*UserModel) Register

func (um *UserModel) Register(email, secret string) (*User, error)

Jump to

Keyboard shortcuts

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