-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
280cfcb
commit 5671879
Showing
12 changed files
with
701 additions
and
47 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,18 @@ | ||
package backend | ||
|
||
import "github.com/aws/aws-sdk-go-v2/service/s3" | ||
|
||
type Backend interface { | ||
Put(url string, data []byte) error | ||
Get(url string) ([]byte, error) | ||
} | ||
|
||
type S3 struct { | ||
BucketName string `yaml:"bucketName"` | ||
Region string `yaml:"region"` | ||
S3Client *s3.Client `yaml:"-"` | ||
} | ||
|
||
type FileSystem struct { | ||
BaseDir string `yaml:"baseDir"` | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,42 @@ | ||
package backend | ||
|
||
import "fmt" | ||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"io" | ||
|
||
type S3 struct { | ||
BucketName string | ||
} | ||
"github.com/aws/aws-sdk-go-v2/service/s3" | ||
) | ||
|
||
func (s S3) Put(url string, data []byte) error { | ||
fmt.Println(string(data)) | ||
func (b S3) Put(url string, data []byte) error { | ||
_, err := b.S3Client.PutObject(context.TODO(), &s3.PutObjectInput{ | ||
Bucket: &b.BucketName, | ||
Key: &url, | ||
Body: bytes.NewReader(data), | ||
}) | ||
if err != nil { | ||
fmt.Println(err) | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (s S3) Get(url string) ([]byte, error) { | ||
fmt.Printf("Getting %s to S3", s.BucketName) | ||
return nil, nil | ||
func (b S3) Get(url string) ([]byte, error) { | ||
res, err := b.S3Client.GetObject(context.TODO(), &s3.GetObjectInput{ | ||
Bucket: &b.BucketName, | ||
Key: &url, | ||
}) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
defer res.Body.Close() | ||
|
||
body, err := io.ReadAll(res.Body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return body, nil | ||
} |
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
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
Oops, something went wrong.