-
Notifications
You must be signed in to change notification settings - Fork 0
/
gocql_session.go
45 lines (35 loc) · 898 Bytes
/
gocql_session.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package gocassandra
import (
"github.com/gocql/gocql"
"github.com/danteay/go-cassandra/config"
)
func getSession(c config.Config) (*gocql.Session, error) {
cluster := gocql.NewCluster(c.ContactPoints...)
cluster.Keyspace = c.KeyspaceName
cluster.Consistency = gocql.Consistency(c.Consistency)
cluster.ProtoVersion = c.ProtoVersion
if c.Port != 0 {
cluster.Port = c.Port
}
if c.DisableInitialHostLookup {
cluster.DisableInitialHostLookup = c.DisableInitialHostLookup
}
if c.Username != "" && c.Password != "" {
cluster.Authenticator = gocql.PasswordAuthenticator{
Username: c.Username,
Password: c.Password,
}
}
if c.CaPath != "" {
cluster.SslOpts = &gocql.SslOptions{
CaPath: c.CaPath,
}
}
if c.Timeout != 0 {
cluster.Timeout = c.Timeout
}
if c.ConnectTimeout != 0 {
cluster.ConnectTimeout = c.ConnectTimeout
}
return cluster.CreateSession()
}