-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathconfig.go
48 lines (44 loc) · 1.17 KB
/
config.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
package dynamo
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
)
// Config dynamodb configuration parameters
type Config struct {
SESSION *session.Session
TABLE *TableConfig
ENDPOINT string
}
type TableConfig struct {
BasicCname string
AccessCName string
RefreshCName string
}
// NewConfig create dynamodb configuration
func NewConfig(region string, endpoint string, access_key string, secret string, basic_table_name string, access_table_name string, refresh_table_name string) (config *Config, err error) {
awsConfig := aws.NewConfig()
if len(region) > 0 {
awsConfig.Region = aws.String(region)
}
if len(access_key) > 0 && len(secret) > 0 {
awsConfig.Credentials = credentials.NewStaticCredentials(access_key, secret, "")
}
if len(endpoint) > 0 {
awsConfig.Endpoint = aws.String(endpoint)
}
newSession, err := session.NewSession(awsConfig)
if err != nil {
return
}
config = &Config{
SESSION: newSession,
TABLE: &TableConfig{
BasicCname: basic_table_name,
AccessCName: access_table_name,
RefreshCName: refresh_table_name,
},
ENDPOINT: endpoint,
}
return
}