Skip to content

Utility functions that we often use when working with mgo

Notifications You must be signed in to change notification settings

transcovo/mgo-helper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mgo-helper

This lib regroups all the golang mongo driver mgo utils that we developped to integrate into our projects.

CircleCI codecov GoDoc

Requirements

Minimum Go version: 1.7

Installation

  • 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

Usage

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

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.

About

Utility functions that we often use when working with mgo

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published