Skip to content

Commit

Permalink
review: update GetOptions and API.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Auernhammer committed Sep 26, 2017
1 parent f7ddad6 commit 233c413
Show file tree
Hide file tree
Showing 18 changed files with 143 additions and 91 deletions.
2 changes: 1 addition & 1 deletion api-compose-object.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func (s *SourceInfo) getProps(c Client) (size int64, etag string, userMeta map[s
// Get object info - need size and etag here. Also, decryption
// headers are added to the stat request if given.
var objInfo ObjectInfo
opts := GetOptions{}
opts := GetObjectOptions{}
for k, v := range s.decryptKey.getSSEHeaders(false) {
opts.Set(k, v)
}
Expand Down
3 changes: 2 additions & 1 deletion api-get-object-context.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package minio
import "context"

// GetObjectWithContext - returns an seekable, readable object.
func (c Client) GetObjectWithContext(ctx context.Context, bucketName, objectName string, opts GetOptions) (*Object, error) {
// The options can be used to specify the GET request further.
func (c Client) GetObjectWithContext(ctx context.Context, bucketName, objectName string, opts GetObjectOptions) (*Object, error) {
return c.getObjectWithContext(ctx, bucketName, objectName, opts)
}
17 changes: 14 additions & 3 deletions api-get-object-file.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,34 @@ import (
"os"
"path/filepath"

"github.com/minio/minio-go/pkg/encrypt"

"context"

"github.com/minio/minio-go/pkg/s3utils"
)

// FGetObjectWithContext - download contents of an object to a local file.
func (c Client) FGetObjectWithContext(ctx context.Context, bucketName, objectName, filePath string, opts GetOptions) error {
// The options can be used to specify the GET request further.
func (c Client) FGetObjectWithContext(ctx context.Context, bucketName, objectName, filePath string, opts GetObjectOptions) error {
return c.fGetObjectWithContext(ctx, bucketName, objectName, filePath, opts)
}

// FGetObject - download contents of an object to a local file.
func (c Client) FGetObject(bucketName, objectName, filePath string, opts GetOptions) error {
func (c Client) FGetObject(bucketName, objectName, filePath string, opts GetObjectOptions) error {
return c.fGetObjectWithContext(context.Background(), bucketName, objectName, filePath, opts)
}

// FGetEncryptedObject - Decrypt and store an object at filePath.
func (c Client) FGetEncryptedObject(bucketName, objectName, filePath string, materials encrypt.Materials) error {
if materials == nil {
return ErrInvalidArgument("Unable to recognize empty encryption properties")
}
return c.FGetObject(bucketName, objectName, filePath, GetObjectOptions{Materials: materials})
}

// fGetObjectWithContext - fgetObject wrapper function with context
func (c Client) fGetObjectWithContext(ctx context.Context, bucketName, objectName, filePath string, opts GetOptions) error {
func (c Client) fGetObjectWithContext(ctx context.Context, bucketName, objectName, filePath string, opts GetObjectOptions) error {
// Input validation.
if err := s3utils.CheckValidBucketName(bucketName); err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions api-get-object.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ func (c Client) GetEncryptedObject(bucketName, objectName string, encryptMateria
return nil, ErrInvalidArgument("Unable to recognize empty encryption properties")
}

return c.GetObject(bucketName, objectName, GetOptions{Materials: encryptMaterials})
return c.GetObject(bucketName, objectName, GetObjectOptions{Materials: encryptMaterials})
}

// GetObject - returns an seekable, readable object.
func (c Client) GetObject(bucketName, objectName string, opts GetOptions) (*Object, error) {
func (c Client) GetObject(bucketName, objectName string, opts GetObjectOptions) (*Object, error) {
return c.getObjectWithContext(context.Background(), bucketName, objectName, opts)
}

// GetObject wrapper function that accepts a request context
func (c Client) getObjectWithContext(ctx context.Context, bucketName, objectName string, opts GetOptions) (*Object, error) {
func (c Client) getObjectWithContext(ctx context.Context, bucketName, objectName string, opts GetObjectOptions) (*Object, error) {
// Input validation.
if err := s3utils.CheckValidBucketName(bucketName); err != nil {
return nil, err
Expand Down Expand Up @@ -601,7 +601,7 @@ func newObject(reqCh chan<- getRequest, resCh <-chan getResponse, doneCh chan<-
//
// For more information about the HTTP Range header.
// go to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.
func (c Client) getObject(ctx context.Context, bucketName, objectName string, opts GetOptions) (io.ReadCloser, ObjectInfo, error) {
func (c Client) getObject(ctx context.Context, bucketName, objectName string, opts GetObjectOptions) (io.ReadCloser, ObjectInfo, error) {
// Validate input arguments.
if err := s3utils.CheckValidBucketName(bucketName); err != nil {
return nil, ObjectInfo{}, err
Expand Down
18 changes: 9 additions & 9 deletions api-get-options.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ import (
"github.com/minio/minio-go/pkg/encrypt"
)

// GetOptions are used to specify additional headers or options
// GetObjectOptions are used to specify additional headers or options
// during GET requests.
type GetOptions struct {
type GetObjectOptions struct {
headers map[string]string

UserMetadata map[string]string
Materials encrypt.Materials
}

// Header returns the http.Header representation of the GET options.
func (o GetOptions) Header() http.Header {
func (o GetObjectOptions) Header() http.Header {
headers := make(http.Header, len(o.UserMetadata))
for k, v := range o.UserMetadata {
if !strings.HasPrefix(strings.ToLower(k), "x-amz-meta-") {
Expand All @@ -53,15 +53,15 @@ func (o GetOptions) Header() http.Header {
// Set adds a key value pair to the options. The
// key-value pair will be part of the HTTP GET request
// headers.
func (o *GetOptions) Set(key, value string) {
func (o *GetObjectOptions) Set(key, value string) {
if o.headers == nil {
o.headers = make(map[string]string)
}
o.headers[http.CanonicalHeaderKey(key)] = value
}

// SetMatchETag - set match etag.
func (o *GetOptions) SetMatchETag(etag string) error {
func (o *GetObjectOptions) SetMatchETag(etag string) error {
if etag == "" {
return ErrInvalidArgument("ETag cannot be empty.")
}
Expand All @@ -70,7 +70,7 @@ func (o *GetOptions) SetMatchETag(etag string) error {
}

// SetMatchETagExcept - set match etag except.
func (o *GetOptions) SetMatchETagExcept(etag string) error {
func (o *GetObjectOptions) SetMatchETagExcept(etag string) error {
if etag == "" {
return ErrInvalidArgument("ETag cannot be empty.")
}
Expand All @@ -79,7 +79,7 @@ func (o *GetOptions) SetMatchETagExcept(etag string) error {
}

// SetUnmodified - set unmodified time since.
func (o *GetOptions) SetUnmodified(modTime time.Time) error {
func (o *GetObjectOptions) SetUnmodified(modTime time.Time) error {
if modTime.IsZero() {
return ErrInvalidArgument("Modified since cannot be empty.")
}
Expand All @@ -88,7 +88,7 @@ func (o *GetOptions) SetUnmodified(modTime time.Time) error {
}

// SetModified - set modified time since.
func (o *GetOptions) SetModified(modTime time.Time) error {
func (o *GetObjectOptions) SetModified(modTime time.Time) error {
if modTime.IsZero() {
return ErrInvalidArgument("Modified since cannot be empty.")
}
Expand All @@ -98,7 +98,7 @@ func (o *GetOptions) SetModified(modTime time.Time) error {

// SetRange - set the start and end offset of the object to be read.
// See https://tools.ietf.org/html/rfc7233#section-3.1 for reference.
func (o *GetOptions) SetRange(start, end int64) error {
func (o *GetObjectOptions) SetRange(start, end int64) error {
switch {
case start == 0 && end < 0:
// Read last '-end' bytes. `bytes=-N`.
Expand Down
4 changes: 2 additions & 2 deletions api-stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func extractObjMetadata(header http.Header) http.Header {
}

// StatObject verifies if object exists and you have permission to access.
func (c Client) StatObject(bucketName, objectName string, opts GetOptions) (ObjectInfo, error) {
func (c Client) StatObject(bucketName, objectName string, opts GetObjectOptions) (ObjectInfo, error) {
// Input validation.
if err := s3utils.CheckValidBucketName(bucketName); err != nil {
return ObjectInfo{}, err
Expand All @@ -93,7 +93,7 @@ func (c Client) StatObject(bucketName, objectName string, opts GetOptions) (Obje
}

// Lower level API for statObject supporting pre-conditions and range headers.
func (c Client) statObject(bucketName, objectName string, opts GetOptions) (ObjectInfo, error) {
func (c Client) statObject(bucketName, objectName string, opts GetObjectOptions) (ObjectInfo, error) {
// Input validation.
if err := s3utils.CheckValidBucketName(bucketName); err != nil {
return ObjectInfo{}, err
Expand Down
4 changes: 2 additions & 2 deletions core.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ func (c Core) PutBucketPolicy(bucket string, bucketPolicy policy.BucketAccessPol
// GetObject is a lower level API implemented to support reading
// partial objects and also downloading objects with special conditions
// matching etag, modtime etc.
func (c Core) GetObject(bucketName, objectName string, opts GetOptions) (io.ReadCloser, ObjectInfo, error) {
func (c Core) GetObject(bucketName, objectName string, opts GetObjectOptions) (io.ReadCloser, ObjectInfo, error) {
return c.getObject(context.Background(), bucketName, objectName, opts)
}

// StatObject is a lower level API implemented to support special
// conditions matching etag, modtime on a request.
func (c Core) StatObject(bucketName, objectName string, opts GetOptions) (ObjectInfo, error) {
func (c Core) StatObject(bucketName, objectName string, opts GetObjectOptions) (ObjectInfo, error) {
return c.statObject(bucketName, objectName, opts)
}
14 changes: 7 additions & 7 deletions core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func TestGetObjectCore(t *testing.T) {
buf3 := make([]byte, n)
buf4 := make([]byte, 1)

opts := GetOptions{}
opts := GetObjectOptions{}
opts.SetRange(offset, offset+int64(len(buf1))-1)
reader, objectInfo, err := c.GetObject(bucketName, objectName, opts)
if err != nil {
Expand Down Expand Up @@ -179,7 +179,7 @@ func TestGetObjectCore(t *testing.T) {
t.Fatal("Error: Incorrect data read in GetObject, than what was previously upoaded.")
}

opts = GetOptions{}
opts = GetObjectOptions{}
opts.SetMatchETag("etag")
_, _, err = c.GetObject(bucketName, objectName, opts)
if err == nil {
Expand All @@ -189,7 +189,7 @@ func TestGetObjectCore(t *testing.T) {
t.Fatalf("Expected \"PreconditionFailed\" as code, got %s instead", errResp.Code)
}

opts = GetOptions{}
opts = GetObjectOptions{}
opts.SetMatchETagExcept("etag")
reader, objectInfo, err = c.GetObject(bucketName, objectName, opts)
if err != nil {
Expand All @@ -209,7 +209,7 @@ func TestGetObjectCore(t *testing.T) {
t.Fatal("Error: Incorrect data read in GetObject, than what was previously upoaded.")
}

opts = GetOptions{}
opts = GetObjectOptions{}
opts.SetRange(0, 0)
reader, objectInfo, err = c.GetObject(bucketName, objectName, opts)
if err != nil {
Expand Down Expand Up @@ -288,7 +288,7 @@ func TestGetObjectContentEncoding(t *testing.T) {
t.Fatalf("Error: number of bytes does not match, want %v, got %v\n", len(buf), n)
}

rwc, objInfo, err := c.GetObject(bucketName, objectName, GetOptions{})
rwc, objInfo, err := c.GetObject(bucketName, objectName, GetObjectOptions{})
if err != nil {
t.Fatalf("Error: %v", err)
}
Expand Down Expand Up @@ -427,7 +427,7 @@ func TestCorePutObject(t *testing.T) {
}

// Read the data back
r, err := c.Client.GetObject(bucketName, objectName, GetOptions{})
r, err := c.Client.GetObject(bucketName, objectName, GetObjectOptions{})
if err != nil {
t.Fatal("Error:", err, bucketName, objectName)
}
Expand Down Expand Up @@ -498,7 +498,7 @@ func TestCoreGetObjectMetadata(t *testing.T) {
log.Fatalln(err)
}

reader, objInfo, err := core.GetObject(bucketName, "my-objectname", GetOptions{})
reader, objInfo, err := core.GetObject(bucketName, "my-objectname", GetObjectOptions{})
if err != nil {
log.Fatalln(err)
}
Expand Down

0 comments on commit 233c413

Please sign in to comment.