コード例 #1
0
ファイル: mongo.go プロジェクト: xxoommd/SimpleAccountSystem
// 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)
}
コード例 #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)
	}
}
コード例 #3
0
ファイル: user.go プロジェクト: xxoommd/SimpleAccountSystem
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()
	}
}