This lib regroups all the golang mongo driver mgo utils that we developped to integrate into our projects.
Minimum Go version: 1.7
-
If you are using govendor
govendor fetch github.com/transcovo/mgo-helper govendor fetch github.com/transcovo/mgo-helper/mongo
-
standard way (not recommended)
got get -u github.com/transcovo/mgo-helper
-
You may want to use other modules (doc to come):
govendor fetch github.com/transcovo/mgo-helper/models govendor fetch github.com/transcovo/mgo-helper/utils
The main function to be used to connect is mongo.InitMongoFromConfig
by providing a mongo.Configuration
object
import (
"github.com/transcovo/mgo-helper/mongo"
)
mongoConfig := mongo.Configuration{
PingFrequency: 100,
SSLCert: []byte{},
UseSSL: false,
URL: "mongodb://localhost:27017/some-test-db",
}
db, teardown := mongo.InitMongoFromConfig(mongoConfig)
defer teardown()
Tests with go are a little weird: you can't run all the tests at once for your project.
Still, to do that, run ./tools/test.sh
. It will recursively run the tests for all packages. It's the fastest
test script if you're following TDD. To add a coverage report generation to the tests (much slower), run ./tools/coverage.sh
.
You can run ./tools/coverage.sh --html
to run the tests with the coverage report and open the coverage
result in the browser.