Update to new changes in minio-go
This commit is contained in:
Generated
+1
-1
@@ -32,7 +32,7 @@
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/minio/minio-go",
|
||||
"Rev": "513ea3dc246f1aa25bfd0c21fe87011119b265ca"
|
||||
"Rev": "6d3ba37e943a498d80330ce0b96d21213ee3e615"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/minio/minio/pkg/iodine",
|
||||
|
||||
+43
@@ -29,6 +29,7 @@ func ExampleGetPartSize() {
|
||||
fmt.Println(GetPartSize(5000000000))
|
||||
// Output: 5242880
|
||||
}
|
||||
|
||||
func ExampleGetPartSize_second() {
|
||||
fmt.Println(GetPartSize(50000000000000000))
|
||||
// Output: 5368709120
|
||||
@@ -206,6 +207,13 @@ func TestObjectOperations(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Error")
|
||||
}
|
||||
err = a.RemoveObject("bucket", "object1")
|
||||
if err == nil {
|
||||
t.Fatalf("Error")
|
||||
}
|
||||
if err.Error() != "404 Not Found" {
|
||||
t.Errorf("Error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPartSize(t *testing.T) {
|
||||
@@ -261,3 +269,38 @@ func TestURLEncoding(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestErrorResponse(t *testing.T) {
|
||||
errorResponse := []byte("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Error><Code>AccessDenied</Code><Message>Access Denied</Message><Resource>/mybucket/myphoto.jpg</Resource><RequestId>F19772218238A85A</RequestId><HostId>GuWkjyviSiGHizehqpmsD1ndz5NClSP19DOT+s2mv7gXGQ8/X1lhbDGiIJEXpGFD</HostId></Error>")
|
||||
errorReader := bytes.NewReader(errorResponse)
|
||||
err := responseToError(errorReader)
|
||||
if err == nil {
|
||||
t.Fatal("Error")
|
||||
}
|
||||
if err.Error() != "Access Denied" {
|
||||
t.Fatal("Error")
|
||||
}
|
||||
resp := ToErrorResponse(err)
|
||||
// valid all fields
|
||||
if resp == nil {
|
||||
t.Fatal("Error")
|
||||
}
|
||||
if resp.Code != "AccessDenied" {
|
||||
t.Fatal("Error")
|
||||
}
|
||||
if resp.RequestID != "F19772218238A85A" {
|
||||
t.Fatal("Error")
|
||||
}
|
||||
if resp.Message != "Access Denied" {
|
||||
t.Fatal("Error")
|
||||
}
|
||||
if resp.Resource != "/mybucket/myphoto.jpg" {
|
||||
t.Fatal("Error")
|
||||
}
|
||||
if resp.HostID != "GuWkjyviSiGHizehqpmsD1ndz5NClSP19DOT+s2mv7gXGQ8/X1lhbDGiIJEXpGFD" {
|
||||
t.Fatal("Error")
|
||||
}
|
||||
if resp.XML() == "" {
|
||||
t.Fatal("Error")
|
||||
}
|
||||
}
|
||||
|
||||
Generated
Vendored
+44
-27
@@ -18,7 +18,7 @@ package client
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"net/http"
|
||||
"io"
|
||||
)
|
||||
|
||||
/* **** SAMPLE ERROR RESPONSE ****
|
||||
@@ -32,8 +32,9 @@ import (
|
||||
</Error>
|
||||
*/
|
||||
|
||||
// errorResponse is the type returned by some API operations.
|
||||
type errorResponse struct {
|
||||
// ErrorResponse is the type error returned by some API operations.
|
||||
type ErrorResponse struct {
|
||||
XMLName xml.Name `xml:"Error" json:"-"`
|
||||
Code string
|
||||
Message string
|
||||
Resource string
|
||||
@@ -41,34 +42,50 @@ type errorResponse struct {
|
||||
HostID string `xml:"HostId"`
|
||||
}
|
||||
|
||||
// ToErrorResponse returns parsed ErrorResponse struct, if input is nil or not ErrorResponse return value is nil
|
||||
// this fuction is useful when some one wants to dig deeper into the error structures over the network.
|
||||
//
|
||||
// for example:
|
||||
//
|
||||
// import s3 "github.com/minio/minio-go"
|
||||
// ...
|
||||
// ...
|
||||
// ..., err := s3.GetObject(...)
|
||||
// if err != nil {
|
||||
// resp := s3.ToErrorResponse(err)
|
||||
// fmt.Println(resp.XML())
|
||||
// }
|
||||
// ...
|
||||
// ...
|
||||
func ToErrorResponse(err error) *ErrorResponse {
|
||||
switch err := err.(type) {
|
||||
case ErrorResponse:
|
||||
return &err
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// XML send raw xml marshalled as string
|
||||
func (e ErrorResponse) XML() string {
|
||||
b, _ := xml.Marshal(&e)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// Error formats HTTP error string
|
||||
func (e ErrorResponse) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
/// Internal function not exposed
|
||||
|
||||
// responseToError returns a new encoded ErrorResponse structure
|
||||
func responseToError(res *http.Response) error {
|
||||
var respError errorResponse
|
||||
decoder := xml.NewDecoder(res.Body)
|
||||
func responseToError(body io.Reader) error {
|
||||
var respError ErrorResponse
|
||||
decoder := xml.NewDecoder(body)
|
||||
err := decoder.Decode(&respError)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return respError
|
||||
}
|
||||
|
||||
// GetCode get underlying error code for example: "MissingSecurityHeader"
|
||||
func (e errorResponse) GetCode() string {
|
||||
return e.Code
|
||||
}
|
||||
|
||||
// GetRequestID get request id useful in debugging
|
||||
func (e errorResponse) GetRequestID() string {
|
||||
return e.RequestID
|
||||
}
|
||||
|
||||
// XML send raw xml marshalled as string
|
||||
func (e errorResponse) XML() string {
|
||||
b, _ := xml.Marshal(&e)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// Error formats HTTP error string
|
||||
func (e errorResponse) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
+8
-8
@@ -112,7 +112,7 @@ func (a *lowLevelAPI) putBucket(bucket, acl, location string) error {
|
||||
defer resp.Body.Close()
|
||||
if resp != nil {
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return responseToError(resp)
|
||||
return responseToError(resp.Body)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -146,7 +146,7 @@ func (a *lowLevelAPI) putBucketACL(bucket, acl string) error {
|
||||
defer resp.Body.Close()
|
||||
if resp != nil {
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return responseToError(resp)
|
||||
return responseToError(resp.Body)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -179,7 +179,7 @@ func (a *lowLevelAPI) getBucketACL(bucket string) (*accessControlPolicy, error)
|
||||
defer resp.Body.Close()
|
||||
if resp != nil {
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, responseToError(resp)
|
||||
return nil, responseToError(resp.Body)
|
||||
}
|
||||
}
|
||||
policy := new(accessControlPolicy)
|
||||
@@ -218,7 +218,7 @@ func (a *lowLevelAPI) getBucketLocation(bucket string) (string, error) {
|
||||
defer resp.Body.Close()
|
||||
if resp != nil {
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return "", responseToError(resp)
|
||||
return "", responseToError(resp.Body)
|
||||
}
|
||||
}
|
||||
var locationConstraint string
|
||||
@@ -299,7 +299,7 @@ func (a *lowLevelAPI) listObjects(bucket, marker, prefix, delimiter string, maxk
|
||||
defer resp.Body.Close()
|
||||
if resp != nil {
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, responseToError(resp)
|
||||
return nil, responseToError(resp.Body)
|
||||
}
|
||||
}
|
||||
listBucketResult := new(listBucketResult)
|
||||
@@ -417,7 +417,7 @@ func (a *lowLevelAPI) putObject(bucket, object string, size int64, body io.ReadS
|
||||
defer resp.Body.Close()
|
||||
if resp != nil {
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, responseToError(resp)
|
||||
return nil, responseToError(resp.Body)
|
||||
}
|
||||
}
|
||||
metadata := new(ObjectStat)
|
||||
@@ -469,7 +469,7 @@ func (a *lowLevelAPI) getObject(bucket, object string, offset, length uint64) (i
|
||||
case http.StatusOK:
|
||||
case http.StatusPartialContent:
|
||||
default:
|
||||
return nil, nil, responseToError(resp)
|
||||
return nil, nil, responseToError(resp.Body)
|
||||
}
|
||||
}
|
||||
md5sum := strings.Trim(resp.Header.Get("ETag"), "\"") // trim off the odd double quotes
|
||||
@@ -602,7 +602,7 @@ func (a *lowLevelAPI) listBuckets() (*listAllMyBucketsResult, error) {
|
||||
return nil, fmt.Errorf("%s", resp.Status)
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, responseToError(resp)
|
||||
return nil, responseToError(resp.Body)
|
||||
}
|
||||
}
|
||||
listAllMyBucketsResult := new(listAllMyBucketsResult)
|
||||
|
||||
+5
-5
@@ -86,7 +86,7 @@ func (a *lowLevelAPI) listMultipartUploads(bucket, keymarker, uploadIDMarker, pr
|
||||
defer resp.Body.Close()
|
||||
if resp != nil {
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, responseToError(resp)
|
||||
return nil, responseToError(resp.Body)
|
||||
}
|
||||
}
|
||||
listMultipartUploadsResult := new(listMultipartUploadsResult)
|
||||
@@ -127,7 +127,7 @@ func (a *lowLevelAPI) initiateMultipartUpload(bucket, object string) (*initiateM
|
||||
defer resp.Body.Close()
|
||||
if resp != nil {
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, responseToError(resp)
|
||||
return nil, responseToError(resp.Body)
|
||||
}
|
||||
}
|
||||
initiateMultipartUploadResult := new(initiateMultipartUploadResult)
|
||||
@@ -176,7 +176,7 @@ func (a *lowLevelAPI) completeMultipartUpload(bucket, object, uploadID string, c
|
||||
defer resp.Body.Close()
|
||||
if resp != nil {
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, responseToError(resp)
|
||||
return nil, responseToError(resp.Body)
|
||||
}
|
||||
}
|
||||
completeMultipartUploadResult := new(completeMultipartUploadResult)
|
||||
@@ -262,7 +262,7 @@ func (a *lowLevelAPI) listObjectParts(bucket, object, uploadID string, partNumbe
|
||||
defer resp.Body.Close()
|
||||
if resp != nil {
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, responseToError(resp)
|
||||
return nil, responseToError(resp.Body)
|
||||
}
|
||||
}
|
||||
listObjectPartsResult := new(listObjectPartsResult)
|
||||
@@ -322,7 +322,7 @@ func (a *lowLevelAPI) uploadPart(bucket, object, uploadID string, partNumber int
|
||||
defer resp.Body.Close()
|
||||
if resp != nil {
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, responseToError(resp)
|
||||
return nil, responseToError(resp.Body)
|
||||
}
|
||||
}
|
||||
return completePart, nil
|
||||
|
||||
Reference in New Issue
Block a user