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