# README
go-rscsrv-mgo
The go-rscsrv-mgo is the MongoDB resource service that wraps globalsign/mgo library.
Dependencies
It depends on the lab259/go-rscsrv (and its dependencies, of course) itself and the globalsign/mgo library.
Installation
You may fetch the library directly using go get
.
go get github.com/lab259/go-rscsrv-mgo
Usage
Applying configuration and starting service
// Create MgoService instance
var mgoService MgoService
// Applying configuration
err := mgoService.ApplyConfiguration(MgoServiceConfiguration{
Addresses: []string{"localhost"},
Username: "username",
Password: "password",
Database: "my-db",
PoolSize: 1,
Timeout: 60,
})
if err != nil {
panic(err)
}
// Starting service
err := mgoService.Start()
if err != nil {
panic(err)
}
// Create a custom object
var object MyModel
// Executing something using a *mgo.Session
err := mgoService.RunWithSession(func(session *mgo.Session) error {
// Retrieving an object from the MongoDB
return session.DB("my-db").C("my-collection").FindId("my-object-id").One(&object)
})
if err != nil {
panic(err)
}
id := object.Id // "my-object-id"
# Structs
MgoService implements the mgo service itself.
MgoServiceConfiguration describes the `MgoService` configuration.
# Type aliases
MgoServiceMode is an alias for the `mgo.Mode` that implements Unmarshaling from the YAML.