♻️ Refactor get s3 client process

This commit is contained in:
2025-03-24 22:48:43 +08:00
parent 9360d17706
commit 1390f26afa
5 changed files with 22 additions and 30 deletions

View File

@ -1,5 +1,11 @@
package models
import (
pkg "git.solsynth.dev/hypernet/paperclip/pkg/internal"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
)
const (
DestinationTypeLocal = "local"
DestinationTypeS3 = "s3"
@ -33,3 +39,15 @@ type S3Destination struct {
EnableSigned bool `json:"enable_signed"`
BucketLookup int `json:"bucket_lookup"`
}
func (v S3Destination) GetClient() (*minio.Client, error) {
client, err := minio.New(v.Endpoint, &minio.Options{
Creds: credentials.NewStaticV4(v.SecretID, v.SecretKey, ""),
Secure: v.EnableSSL,
BucketLookup: minio.BucketLookupType(v.BucketLookup),
})
if err == nil {
client.SetAppInfo("HyperNet.Paperclip", pkg.AppVersion)
}
return client, err
}