-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcdn.go
32 lines (29 loc) · 866 Bytes
/
cdn.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 utils
import (
"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"
)
// CDNConfig represents a configuration to connect to a CDN / S3 instance
type CDNConfig struct {
Endpoint string
Region string
AccessKeyID string
SecretAccessKey string
}
// NewCDN Initialise connection to CDN
func NewCDN(config CDNConfig) (*s3.S3, error) {
s3Config := &aws.Config{
Credentials: credentials.NewStaticCredentials(config.AccessKeyID, config.SecretAccessKey, ""),
Endpoint: aws.String(config.Endpoint),
Region: aws.String(config.Region),
S3ForcePathStyle: aws.Bool(true),
}
newSession, err := session.NewSession(s3Config)
if err != nil {
return nil, err
}
cdn := s3.New(newSession)
return cdn, nil
}