Domanda

I have the following gocql connection.

 //cassandra connection
  cluster := gocql.NewCluster("localhost")
  cluster.Keyspace = "demo"
  cluster.DefaultPort = 9042
  cluster.Consistency = gocql.Quorum
  session, _ = cluster.CreateSession()
  defer session.Close()

I want to put this inside a golang function and return the session variable,but I don't know its datatype. I tried returning *Session but it gives me an error. Any idea how to do this.

È stato utile?

Soluzione

Per the documentation (http://godoc.org/github.com/gocql/gocql#ClusterConfig.CreateSession) the type is *gocql.Session. I would note, however, that if you defer the session.Close() call, it will run as soon as you return, meaning you will never return a valid connection. You will have to close the session in the calling function.

Altri suggerimenti

cluster.CreateSession() returns *gocql.Session, error

Maybe if you could share your actual code and tell us what error you are getting, this question would be easier to answer.

BTW there is a mailing list for more involved questions, as well as the issue tracker on Github.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top