Esempio n. 1
0
File: db.go Progetto: wtangiit/AWE
func Initialize() (err error) {
	c := connection{}
	s, err := mgo.DialWithTimeout(conf.MONGODB_HOST, DbTimeout)
	if err != nil {
		e := errors.New(fmt.Sprintf("no reachable mongodb server(s) at %s", conf.MONGODB_HOST))
		return e
	}
	c.Session = s
	c.DB = c.Session.DB(conf.MONGODB_DATABASE)
	if conf.MONGODB_USER != "" && conf.MONGODB_PASSWD != "" {
		c.DB.Login(conf.MONGODB_USER, conf.MONGODB_PASSWD)
	}
	Connection = c
	return
}
Esempio n. 2
0
File: db.go Progetto: paczian/Shock
func Initialize() (err error) {
	c := connection{}
	s, err := mgo.DialWithTimeout(conf.Conf["mongodb-hosts"], DbTimeout)
	if err != nil {
		e := errors.New(fmt.Sprintf("no reachable mongodb server(s) at %s", conf.Conf["mongodb-hosts"]))
		return e
	}
	c.Session = s
	c.DB = c.Session.DB(conf.Conf["mongodb-database"])
	if conf.Conf["mongodb-user"] != "" && conf.Conf["mongodb-password"] != "" {
		c.DB.Login(conf.Conf["mongodb-user"], conf.Conf["mongodb-password"])
	}
	Connection = c
	return
}
Esempio n. 3
0
// Connect to mongodb
func TestConnect(host_info HostInfo, chan_host_info chan HostInfo) {
	host := host_info.Host
	port := host_info.Port
	is_weak := host_info.Is_weak
	url := fmt.Sprintf("%s:%s", host, port)
	session, err := mgo.DialWithTimeout(url, 2*time.Second)
	if err == nil {
		dbs, err := session.DatabaseNames()
		if err == nil {
			is_weak = true
			host_info.Dbs = dbs
		}
	}
	host_info.Is_weak = is_weak
	chan_host_info <- host_info
}