-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
52 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters