Last active
September 3, 2017 11:29
-
-
Save munisystem/dc04a93f7a7b40a986b7b87c792a2d38 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package s3 | |
import ( | |
"bytes" | |
"fmt" | |
"github.com/aws/aws-sdk-go/aws" | |
"github.com/aws/aws-sdk-go/aws/session" | |
"github.com/aws/aws-sdk-go/service/s3" | |
) | |
type S3 struct { | |
Service *s3.S3 | |
} | |
func NewClient() *S3 { | |
return &S3{ | |
Service: s3.New(session.Must(session.NewSession())), | |
} | |
} | |
func (s *S3) Put(bucket, key string, body []byte) error { | |
input := &s3.PutObjectInput{ | |
Bucket: aws.String(bucket), | |
Key: aws.String(key), | |
Body: bytes.NewReader(body), | |
} | |
if _, err := s.Service.PutObject(input); err != nil { | |
return fmt.Errorf("Faild to add object to S3 (bucket: %s, key: %s): %s", bucket, key, err.Error()) | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment