-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsession.go
More file actions
47 lines (39 loc) · 1.13 KB
/
Copy pathsession.go
File metadata and controls
47 lines (39 loc) · 1.13 KB
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
46
47
package main
import (
"time"
log "github.com/Sirupsen/logrus"
"github.com/gocql/gocql"
)
func (config *Config) session() *gocql.Session {
cluster := gocql.NewCluster(config.Seeds...)
if config.CertPath != "" {
log.Debugf("using SSL with certificate '%s' and key '%s'", config.CertPath, config.KeyPath)
cluster.SslOpts = &gocql.SslOptions{
CertPath: expandHome(config.CertPath),
KeyPath: expandHome(config.KeyPath),
EnableHostVerification: false,
}
}
if config.Username != "" {
log.Debugf("using authentication with username '%s'", config.Username)
cluster.Authenticator = gocql.PasswordAuthenticator{
Username: config.Username,
Password: config.Password,
}
}
if config.Timeout > 0 {
cluster.Timeout = time.Second * time.Duration(config.Timeout)
log.Debugf("setting cluster timeout to %v", cluster.Timeout)
}
if config.Retries > 0 {
log.Debugf("setting cluster retry number to %d", config.Retries)
cluster.RetryPolicy = &gocql.SimpleRetryPolicy{
NumRetries: config.Retries,
}
}
session, err := cluster.CreateSession()
if err != nil {
log.Fatal(err)
}
return session
}