Add support for Cassandra >= 3 with protocol version 4

This commit is contained in:
Alex Barlow 2016-03-19 21:36:47 +00:00
parent 5593c9892b
commit 12c19e08b7
1 changed files with 12 additions and 2 deletions

View File

@ -4,6 +4,7 @@ package cassandra
import (
"fmt"
"net/url"
"strconv"
"strings"
"time"
@ -40,10 +41,10 @@ const (
)
// Cassandra Driver URL format:
// cassandra://host:port/keyspace
// cassandra://host:port/keyspace?protocol=version
//
// Example:
// cassandra://localhost/SpaceOfKeys
// cassandra://localhost/SpaceOfKeys?protocol=4
func (driver *Driver) Initialize(rawurl string) error {
u, err := url.Parse(rawurl)
@ -52,6 +53,15 @@ func (driver *Driver) Initialize(rawurl string) error {
cluster.Consistency = gocql.All
cluster.Timeout = 1 * time.Minute
if len(u.Query().Get("protocol")) > 0 {
protoversion, err := strconv.Atoi(u.Query().Get("protocol"))
if err != nil {
return err
}
cluster.ProtoVersion = protoversion
}
// Check if url user struct is null
if u.User != nil {
password, passwordSet := u.User.Password()