// Init initializes the db connection and waits for a basic check to complete.
Init initializes the db connection and waits for a basic check to complete.
// Init initializes the db connection and waits for a basic check to complete .
func (ds *DataStore) Init() {
	getEnv := func(key, fallback string) string {
		if value, ok := os.LookupEnv(key); ok {
			return value
		}
		return fallback
	}
	dbUserName := getEnv("POSTGRES_USER", "console")
	dbName := getEnv("POSTGRES_DB", "console")
	dbHostName := getEnv("POSTGRES_HOST", "integtest_condat-postgres_1") 
	dbPort := getEnv("POSTGRES_PORT", "5432")
	dbPasswd := getEnv("POSTGRES_PASSWD", "console")
	connStr := fmt.Sprintf("sslmode=disable user=%s dbname=%s host=%s port=%s", dbUserName, dbName,
		dbHostName, dbPort)
	log.Printf("Attempt to open DB conn as: %s", connStr)
	connStr += " password=" + dbPasswd
	log.Printf(connStr)
	var err error
	ds.DB, err = sql.Open("postgres", connStr)
	if err != nil {
		log.Panicf("Unable to open DB connection: %s", err)
	}
	log.Printf("Opened DB conn")
	for err := ds.CheckConn(); err != nil; err = ds.CheckConn() {
		log.Printf("Waiting on db connection")
		time.Sleep(2 * time.Second)
	}
	log.Printf("db connected")
}
func ( ds * DataStore ) Init ( ) { getEnv := func ( key , fallback string ) string { if value , ok := os . LookupEnv ( key ) ; ok { return value } return fallback } dbUserName := getEnv ( " " , " " ) dbName := getEnv ( " " , " " ) dbHostName := getEnv ( " " , " " ) dbPort := getEnv ( " " , " " ) dbPasswd := getEnv ( " " , " " ) connStr := fmt . Sprintf ( " " , dbUserName , dbName , dbHostName , dbPort ) log . Printf ( " " , connStr ) connStr += " " + dbPasswd log . Printf ( connStr ) var err error ds . DB , err = sql . Open ( " " , connStr ) if err != nil { log . Panicf ( " " , err ) } log . Printf ( " " ) for err := ds . CheckConn ( ) ; err != nil ; err = ds . CheckConn ( ) { log . Printf ( " " ) time . Sleep ( 2 * time . Second ) } log . Printf ( " " ) }
Init initializes the db connection and waits for a basic check to complete.
Init initializes the db connection and waits for a basic check to complete .
// Get environment var with default. // Rely on these hardcoded values for now until they can get properly plumbed // into the compose environment. // POSTGRES_HOST // Try an operation