refactor: minor doc changes
This commit is contained in:
@@ -13,7 +13,7 @@ go get github.com/rhnvrm/simples3
|
||||
## Example
|
||||
|
||||
```go
|
||||
testTxt, _ := os.Open("test.txt")
|
||||
testTxt, _ := os.Open("testdata/test.txt")
|
||||
defer testTxt.Close()
|
||||
|
||||
// Create an instance of the package
|
||||
@@ -24,6 +24,9 @@ s3 := simples3.New(Region, AWSAccessKey, AWSSecretKey)
|
||||
// obtain credentials from IAM attached to the instance.
|
||||
s3 := simples3.NewUsingIAM(Region)
|
||||
|
||||
// You can also set a custom endpoint to a compatible s3 instance.
|
||||
s3.SetEndpoint(CustomEndpoint)
|
||||
|
||||
// Note: Consider adding a testTxt.Seek(0, 0)
|
||||
// in case you have read
|
||||
// the body, as the pointer is shared by the library.
|
||||
|
||||
@@ -55,8 +55,8 @@ const (
|
||||
defaultExpirationHour = 1 * time.Hour
|
||||
)
|
||||
|
||||
// NowTime mockable time.Now()
|
||||
var NowTime = func() time.Time {
|
||||
// nowTime mockable time.Now()
|
||||
var nowTime = func() time.Time {
|
||||
return time.Now().UTC()
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ var newLine = []byte{'\n'}
|
||||
// policy and signing keys with the signature returns the upload policy.
|
||||
// https://docs.aws.amazon.com/ja_jp/AmazonS3/latest/API/sigv4-authentication-HTTPPOST.html
|
||||
func (s3 *S3) CreateUploadPolicies(uploadConfig UploadConfig) (UploadPolicies, error) {
|
||||
nowTime := NowTime()
|
||||
nowTime := nowTime()
|
||||
credential := string(s3.buildCredential(nowTime))
|
||||
data, err := buildUploadSign(nowTime, credential, uploadConfig)
|
||||
if err != nil {
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ type PresignedInput struct {
|
||||
// (https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-query-string-auth.html)
|
||||
func (s3 *S3) GeneratePresignedURL(in PresignedInput) string {
|
||||
var (
|
||||
nowTime = NowTime()
|
||||
nowTime = nowTime()
|
||||
|
||||
protocol = defaultProtocol
|
||||
endpoint = defaultPresignedHost
|
||||
|
||||
+4
-4
@@ -42,7 +42,7 @@ func TestS3_GeneratePresignedURL_Personal(t *testing.T) {
|
||||
Endpoint: os.Getenv("AWS_S3_ENDPOINT"),
|
||||
ObjectKey: "test1.txt",
|
||||
Method: "GET",
|
||||
Timestamp: NowTime(),
|
||||
Timestamp: nowTime(),
|
||||
ExpirySeconds: 3600,
|
||||
}); got == dontwant {
|
||||
t.Errorf("S3.GeneratePresignedURL() = %v, dontwant %v", got, dontwant)
|
||||
@@ -63,7 +63,7 @@ func TestS3_GeneratePresignedURL_ExtraHeader(t *testing.T) {
|
||||
Endpoint: os.Getenv("AWS_S3_ENDPOINT"),
|
||||
ObjectKey: "test2.txt",
|
||||
Method: "GET",
|
||||
Timestamp: NowTime(),
|
||||
Timestamp: nowTime(),
|
||||
ExpirySeconds: 3600,
|
||||
ExtraHeaders: map[string]string{
|
||||
"x-amz-meta-test": "test",
|
||||
@@ -87,7 +87,7 @@ func TestS3_GeneratePresignedURL_PUT(t *testing.T) {
|
||||
Endpoint: os.Getenv("AWS_S3_ENDPOINT"),
|
||||
ObjectKey: "test2.txt",
|
||||
Method: "PUT",
|
||||
Timestamp: NowTime(),
|
||||
Timestamp: nowTime(),
|
||||
ExpirySeconds: 3600,
|
||||
}); got == dontwant {
|
||||
t.Errorf("S3.GeneratePresignedURL() = %v, dontwant %v", got, dontwant)
|
||||
@@ -111,7 +111,7 @@ func BenchmarkS3_GeneratePresigned(b *testing.B) {
|
||||
Endpoint: os.Getenv("AWS_S3_ENDPOINT"),
|
||||
ObjectKey: "test.txt",
|
||||
Method: "GET",
|
||||
Timestamp: NowTime(),
|
||||
Timestamp: nowTime(),
|
||||
ExpirySeconds: 3600,
|
||||
})
|
||||
}
|
||||
|
||||
+2
-1
@@ -158,7 +158,8 @@ func (s3 *S3) getURL(bucket string, args ...string) (uri string) {
|
||||
return
|
||||
}
|
||||
|
||||
// SetEndpoint ...
|
||||
// SetEndpoint can be used to the set a custom endpoint for
|
||||
// using an alternate instance compatible with the s3 API.
|
||||
func (s3 *S3) SetEndpoint(uri string) *S3 {
|
||||
if len(uri) > 0 {
|
||||
s3.Endpoint = uri
|
||||
|
||||
+5
-3
@@ -16,7 +16,7 @@ type tConfig struct {
|
||||
}
|
||||
|
||||
func TestS3_FileUpload(t *testing.T) {
|
||||
testTxt, err := os.Open("test.txt")
|
||||
testTxt, err := os.Open("testdata/test.txt")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -75,7 +75,8 @@ func TestS3_FileUpload(t *testing.T) {
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
for _, testcase := range tests {
|
||||
tt := testcase
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
s3 := New(tt.fields.Region, tt.fields.AccessKey, tt.fields.SecretKey)
|
||||
s3.SetEndpoint(tt.fields.Endpoint)
|
||||
@@ -118,7 +119,8 @@ func TestS3_FileDelete(t *testing.T) {
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
for _, testcase := range tests {
|
||||
tt := testcase
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
s3 := New(tt.fields.Region, tt.fields.AccessKey, tt.fields.SecretKey)
|
||||
s3.SetEndpoint(tt.fields.Endpoint)
|
||||
|
||||
Vendored
Reference in New Issue
Block a user