-
Notifications
You must be signed in to change notification settings - Fork 2
/
managed_session.go
49 lines (39 loc) · 1.19 KB
/
managed_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
46
47
48
49
package gocql
import (
"context"
"github.com/gocql/gocql"
)
// ManagedSession represents a gocqsl managed session
type ManagedSession struct {
Session *gocql.Session
Plugins []Plugin
Options *Options
}
// NewManagedSessionWithConfigPath returns a ManagedSession with options from config path.
func NewManagedSessionWithConfigPath(ctx context.Context, path string, plugins ...Plugin) (*ManagedSession, error) {
opts, err := NewOptionsWithPath(path)
if err != nil {
return nil, err
}
return NewManagedSessionWithOptions(ctx, opts, plugins...)
}
// NewManagedSession returns a ManagedSession with default options.
func NewManagedSession(ctx context.Context, plugins ...Plugin) (*ManagedSession, error) {
opts, err := NewOptions()
if err != nil {
return nil, err
}
return NewManagedSessionWithOptions(ctx, opts, plugins...)
}
// NewManagedSessionWithOptions returns a ManagedSession with options.
func NewManagedSessionWithOptions(ctx context.Context, opts *Options, plugins ...Plugin) (*ManagedSession, error) {
s, err := NewSessionWithOptions(ctx, opts, plugins...)
if err != nil {
return nil, err
}
return &ManagedSession{
Session: s,
Plugins: plugins,
Options: opts,
}, nil
}