Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidId = errors.New("invalid id")
var ErrMissingCryptoSecret = errors.New("missing crypto secret")
var ErrMongoCollectionNotFetched = errors.New("mongo collection not fetched")
var ErrRecordNotFound = mgo.ErrNotFound
Functions ¶
func Destroy ¶
Delete from the DB For this to work, the model should be initialized with the correct value of Id for which to lookup in DB
func Find ¶
Returns the Struct from the DB For this to work, the model should be initialized with the correct value of Id for which to lookup in DB
func FindBy ¶
FindBy returns a record of a model interface by a where clause passed to it. It expects an input of the whereClause as the shortened bson.M format. Check here : https://godoc.org/gopkg.in/mgo.v2/bson#M
func FindMany ¶
FindBy returns many records of a model interface by a where clause passed to it. It expects the string collectionName it should look into It expects an input of the whereClause as the shortened bson.M format. Check here : https://godoc.org/gopkg.in/mgo.v2/bson#M
This method has an issue with Decryption. So Decrypt the models manually. var models []MyAwesomeModel FindMany("my_awesome_models", bson.M{"some_field": "some_field_value"}, &models)
In case limit and skip is called, then please pass them in the options parameter in the order skip, limit eg, to have no skips but to have a limit of 10
FindMany("my_awesome_models", bson.M{"some_field": "some_field_value"}, &models, -1, 10)
Types ¶
type CryptoConfig ¶
type CryptoConfig struct {
AESSecret []byte
}
CryptoConfig represents the configuration keys of encryption secret
type Model ¶
type Model interface {
// This method should return the collection name in the mongo DB where this model will be stored
CollectionName() string
// Should return a valid MongoConfig which contains the configuration values to connect to the DB
DBConfig() *MongoConfig
}
Model interface represents a storable entity Two methods need to be defined for this.
type Models ¶
type Models interface {
// This method should return the collection name in the mongo DB where this model will be stored
CollectionName() string
// Should return a valid MongoConfig which contains the configuration values to connect to the DB
DBConfig() *MongoConfig
}
A models interface represents a storable entity list of entities Two methods need to be defined for this.
type MongoConfig ¶
type MongoConfig struct {
// Define a comma separated array of Servers here
Servers string
// Define the DB Name for which the corresponding model would connect to
DBName string
Timeout time.Duration
// Specifies if the connection is SSL. This is important to use a tls.Dial function in that case due to limitations of mgo package
IsSSL bool
// configuration keys for encryption and decryption
CryptoConfig *CryptoConfig
}
MongoConfig struct determines the connection to the mongo DB.