Created
July 16, 2022 02:06
-
-
Save hernanhrm/6450b76b4db87b9f442cee153696819a to your computer and use it in GitHub Desktop.
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
// 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