Example #1
0
// NewDb creates a new Db interface to the database.
// addr is the IP address and port, in string form, of the database server.
func NewDb(addr, dbname string) (db *Db, err os.Error) {
	s, err := mgo.Mongo(addr)
	if err != nil {
		log.Printf("Problem connecting to MongoDB: %s", err)
		return nil, err
	}
	db = &Db{
		s:  s,
		kp: NewKPartite(dbname, s),
	}
	// Initialize user system
	if err := db.initUser(); err != nil {
		db.Close()
		return nil, err
	}
	// Initialize like system
	if err := db.initLike(); err != nil {
		db.Close()
		return nil, err
	}
	// Initialize follow/notify  system
	if err := db.initFollow(); err != nil {
		db.Close()
		return nil, err
	}
	// Initialize messaging system
	if err := db.initMsg(); err != nil {
		db.Close()
		return nil, err
	}
	return db, nil
}
Example #2
0
func TestByteSlices(t *testing.T) {
	s, err := mgo.Mongo("localhost:22000")
	if err != nil {
		t.Fatalf("connect: %s", err)
	}
	c := s.DB("tester").C("mgo_test")
	doc := &Doc{[]byte{1, 2, 3, 4}}
	if err = c.Insert(doc); err != nil {
		t.Errorf("insert: %s", err)
	}
}