Skip to content

Commit

Permalink
Merge pull request #4 from mojura/use-rate-limiting
Browse files Browse the repository at this point in the history
use semaphore
  • Loading branch information
itsmontoya authored Aug 12, 2024
2 parents 9b2ffc9 + 6595bc2 commit 278114b
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type S3 struct {
}

func (s *S3) Export(ctx context.Context, prefix, filename string, r io.Reader) (newFilename string, err error) {
s.sema.Use()
rs, ok := r.(io.ReadSeeker)
if !ok {
rs = aws.ReadSeekCloser(r)
Expand All @@ -76,6 +77,7 @@ func (s *S3) Export(ctx context.Context, prefix, filename string, r io.Reader) (
}

func (s *S3) Import(ctx context.Context, prefix, filename string, w io.Writer) (err error) {
s.sema.Use()
filepath := path.Join(prefix, filename)
getInput := s3.GetObjectInput{
Bucket: aws.String(s.o.Bucket),
Expand All @@ -93,6 +95,7 @@ func (s *S3) Import(ctx context.Context, prefix, filename string, w io.Writer) (
}

func (s *S3) Get(ctx context.Context, prefix, filename string, fn func(r io.Reader) error) (err error) {
s.sema.Use()
var out *s3.GetObjectOutput
filepath := path.Join(prefix, filename)
input := newGetInputObject(s.o.Bucket, filepath)
Expand All @@ -105,6 +108,7 @@ func (s *S3) Get(ctx context.Context, prefix, filename string, fn func(r io.Read
}

func (s *S3) GetNext(ctx context.Context, prefix, lastFilename string) (nextKey string, err error) {
s.sema.Use()
startAfter := path.Join(prefix, lastFilename)
input := s3.ListObjectsV2Input{
Bucket: aws.String(s.o.Bucket),
Expand Down

0 comments on commit 278114b

Please sign in to comment.