Exemplo n.º 1
0
func New() (*ZooKeeper, error) {
	c, err := container.Find(containerName)
	if err != nil {
		c, err = container.New("--name="+containerName, "--detach=true", "--publish-all=true", "h12w/zookeeper:latest")
		if err != nil {
			return nil, err
		}
	}
	return &ZooKeeper{
		c: c,
	}, nil
}
Exemplo n.º 2
0
func New() (*Mongo, error) {
	c, err := container.Find(containerName)
	if err != nil {
		c, err = container.New("--name="+containerName, "--detach=true", "--publish-all=true", "mongo:latest")
		if err != nil {
			return nil, err
		}
	}
	connStr := "mongodb://" + c.Addr(internalPort)
	session, err := mgo.Dial(connStr)
	if err != nil {
		c.Close()
		return nil, err
	}
	dbName := "db_" + strconv.Itoa(rand.Int())
	db := session.DB(dbName)
	return &Mongo{
		DBName:   dbName,
		ConnStr:  connStr,
		Session:  session,
		Database: db,
		c:        c,
	}, nil
}