usermgo

package
v0.0.0-...-633417b Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2018 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound       = errors.New("record not found")
	ErrExpiredContext = errors.New("context has expired")
)

errors ...

Functions

func AddIndex

func AddIndex(db MongoDB, m metrics.Metrics, col string, indexes ...mgo.Index) error

AddIndex adds provided index if any to giving collection within database exposed by the provided MongoDB instance.

func Count

func Count(ctx context.Context, db MongoDB, m metrics.Metrics, col string) (int, error)

Count attempts to return the total number of record from the db.

func Create

func Create(ctx context.Context, db MongoDB, m metrics.Metrics, col string, elem methods.User) error

Create attempts to add the record into the db using the provided instance of the methods.User. Records using this DB must have a public id value, expressed either by a bson or json tag on the given User struct.

func Delete

func Delete(ctx context.Context, db MongoDB, m metrics.Metrics, col string, publicID string) error

Delete attempts to remove the record from the db using the provided publicID. Records using this DB must have a public id value, expressed either by a bson or json tag on the given methods.User struct.

func Exec

func Exec(ctx context.Context, db MongoDB, m metrics.Metrics, col string, isread bool, fx func(col *mgo.Collection) error) error

Exec provides a function which allows the execution of a custom function against the collection.

func Get

func Get(ctx context.Context, db MongoDB, m metrics.Metrics, col string, publicID string) (methods.User, error)

Get retrieves a record from the db using the publicID and returns the methods.User type. Records using this DB must have a public id value, expressed either by a bson or json tag on the given User struct.

func GetAll

func GetAll(ctx context.Context, db MongoDB, m metrics.Metrics, col string, order string, orderBy string, page int, responsePerPage int) ([]methods.User, int, error)

GetAll retrieves all records from the db and returns a slice of methods.User type. Records using this DB must have a public id value, expressed either by a bson or json tag on the given User struct.

func GetAllByOrder

func GetAllByOrder(ctx context.Context, db MongoDB, m metrics.Metrics, col string, order string, orderBy string) ([]methods.User, error)

GetAllByOrder retrieves all records from the db and returns a slice of methods.User type. Records using this DB must have a public id value, expressed either by a bson or json tag on the given User struct.

func GetByField

func GetByField(ctx context.Context, db MongoDB, m metrics.Metrics, col string, key string, value interface{}) (methods.User, error)

GetByField retrieves a record from the db using the provided field key and value returns the methods.User type. Records using this DB must have a public id value, expressed either by a bson or json tag on the given User struct.

func Update

func Update(ctx context.Context, db MongoDB, m metrics.Metrics, col string, publicID string, elem methods.User) error

Update uses a record from the db using the publicID and returns the methods.User type. Records using this DB must have a public id value, expressed either by a bson or json tag on the given User struct.

Types

type Config

type Config struct {
	DB       string `toml:"db" json:"db"`
	AuthDB   string `toml:"authdb" json:"authdb"`
	User     string `toml:"user" json:"user"`
	Password string `toml:"password" json:"password"`
	Host     string `toml:"host" json:"host"`
}

Config embodies the data used to connect to user's mongo connection.

func (Config) Empty

func (mgc Config) Empty() bool

Empty returns true/false if all Config values are at default/empty/non-set state.

func (Config) Validate

func (mgc Config) Validate() error

Validate returns an error if the config is invalid.

type MongoDB

type MongoDB interface {
	New(isread bool) (*mgo.Database, *mgo.Session, error)
}

MongoDB defines a interface which exposes a method for retrieving a mongo.Database and mongo.Session.

func NewMongoDB

func NewMongoDB(conf Config) MongoDB

NewMongoDB returns a new instance of a MongoDB.

type UserConsumer

type UserConsumer interface {
	Consume(map[string]interface{}) error
}

UserConsumer defines an interface which accepts a map of data which will be consumed into the giving implementing structure as decided by the structure.

type UserFields

type UserFields interface {
	Fields() (map[string]interface{}, error)
}

UserFields defines an interface which exposes method to return a map of all attributes associated with the defined structure as decided by the structure.

type Validation

type Validation interface {
	Validate() error
}

Validation defines an interface which expose a method to validate a giving type.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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