1

I get this error trying to compile:

package main
import "fmt"
import "log"
import "github.com/gocql/gocql"
var (
    name, sex string
    age int
)
func main() {
    // connect to the cluster
    cluster := gocql.NewCluster("127.0.0.1")
    cluster.Keyspace = "dbaccess"
    session, _ := cluster.CreateSession()
    defer session.Close()
    cluster.ProtoVersion = 4
    if err := session.Query("SELECT name, age FROM people WHERE name='doug'").Scan(&name, &age); 
    err != nil {
        log.Fatal(err)
    }
    fmt.Println(name, age)
}

I added the line

cluster.ProtoVersion = 4

After reading about it here but I'm too new to understand if that's my issue, or I did something wrong elsewhere. Do I have to wait for an update to gocql that fixes this, or what should I do?

batflaps
  • 261
  • 3
  • 12
  • 1
    Just a wild guess, look likes protocol version mismatch, what is your Cassandra version ? – doanduyhai Jan 18 '16 at 06:35
  • 3.1.1. I just switched this line `cluster.ProtoVersion = 3` as a test to reflect 3.x, but now it says `no response received from cassandra within timeout period` – batflaps Jan 18 '16 at 19:34
  • Starting from Cassandra 3.x.x, the protocol version should be 4 normally. If you're having issue with the go driver using protocol v4, raise an issue at their github. I'm using the Java driver and it works with protocol v4 – doanduyhai Jan 18 '16 at 20:24

1 Answers1

3

Okay, I sorted out with @Zariel on the github issue #538 thread. You have to put the ProtoVersion = 4 up by the first gocql stuff like:

package main
import "fmt"
import "log"
import "github.com/gocql/gocql"

var (
    name, sex, age string
)

func main() {
    // connect to the cluster
    cluster := gocql.NewCluster("127.0.0.1")
    cluster.ProtoVersion = 4
    cluster.Keyspace = "dbaccess"
    session, _ := cluster.CreateSession()
    defer session.Close()

    if err := session.Query("SELECT name, age FROM people WHERE name='doug'").Scan(&name, &age); 
    err != nil {
        log.Fatal(err)
    }
    fmt.Println(name, age)
}

Hope that helps someone else :)

batflaps
  • 261
  • 3
  • 12