// Init ... func (rthink *RethinkDBImpl) Init(conntype string, dbhost string, username string, password string, port int, dbname string, log log.Logger, hosts ...string) error { var retErr error if conntype == "cluster" { session, err := r.Connect(r.ConnectOpts{ Addresses: hosts, Database: dbname, AuthKey: password, }) retErr = err if err != nil { log.Crit("Got error when connect database, the error is '%v'", err) return retErr } rthink.Session = session } else { session, err := r.Connect(r.ConnectOpts{ Address: dbhost, Database: dbname, AuthKey: password, }) retErr = err if err != nil { log.Crit("Got error when connect database, the error is '%v'", err) return retErr } rthink.Session = session } fmt.Println("Rethink Connected") return nil }
// Init ... func (rdbms *RDBMSImpl) Init(dbtype string, dbhost string, username string, password string, port int, dbname string, log log.Logger) error { var err error connString := fmt.Sprintf("user=%s port=%d password=%s dbname=%s sslmode=disable", username, port, password, dbname) rdbms.DB, err = gorm.Open(dbtype, connString) if err != nil { log.Crit("Got error when connect database, the error is '%v'", err) return err } rdbms.DB.LogMode(true) fmt.Println("Connected") return nil }
// InitDataStore ... func (datastore *DataStore) InitDataStore(storeType string, connDetails map[string]interface{}, log log.Logger) error { var err error datastore.StoreType = storeType if storeType == "rdbms" { rdbms := RDBMSImpl{} err = rdbms.Init(connDetails["dbtype"].(string), connDetails["host"].(string), connDetails["username"].(string), connDetails["password"].(string), int(connDetails["port"].(float64)), connDetails["database"].(string), log) if err != nil { log.Crit("Got error when connect database, the error is '%v'", err) } datastore.RDBMS = rdbms } return err }