Skip to content

Commit

Permalink
use a single S3 client
Browse files Browse the repository at this point in the history
that came from karaberus and was found to cause issues there, so I'm
porting it here too.
  • Loading branch information
odrling committed Jul 31, 2024
1 parent 2acc441 commit d0525dd
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions server/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ import (
"github.com/minio/minio-go/v7/pkg/credentials"
)

var S3_CLIENT *minio.Client = nil

func getS3Client() (*minio.Client, error) {
client, err := minio.New(CONFIG.S3.Endpoint, &minio.Options{
Creds: credentials.NewStaticV4(CONFIG.S3.KeyID, CONFIG.S3.Secret, ""),
Secure: CONFIG.S3.Secure,
})
return client, err
var err error = nil
if S3_CLIENT == nil {
S3_CLIENT, err = minio.New(CONFIG.S3.Endpoint, &minio.Options{
Creds: credentials.NewStaticV4(CONFIG.S3.KeyID, CONFIG.S3.Secret, ""),
Secure: CONFIG.S3.Secure,
})
}
return S3_CLIENT, err
}

func UploadToS3(ctx context.Context, file io.Reader, file_id string, filename string, filesize int64, content_type string, expires time.Time) error {
Expand Down

0 comments on commit d0525dd

Please sign in to comment.