Skip to content
Snippets Groups Projects
Commit a1a18e92 authored by Johan de Klerk's avatar Johan de Klerk
Browse files

Added GetS3Session

parent efe1cc90
Branches
Tags
No related merge requests found
...@@ -78,10 +78,45 @@ const ( ...@@ -78,10 +78,45 @@ const (
MIMETypeXLSX MIMEType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" MIMETypeXLSX MIMEType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
) )
var (
s3Sessions = map[string]*SessionWithHelpers{}
)
type SessionWithHelpers struct { type SessionWithHelpers struct {
S3Session *s3.S3 S3Session *s3.S3
} }
func GetS3Session(region ...string) *SessionWithHelpers {
s3Region := "af-south-1"
// Set custom region
if region != nil && len(region) > 0 {
s3Region = region[0]
}
// Check if session exists for region, if it does return it
if s3Session, ok := s3Sessions[s3Region]; ok {
return s3Session
}
// Setup session
options := session.Options{
Config: aws.Config{
Region: aws.String(s3Region),
},
}
sess, err := session.NewSessionWithOptions(options)
if err != nil {
return nil
}
s3Session := NewSession(sess)
s3Sessions[s3Region] = s3Session
return s3Session
}
func NewSession(session *session.Session) *SessionWithHelpers { func NewSession(session *session.Session) *SessionWithHelpers {
return &SessionWithHelpers{ return &SessionWithHelpers{
S3Session: s3.New(session), S3Session: s3.New(session),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment