Skip to content

Instantly share code, notes, and snippets.

@hernanhrm
Created July 16, 2022 02:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hernanhrm/6450b76b4db87b9f442cee153696819a to your computer and use it in GitHub Desktop.
Save hernanhrm/6450b76b4db87b9f442cee153696819a to your computer and use it in GitHub Desktop.
// Config contains the configuration read from the .env file
type Config struct {
S3AccessKey string `json:"s3_access_key"`
S3SecretKey string `json:"s3_secret_key"`
S3BucketName string `json:"s3_bucket_name"`
S3BucketRegion string `json:"s3_bucket_region"`
}
// Service is the use case of the storage s3 service
type Service struct {
Bucket string
S3 *s3.S3
Signer *v4.Signer
}
// NewS3Service returns a new s3 service
func NewS3Service(conf Config) (Service, error) {
awsSession := session.Must(session.NewSession(&aws.Config{
Region: aws.String(conf.S3BucketRegion),
Credentials: credentials.NewStaticCredentials(conf.S3AccessKey, conf.S3SecretKey, ""),
}))
return Service{
Bucket: conf.S3BucketName,
S3: s3.New(awsSession),
Signer: v4.NewSigner(awsSession.Config.Credentials),
}, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment