Esempio n. 1
0
// Init method
func init() {
	logger.Info("Connecting MongoDB: %s...", conf.Config.MongoURL)
	dbSession, err := mgo.Dial(conf.Config.MongoURL)
	if err != nil {
		logger.Panic("Connect to MongoDB error:", err)
	}
	logger.Info("Connecting MongoDB success")

	Database = dbSession.DB(conf.Config.DBName)
}
Esempio n. 2
0
func init() {
	counterColl = db.Database.C(counterCollName)
	if err := counterColl.Find(bson.M{}).One(&Counter); err != nil {
		logger.Info("Counter not found, create one...")
		Counter = make(map[string]int64)
		counterColl.Insert(Counter)
	}
}
Esempio n. 3
0
func init() {
	userColl = db.Database.C(userCollName)
	userColl.EnsureIndex(mgo.Index{
		Key:    []string{"_id", "name"},
		Unique: true,
		Sparse: true,
	})

	admin := FindUserByName("admin")
	if admin == nil {
		logger.Info("Creating admin user...")
		admin = &User{Name: "admin", Password: "******", PasswordChanged: true, IsValid: true}
		admin.Save()
	}
}