-
-
Notifications
You must be signed in to change notification settings - Fork 201
/
client.go
32 lines (29 loc) · 822 Bytes
/
client.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
package awsclient
import (
"github.com/admpub/nging/v4/application/dbschema"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
)
func Connect(m *dbschema.NgingCloudStorage) (client *s3.S3, err error) {
var sess *session.Session
sess, err = NewSession(m)
if err != nil {
return
}
client = s3.New(sess)
return client, nil
}
func NewSession(m *dbschema.NgingCloudStorage) (*session.Session, error) {
isSecure := m.Secure == `Y`
config := &aws.Config{
DisableSSL: aws.Bool(!isSecure),
Endpoint: aws.String(m.Endpoint),
Credentials: credentials.NewStaticCredentials(m.Key, m.Secret, ""),
}
if len(m.Region) > 0 {
config.Region = aws.String(m.Region)
}
return session.NewSession(config)
}