mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-08-19 05:36:58 +00:00
* fix(tests): keep EC e2e fid cookie arithmetic in uint32 The cookie constants 0x9490CA00 and 0x9500CA00 were added to the int loop variable before conversion, overflowing 32-bit int at compile time on linux/386 and linux/arm. Convert the loop variable instead so the addition stays in uint32. * fix(tests): pass s3client max backoff in milliseconds MaxBackoffDelay is documented as milliseconds and multiplied by 1e6 before use, but the example set it to 5s in nanoseconds, yielding an absurd backoff on 64-bit and a compile-time int overflow on 32-bit. * ci: type-check code and tests for linux/386 64-bit-only constant arithmetic keeps slipping into test files and breaking 32-bit downstream builds. Vet the whole root module under GOOS=linux GOARCH=386 so these fail in CI instead of after release. * fix(tests): convert s3client backoff to Duration before scaling The ms-to-ns multiplication ran in int, wrapping at runtime on 32-bit; scale by time.Millisecond after the Duration conversion instead.
116 lines
2.6 KiB
Go
116 lines
2.6 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/aws/aws-sdk-go-v2/aws"
|
|
"github.com/aws/aws-sdk-go-v2/aws/retry"
|
|
"github.com/aws/aws-sdk-go-v2/config"
|
|
"github.com/aws/aws-sdk-go-v2/credentials"
|
|
"github.com/aws/aws-sdk-go-v2/service/s3"
|
|
)
|
|
|
|
func main() {
|
|
cfg := MyConfig{
|
|
Key: "any",
|
|
Secret: "any",
|
|
Region: "US",
|
|
Endpoint: MyEndpoint{
|
|
URL: "http://localhost:8333",
|
|
},
|
|
Bucket: MyBucketConfig{
|
|
Name: "newbucket",
|
|
Versioning: false,
|
|
},
|
|
MaxBackoffDelay: aws.Int(int((5 * time.Second).Milliseconds())),
|
|
MaxRetryAttempts: aws.Int(1),
|
|
}
|
|
|
|
awsCfg, err := MyAwsConfig(cfg)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
svc := s3.NewFromConfig(*awsCfg, func(o *s3.Options) {
|
|
o.UsePathStyle = true
|
|
})
|
|
|
|
// Use the S3 client to interact with SeaweedFS
|
|
// ...
|
|
// Example: List all buckets
|
|
result, err := svc.ListBuckets(context.Background(), &s3.ListBucketsInput{})
|
|
// no errors - got list of buckets
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
// Print the list of buckets
|
|
for _, bucket := range result.Buckets {
|
|
println(*bucket.Name)
|
|
}
|
|
|
|
bucket := "bucket1"
|
|
_, err = svc.HeadBucket(context.Background(), &s3.HeadBucketInput{Bucket: &bucket})
|
|
// ERROR HERE
|
|
if err != nil {
|
|
println(err)
|
|
}
|
|
|
|
}
|
|
|
|
// === helpers
|
|
|
|
func MyAwsConfig(cfg MyConfig) (*aws.Config, error) {
|
|
|
|
cred := aws.NewCredentialsCache(credentials.NewStaticCredentialsProvider(cfg.Key, cfg.Secret, ""))
|
|
customResolver := aws.EndpointResolverWithOptionsFunc(
|
|
func(service, region string, options ...interface{}) (aws.Endpoint, error) {
|
|
return aws.Endpoint{
|
|
URL: cfg.Endpoint.URL,
|
|
SigningRegion: cfg.Region,
|
|
}, nil
|
|
})
|
|
|
|
awsCfg, err := config.LoadDefaultConfig(context.TODO(),
|
|
config.WithRegion(cfg.Region),
|
|
config.WithCredentialsProvider(cred),
|
|
config.WithEndpointResolverWithOptions(customResolver),
|
|
config.WithRetryer(func() aws.Retryer {
|
|
r := retry.AddWithMaxAttempts(retry.NewStandard(), *cfg.MaxRetryAttempts)
|
|
return retry.AddWithMaxBackoffDelay(r, time.Duration(*cfg.MaxBackoffDelay)*time.Millisecond)
|
|
}))
|
|
return &awsCfg, err
|
|
}
|
|
|
|
type MyConfig struct {
|
|
// Access key of S3 AWS.
|
|
Key string
|
|
// Access secret of S3 AWS.
|
|
Secret string
|
|
// Region.
|
|
Region string
|
|
// AWS endpoint.
|
|
Endpoint MyEndpoint
|
|
// Bucket configuration.
|
|
Bucket MyBucketConfig
|
|
// File access.
|
|
FileAccess MyFileAccessType
|
|
// Maximum backoff delay (ms, default: 20 sec).
|
|
MaxBackoffDelay *int
|
|
// Maximum attempts to retry operation on error (default: 5).
|
|
MaxRetryAttempts *int
|
|
}
|
|
|
|
type MyBucketConfig struct {
|
|
// Name of bucket
|
|
Name string
|
|
// Enable or not versioning
|
|
Versioning bool
|
|
}
|
|
|
|
type MyEndpoint struct {
|
|
URL string
|
|
}
|
|
|
|
type MyFileAccessType byte
|