From 198349f68365246bb4c44762bd3c8b0f811533f2 Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Thu, 2 Sep 2021 06:40:02 -0700 Subject: [PATCH] Add comments and clean up code --- tools/upload.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/upload.go b/tools/upload.go index 193148c..50dbbbf 100644 --- a/tools/upload.go +++ b/tools/upload.go @@ -46,9 +46,10 @@ func main() { log.Fatal(err) } - // Create an Amazon S3 service client client := s3.NewFromConfig(cfg) + // The whole contents of the public/ directory are uploaded. This code assumes + // the directory structure is flat - there are no subdirectories. publicDir := "./public/" c, err := os.ReadDir(publicDir) if err != nil { @@ -66,14 +67,14 @@ func main() { contentType := guessContentType(entry.Name()) log.Printf("Uploading %s (%s)", entry.Name(), contentType) - input := &s3.PutObjectInput{ + cfg := &s3.PutObjectInput{ Bucket: bucket, Key: aws.String(entry.Name()), Body: file, ContentType: aws.String(contentType), } - _, err = client.PutObject(context.TODO(), input) + _, err = client.PutObject(context.TODO(), cfg) if err != nil { log.Fatal(err) }