Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for setting mgo.DialInfo #11

Merged
merged 2 commits into from
Jan 6, 2017

Conversation

iamsaso
Copy link
Contributor

@iamsaso iamsaso commented Jan 5, 2017

This enables tapping into mgo.DialInfo and setting up SSL when needed

Code that I use to enable SSL

config := &bongo.Config{
	ConnectionString: viper.GetString("mongodb.uri"),
	Database:         viper.GetString("mongodb.database"),
}

if viper.GetBool("mongodb.ssl") {
	if config.DialInfo, err = mgo.ParseURL(config.ConnectionString); err != nil {
		panic(fmt.Sprintf("cannot parse given URI %s due to error: %s", config.ConnectionString, err.Error()))
	}

	tlsConfig := &tls.Config{}
	config.DialInfo.DialServer = func(addr *mgo.ServerAddr) (net.Conn, error) {
		conn, err := tls.Dial("tcp", addr.String(), tlsConfig)
		return conn, err
	}

	config.DialInfo.Timeout = time.Second * 3
}

connection, err = bongo.Connect(config)
if err != nil {
	log.Fatal(err)
}

@coveralls
Copy link

coveralls commented Jan 5, 2017

Coverage Status

Coverage decreased (-0.05%) to 83.182% when pulling d40f50c on sasso:master into 0d02692 on maxwellhealth:master.

@coveralls
Copy link

coveralls commented Jan 6, 2017

Coverage Status

Coverage increased (+1.01%) to 84.242% when pulling 53f6a19 on sasso:master into 0d02692 on maxwellhealth:master.

@securingsincity
Copy link
Contributor

@Sasso this looks great thanks!

@securingsincity securingsincity merged commit 5314e13 into go-bongo:master Jan 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants