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.
Returning gocql's session variable from function
문제
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.
해결책
다른 팁
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.
제휴하지 않습니다 StackOverflow