Пример #1
0
// New db adaptor
func NewAdaptor(urls []string, username, password string) *Adaptor {
	cluster := gocql.NewCluster(urls...)
	cluster.Keyspace = "events"
	cluster.ProtoVersion = 3

	// cluster.Authenticator = gocql.PasswordAuthenticator{
	// 	Username: username,
	// 	Password: password,
	// }

	session, err := cluster.CreateSession()
	if err != nil {
		log.Fatalf("Cassandra conn error: %s", err.Error())
	}
	qe := gocassa.GoCQLSessionToQueryExecutor(session)
	conn := gocassa.NewConnection(qe)
	gocassaSession := conn.KeySpace("events")

	return &Adaptor{
		Session:            gocassaSession,
		urls:               urls,
		eventTimeDateRange: 7 * 24 * time.Hour,
		Username:           username,
		Password:           password,
	}
}
Пример #2
0
func (a *Adaptor) ReestablishConnection() {
	log.Println("Reestablishing cql connection")
	cluster := gocql.NewCluster(a.urls[0])
	cluster.ProtoVersion = 3
	cluster.Authenticator = gocql.PasswordAuthenticator{
		Username: a.Username,
		Password: a.Password,
	}
	session, err := cluster.CreateSession()
	if err != nil {
		log.Fatalf("Cassandra conn error: %s", err.Error())
	}
	qe := gocassa.GoCQLSessionToQueryExecutor(session)
	a.Session = gocassa.NewConnection(qe).KeySpace("events")
}