Esempio n. 1
0
func EmailValidation(email string) bool {
	exp, err := regexp.Compile(EMAIL_REGEX)
	if regexpCompiled := log.CheckError(err); regexpCompiled {
		if exp.MatchString(email) {
			return true
		}
	}
	return false
}
Esempio n. 2
0
File: gorm.go Progetto: tka/goyangi
// GormInit init gorm ORM.
func GormInit() (gorm.DB, error) {
	db, err := gorm.Open("mysql", config.MysqlDSL())
	//db, err := gorm.Open("sqlite3", "/tmp/gorm.db")

	// Get database connection handle [*sql.DB](http://golang.org/pkg/database/sql/#DB)
	db.DB()

	// Then you could invoke `*sql.DB`'s functions with it
	db.DB().Ping()
	db.DB().SetMaxIdleConns(10)
	db.DB().SetMaxOpenConns(100)

	// Disable table name's pluralization
	db.SingularTable(true)
	if config.Environment == "DEVELOPMENT" {
		// db.LogMode(true)
		db.AutoMigrate(&model.User{}, &model.Role{}, &model.Connection{}, &model.Language{}, &model.Article{}, &model.Location{}, &model.Comment{}, &model.File{})
		db.Model(&model.User{}).AddIndex("idx_user_token", "token")
	}
	log.CheckError(err)

	return db, err
}