Skip to content

Commit

Permalink
setting up localstack endpoints for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
fullerzz committed Jun 16, 2024
1 parent 2d20105 commit 49d7fa9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
12 changes: 11 additions & 1 deletion aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,17 @@ func createClientConnections() {
}

func setupS3(cfg aws.Config) {
client := s3.NewFromConfig(cfg)
var client *s3.Client
if conf.AwsEndpoint == "DEFAULT" {
slog.Info("Using default S3 endpoint")
client = s3.NewFromConfig(cfg)
} else {
slog.Info("Using localstack S3 endpoint")
client = s3.NewFromConfig(cfg, func(o *s3.Options) {
o.BaseEndpoint = &conf.AwsEndpoint
o.Region = conf.AwsRegion
})
}
bucket := os.Getenv("S3_BUCKET")
s3Bucket := &S3FilesBucket{S3Client: client, BucketName: bucket}
filesBucket = *s3Bucket
Expand Down
4 changes: 3 additions & 1 deletion conf.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"filePrefix": "./uploads/"
"filePrefix": "./uploads/",
"awsEndpoint": "http://127.0.0.1:4566",
"awsRegion": "us-west-1"
}
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ type FileUpload struct {
}

type Configuration struct {
FilePrefix string
FilePrefix string
AwsEndpoint string
AwsRegion string
}

var conf Configuration
Expand All @@ -39,6 +41,7 @@ func loadConfig(confFileName string) {
if err != nil {
panic(err)
}
slog.Info("Configuration loaded", "config", conf)
}

// e.POST("/file/upload", saveFile)
Expand Down

0 comments on commit 49d7fa9

Please sign in to comment.