-
Notifications
You must be signed in to change notification settings - Fork 5
/
options.go
115 lines (100 loc) · 2.7 KB
/
options.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Copyright 2017 Matt Ho
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package dynastore
import (
"fmt"
"io"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/gorilla/securecookie"
"github.com/gorilla/sessions"
)
// Option provides options to creating a dynastore
type Option func(*Store)
// Codecs uses the specified codecs to encrypt the cookie data
func Codecs(codecs ...securecookie.Codec) Option {
return func(s *Store) {
s.codecs = codecs
}
}
// AWSConfig allows the complete AWS configuration to be specified
func AWSConfig(config *aws.Config) Option {
return func(s *Store) {
s.config = config
}
}
// DynamoDB allows a pre-configured dynamodb client to be supplied
func DynamoDB(ddb *dynamodb.DynamoDB) Option {
return func(s *Store) {
s.ddb = ddb
}
}
// TableName allows a custom table name to be specified
func TableName(tableName string) Option {
return func(s *Store) {
s.tableName = tableName
s.ttlField = "ttl"
}
}
// SessionOptions allows the default session options to be specified in a single command
func SessionOptions(options sessions.Options) Option {
return func(s *Store) {
s.options = options
}
}
// Path sets the default session option of the same name
func Path(v string) Option {
return func(s *Store) {
s.options.Path = v
}
}
// Domain sets the default session option of the same name
func Domain(v string) Option {
return func(s *Store) {
s.options.Domain = v
}
}
// Output
func Output(w io.Writer) Option {
return func(s *Store) {
s.printf = func(format string, args ...interface{}) {
fmt.Fprintf(w, format, args...)
}
}
}
// MaxAge sets the default session option of the same name
func MaxAge(v int) Option {
return func(s *Store) {
s.options.MaxAge = v
}
}
// Secure sets the default session option of the same name
func Secure() Option {
return func(s *Store) {
s.options.Secure = true
}
}
// HTTPOnly sets the default session option HttpOnly; HTTP is all capped to satisfy golint
func HTTPOnly() Option {
return func(s *Store) {
s.options.HttpOnly = true
}
}
// TTLField sets the field used to store the ttl value
func TTLField(ttlField string) Option {
return func(s *Store) {
s.ttlField = ttlField
}
}