Ejemplo n.º 1
0
func Setup() {
	var err error
	cfg := config.Read()

	connectionString := cfg.DB.ConnectionString
	if cfg.DB.Type == "sqlite3" {
		connectionString = config.ConfigFile(connectionString)
		log.Println("Using SQLite DB at", connectionString)
	}
	for {
		db, err = gorm.Open(cfg.DB.Type, connectionString)

		if err == nil {
			break
		} else {
			log.Println("Cannot connect to DB. Will try again in 2 seconds:", err)
			time.Sleep(time.Duration(2) * time.Second)
		}
	}

	db.AutoMigrate(
		&User{},
		&CredRecord{},
		&Peer{},
		&SentMessage{},
	)

	db.Model(&CredRecord{}).AddUniqueIndex("idx_cred_hash", "cred_hash")
	db.Model(&CredRecord{}).AddIndex("idx_statement_hash", "statement_hash")
	db.Model(&SentMessage{}).AddUniqueIndex("idx_message_hash", "message_hash")
	db.Model(&User{}).AddUniqueIndex("idx_fingerprint", "fingerprint")
}
Ejemplo n.º 2
0
func PemPath() string {
	return config.ConfigFile("id_rsa")
}