mirror of
https://github.com/gofiber/storage.git
synced 2025-09-27 12:52:25 +08:00
Compare commits
3 Commits
coherence/
...
cloudflare
Author | SHA1 | Date | |
---|---|---|---|
![]() |
40a6167b74 | ||
![]() |
e4d46ce66c | ||
![]() |
386b6f431f |
@@ -44,7 +44,9 @@ func New(config Config) *Storage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create db
|
// Create db
|
||||||
sess := awsdynamodb.NewFromConfig(awscfg)
|
sess := awsdynamodb.NewFromConfig(awscfg, func(o *awsdynamodb.Options) {
|
||||||
|
o.BaseEndpoint = aws.String(cfg.Endpoint)
|
||||||
|
})
|
||||||
|
|
||||||
timeoutCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
timeoutCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
@@ -232,23 +234,10 @@ func (s *Storage) requestContext() (context.Context, context.CancelFunc) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func returnAWSConfig(cfg Config) (aws.Config, error) {
|
func returnAWSConfig(cfg Config) (aws.Config, error) {
|
||||||
endpoint := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) {
|
|
||||||
if cfg.Endpoint != "" {
|
|
||||||
return aws.Endpoint{
|
|
||||||
PartitionID: "aws",
|
|
||||||
URL: cfg.Endpoint,
|
|
||||||
SigningRegion: cfg.Region,
|
|
||||||
HostnameImmutable: true,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
return aws.Endpoint{}, &aws.EndpointNotFoundError{}
|
|
||||||
})
|
|
||||||
|
|
||||||
if cfg.Credentials != (Credentials{}) {
|
if cfg.Credentials != (Credentials{}) {
|
||||||
credentials := credentials.NewStaticCredentialsProvider(cfg.Credentials.AccessKey, cfg.Credentials.SecretAccessKey, "")
|
credentials := credentials.NewStaticCredentialsProvider(cfg.Credentials.AccessKey, cfg.Credentials.SecretAccessKey, "")
|
||||||
return awsconfig.LoadDefaultConfig(context.TODO(),
|
return awsconfig.LoadDefaultConfig(context.TODO(),
|
||||||
awsconfig.WithRegion(cfg.Region),
|
awsconfig.WithRegion(cfg.Region),
|
||||||
awsconfig.WithEndpointResolverWithOptions(endpoint),
|
|
||||||
awsconfig.WithCredentialsProvider(credentials),
|
awsconfig.WithCredentialsProvider(credentials),
|
||||||
awsconfig.WithRetryer(func() aws.Retryer {
|
awsconfig.WithRetryer(func() aws.Retryer {
|
||||||
return retry.AddWithMaxAttempts(retry.NewStandard(), cfg.MaxAttempts)
|
return retry.AddWithMaxAttempts(retry.NewStandard(), cfg.MaxAttempts)
|
||||||
@@ -258,7 +247,6 @@ func returnAWSConfig(cfg Config) (aws.Config, error) {
|
|||||||
|
|
||||||
return awsconfig.LoadDefaultConfig(context.TODO(),
|
return awsconfig.LoadDefaultConfig(context.TODO(),
|
||||||
awsconfig.WithRegion(cfg.Region),
|
awsconfig.WithRegion(cfg.Region),
|
||||||
awsconfig.WithEndpointResolverWithOptions(endpoint),
|
|
||||||
awsconfig.WithRetryer(func() aws.Retryer {
|
awsconfig.WithRetryer(func() aws.Retryer {
|
||||||
return retry.AddWithMaxAttempts(retry.NewStandard(), cfg.MaxAttempts)
|
return retry.AddWithMaxAttempts(retry.NewStandard(), cfg.MaxAttempts)
|
||||||
}),
|
}),
|
||||||
|
19
s3/s3.go
19
s3/s3.go
@@ -40,7 +40,10 @@ func New(config ...Config) *Storage {
|
|||||||
panic(fmt.Sprintf("unable to load SDK config, %v", err))
|
panic(fmt.Sprintf("unable to load SDK config, %v", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
sess := s3.NewFromConfig(awscfg)
|
sess := s3.NewFromConfig(awscfg, func(o *s3.Options) {
|
||||||
|
o.BaseEndpoint = aws.String(cfg.Endpoint)
|
||||||
|
})
|
||||||
|
|
||||||
storage := &Storage{
|
storage := &Storage{
|
||||||
svc: sess,
|
svc: sess,
|
||||||
downloader: manager.NewDownloader(sess),
|
downloader: manager.NewDownloader(sess),
|
||||||
@@ -173,23 +176,10 @@ func (s *Storage) requestContext() (context.Context, context.CancelFunc) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func returnAWSConfig(cfg Config) (aws.Config, error) {
|
func returnAWSConfig(cfg Config) (aws.Config, error) {
|
||||||
endpoint := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) {
|
|
||||||
if cfg.Endpoint != "" {
|
|
||||||
return aws.Endpoint{
|
|
||||||
PartitionID: "aws",
|
|
||||||
URL: cfg.Endpoint,
|
|
||||||
SigningRegion: cfg.Region,
|
|
||||||
HostnameImmutable: true,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
return aws.Endpoint{}, &aws.EndpointNotFoundError{}
|
|
||||||
})
|
|
||||||
|
|
||||||
if cfg.Credentials != (Credentials{}) {
|
if cfg.Credentials != (Credentials{}) {
|
||||||
creds := credentials.NewStaticCredentialsProvider(cfg.Credentials.AccessKey, cfg.Credentials.SecretAccessKey, "")
|
creds := credentials.NewStaticCredentialsProvider(cfg.Credentials.AccessKey, cfg.Credentials.SecretAccessKey, "")
|
||||||
return awsconfig.LoadDefaultConfig(context.TODO(),
|
return awsconfig.LoadDefaultConfig(context.TODO(),
|
||||||
awsconfig.WithRegion(cfg.Region),
|
awsconfig.WithRegion(cfg.Region),
|
||||||
awsconfig.WithEndpointResolverWithOptions(endpoint),
|
|
||||||
awsconfig.WithCredentialsProvider(creds),
|
awsconfig.WithCredentialsProvider(creds),
|
||||||
awsconfig.WithRetryer(func() aws.Retryer {
|
awsconfig.WithRetryer(func() aws.Retryer {
|
||||||
return retry.AddWithMaxAttempts(retry.NewStandard(), cfg.MaxAttempts)
|
return retry.AddWithMaxAttempts(retry.NewStandard(), cfg.MaxAttempts)
|
||||||
@@ -199,7 +189,6 @@ func returnAWSConfig(cfg Config) (aws.Config, error) {
|
|||||||
|
|
||||||
return awsconfig.LoadDefaultConfig(context.TODO(),
|
return awsconfig.LoadDefaultConfig(context.TODO(),
|
||||||
awsconfig.WithRegion(cfg.Region),
|
awsconfig.WithRegion(cfg.Region),
|
||||||
awsconfig.WithEndpointResolverWithOptions(endpoint),
|
|
||||||
awsconfig.WithRetryer(func() aws.Retryer {
|
awsconfig.WithRetryer(func() aws.Retryer {
|
||||||
return retry.AddWithMaxAttempts(retry.NewStandard(), cfg.MaxAttempts)
|
return retry.AddWithMaxAttempts(retry.NewStandard(), cfg.MaxAttempts)
|
||||||
}),
|
}),
|
||||||
|
Reference in New Issue
Block a user