oss

package module
v0.0.0-...-bd7533e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2015 License: Apache-2.0 Imports: 23 Imported by: 0

README

Aliyun OSS Go SDK

GoDoc Build Status

Feature
  • All OSS API
  • Multipart Upload
  • Range Get
  • Full Tested
  • Simple and Easy to use
  • ...
Install

$ go get github.com/cxr29/aliyun-oss-go-sdk

Usage
// Service:
s := oss.NewService("YourAccessKeyId", "YourAccessKeySecret")
// or new service use struct literals
//s := oss.Service{
//	AccessKeyId:     "YourAccessKeyId",
//	AccessKeySecret: "YourAccessKeySecret",
//	...
//}

buckets, err := s.ListBucket() // list my bucket

// Bucket:
b := s.NewBucket("YourBucketName")
// or new bucket use struct literals
//b := oss.Bucket{
//	Service: s,
//	Name:    "YourBucketName",
//	...
//}

err = b.Put()                     // create new bucket
b.Location, err = b.GetLocation() // get and record the location
err = b.Delete()                  // delete the bucket

objects, err := b.ListObject() // list my object

// Object:
o := b.NewObject("YourObjectName")
// or new object use struct literals
//o := oss.Object{
//	Bucket: b,
//	Name:   "YourObjectName",
//	...
//}

var v []byte
// put the bytes as the object data
err = o.Put(v)
// get the object data to the bytes
err = o.Get(&v)

var f *os.File
// open the file for reading then put the file as the object data
err = o.Put(f)
// open the file for writing then get the object data to the file
err = o.Get(f)

// get and record the acl
o.ACL, err = o.GetACL()

// put change the acl
o.ACL = oss.ACLPublicRead
err = o.PutACL()

// delete the object
err = o.Delete()

// Multiupload Upload:
// initialize a Multipart Upload
imu, err := o.InitiateMultipartUpload()

cmu := oss.CompleteMultipartUpload{}

// upload a part
etag, err := o.UploadPart(1, imu.UploadId, part)
cmu.Part = append(cmu.Part, oss.CompleteMultipartUploadPart{1, etag})
// or upload a part copy from the source object
cpr, err := o.UploadPartCopy(1, imu.UploadId, source)
cmu.Part = append(cmu.Part, oss.CompleteMultipartUploadPart{1, cpr.ETag})

// ...

// complte the multipart upload
cmur, err := o.CompleteMultipartUpload(imu.UploadId, cmu)
// or abort the multipart upload
err = o.AbortMultipartUpload(imu.UploadId)

More see the examples.

API Doc

https://godoc.org/github.com/cxr29/aliyun-oss-go-sdk

Test
$ export OSSTestAccessKeyId=YourAccessKeyId
$ export OSSTestAccessKeySecret=YourAccessKeySecret
$ export OSSTestBucket=YourBucketName
$ go test -test.v .

OSSTestPause pause in seconds when send request to OSS, because run test so fast will failed. OSSTestUnsafe, OSSTestDomain and OSSTestSecurityToken also supported.

Author

Chen Xianren <cxr29@foxmail.com>

Documentation

Overview

Package oss implements a library for Aliyun Object Storage Service.

Index

Constants

View Source
const (
	ACLPublicReadWrite = "public-read-write"
	ACLPublicRead      = "public-read"
	ACLPrivate         = "private"
)

OSS Access Control List

View Source
const (
	LocationCNQingdao    = "oss-cn-qingdao"
	LocationCNBeijing    = "oss-cn-beijing"
	LocationCNHangzhou   = "oss-cn-hangzhou"
	LocationCNHongkong   = "oss-cn-hongkong"
	LocationCNShenzhen   = "oss-cn-shenzhen"
	LocationCNShanghai   = "oss-cn-shanghai"
	LocationUSWest1      = "oss-us-west-1"
	LocationAPSoutheast1 = "oss-ap-southeast-1"
)

OSS Location List

View Source
const (
	HeaderRange        = "Range"
	HeaderContentRange = "Content-Range"
)

Variables

View Source
var (
	ErrContentRangeInvalid = errors.New("content range invalid")
	ErrContentRangeCorrupt = errors.New("content range corrupt")
)
View Source
var UserAgent = "aliyun-oss-go-sdk"

UserAgent is the default user agent and is used by GetRequest.

Functions

func CanonicalizedHeaders

func CanonicalizedHeaders(header http.Header) string

CanonicalizedHeaders returns the canonicalized OSS headers as a string.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/access-control&signature-header

func CanonicalizedResource

func CanonicalizedResource(u *url.URL) string

CanonicalizedResource returns the canonicalized OSS resource as a string.

Get the bucket name and the object name from the URL's Host and Path.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/access-control&signature-header

func FormatRange

func FormatRange(first, length int64) (r string)

FormatRange set the Range header given first and length. It returns byte-range-spec if first >= 0, no last-byte-pos if length <= 0. It returns suffix-byte-range-spec if first < 0 and length > 0. It returns the empty string if first < 0 and length <= 0.

http://tools.ietf.org/html/draft-ietf-httpbis-p5-range-19#section-5.4

func GetDomain

func GetDomain(location string, internal bool) (domain string)

GetDomain returns the OSS access domain by the location, if the internal is ture returns the intranet domain.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/product-documentation/domain-region

func HmacSha1

func HmacSha1(secret, data string) string

HmacSha1 returns the base64 HMAC-SHA1 hash of the data using the given secret.

func HmacSha256

func HmacSha256(secret, data string) string

HmacSha256 returns the base64 HMAC-SHA256 hash of the data using the given secret.

func HmacX

func HmacX(secret, data string, h func() hash.Hash) string

HmacX returns the base64 HMAC-X hash of the data using the given secret.

The SHA1 is used if the given hash.Hash type is nil.

func IsBucketName

func IsBucketName(name string) bool

IsBucketName returns true if the name is a valid bucket name.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/product-documentation/intruduction&concepts

func IsObjectName

func IsObjectName(name string) bool

IsObjectName returns true if the name is a valid object name.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/product-documentation/intruduction&concepts

func Md5sum

func Md5sum(data []byte) string

Md5sum returns the base64 MD5 checksum of the data.

func ParseContentRange

func ParseContentRange(cr string) (first int64, length int64, total int64, err error)

ParseContentRange parse the Content-Range header. It returns total = -1 if the instance-length is the asterisk "*" character. It returns first = length = -1 if the byte-range-resp-spec is the asterisk "*" character.

http://tools.ietf.org/html/draft-ietf-httpbis-p5-range-19#section-5.2

func ReadBody

func ReadBody(res *http.Response, v interface{}) error

ReadBody reads the response body and stores the result in the value pointed to by v,

When the status code is 3xx, 4xx or 5xx returns the Error.

If v is nil, the response body is discarded or, if v's type is not *[]byte, *os.File and *bytes.Buffer, then decode XML to it.

Content-Encoding deflate and gzip are supported.

Types

type AccessControlPolicy

type AccessControlPolicy struct {
	Owner             Owner
	AccessControlList struct {
		Grant string
	}
}

AccessControlPolicy contains the information of the bucket ACL.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/access-control&bucket-acl

type Bucket

type Bucket struct {
	Service
	Name     string
	ACL      string
	Location string
}

Bucket represents a OSS bucket, the Name is required.

func (Bucket) Delete

func (b Bucket) Delete(args ...Params) error

Delete the bucket, returns BucketNotEmpty Error if the buckect is not empty.

The first optional Params is for Header, the second is for Query.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/bucket&DeleteBucket

func (Bucket) DeleteCORS

func (b Bucket) DeleteCORS(args ...Params) error

DeleteCORS close the CORS and empty the rules.

The first optional Params is for Header, the second is for Query.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/cors&DeleteBucketcors

func (Bucket) DeleteLifecycle

func (b Bucket) DeleteLifecycle(args ...Params) error

DeleteLifecycle remove the objects lifecycle of the bucket, after no objects will be auto deleted.

The first optional Params is for Header, the second is for Query.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/bucket&DeleteBucketLifecycle

func (Bucket) DeleteLogging

func (b Bucket) DeleteLogging(args ...Params) error

DeleteLogging close the bucket access log.

The first optional Params is for Header, the second is for Query.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/bucket&DeleteBucketLogging

func (Bucket) DeleteObjects

func (b Bucket) DeleteObjects(keys []string, quiet bool, args ...Params) ([]string, error)

DeleteObjects delete multiple objects by the keys, if not quiet returns the deleted objects.

The first optional Params is for Header, the second is for Query.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/object&DeleteMultipleObjects

func (Bucket) DeleteWebsite

func (b Bucket) DeleteWebsite(args ...Params) error

DeleteWebsite close the static site of the bucket.

The first optional Params is for Header, the second is for Query.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/bucket&DeleteBucketWebsite

func (Bucket) Do

func (b Bucket) Do(method, object string, body, v interface{}, args ...Params) error

Do sends an HTTP request to OSS and read the HTTP response to v.

The first optional Params is for Header, the second is for Query.

Overwritten the Service.Do with the bucket name.

func (Bucket) GetACL

func (b Bucket) GetACL(args ...Params) (string, error)

GetACL returns the bucket ACL.

The first optional Params is for Header, the second is for Query.

Get and record:

b.ACL, err = b.GetACL()

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucketAcl

func (Bucket) GetCORS

func (b Bucket) GetCORS(args ...Params) (*CORSConfiguration, error)

GetCORS get the CROS configuration.

The first optional Params is for Header, the second is for Query.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/cors&GetBucketcors

func (Bucket) GetLifecycle

func (b Bucket) GetLifecycle(args ...Params) (*LifecycleConfiguration, error)

GetLifecycle returns the objects lifecycle configuration of the bucket.

The first optional Params is for Header, the second is for Query.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucketLifecycle

func (Bucket) GetLocation

func (b Bucket) GetLocation(args ...Params) (string, error)

GetLocation returns the bucket location.

The first optional Params is for Header, the second is for Query.

Get and record:

b.Location, err = b.GetLocation()

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucketLocation

func (Bucket) GetLogging

func (b Bucket) GetLogging(args ...Params) (*BucketLoggingStatus, error)

GetLogging returns the logging status of the bucket.

The first optional Params is for Header, the second is for Query.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucketLogging

func (Bucket) GetReferer

func (b Bucket) GetReferer(args ...Params) (*RefererConfiguration, error)

GetReferer returns the referer white list configuration of the bucket.

The first optional Params is for Header, the second is for Query.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucketReferer

func (Bucket) GetRequest

func (b Bucket) GetRequest(method, object string, body interface{}, args ...Params) (*http.Request, error)

GetRequest returns a new http.Request given a method and optional object, body.

The first optional Params is for Header, the second is for Query.

Overwritten the Service.GetRequest with the bucket name.

func (Bucket) GetResponse

func (b Bucket) GetResponse(method, object string, body interface{}, args ...Params) (*http.Response, error)

GetResponse sends an HTTP request to OSS and returns the HTTP response.

The first optional Params is for Header, the second is for Query.

Overwritten the Service.GetResponse with the bucket name.

func (Bucket) GetWebsite

func (b Bucket) GetWebsite(args ...Params) (*WebsiteConfiguration, error)

GetWebsite returns the static site configuration of the bucket.

The first optional Params is for Header, the second is for Query.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucketWebsite

func (Bucket) ListMultipartUploads

func (b Bucket) ListMultipartUploads(args ...Params) (*ListMultipartUploadsResult, error)

ListMultipartUploads returns the initialized but not complete or abort Multipart Uploads.

The first optional Params is for Header, the second is for Query.

Query predefine parameters: delimiter, max-uploads, key-marker, prefix, upload-id-marker, encoding-type.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/multipart-upload&ListMultipartUploads

func (Bucket) ListObject

func (b Bucket) ListObject(args ...Params) (*ListBucketResult, error)

ListObject returns the objects information of the bucket.

The first optional Params is for Header, the second is for Query.

Query predefine parameters: delimiter, marker, max-keys, prefix, encoding-type.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucket

func (Bucket) NewObject

func (b Bucket) NewObject(objectName string) Object

NewObject returns a new Object given a objectName from the bucket.

func (Bucket) Put

func (b Bucket) Put(args ...Params) error

Put create the buckect also send the ACL and the location if they are not the empty string.

The first optional Params is for Header, the second is for Query.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/bucket&PutBucket

func (Bucket) PutACL

func (b Bucket) PutACL(args ...Params) error

PutACL change the bucket acl if it is the empty string.

The first optional Params is for Header, the second is for Query.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/bucket&PutBucketACL

func (Bucket) PutCORS

func (b Bucket) PutCORS(cfg CORSConfiguration, args ...Params) error

PutCORS set the CROS configuration, replace it if already exists.

The first optional Params is for Header, the second is for Query.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/cors&PutBucketcors

func (Bucket) PutLifecycle

func (b Bucket) PutLifecycle(lc LifecycleConfiguration, args ...Params) error

PutLifecycle set the objects lifecycle of the bucket.

The first optional Params is for Header, the second is for Query.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/bucket&PutBucketLifecycle

func (Bucket) PutLogging

func (b Bucket) PutLogging(bls BucketLoggingStatus, args ...Params) error

PutLogging open the bucket access log.

The first optional Params is for Header, the second is for Query.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/bucket&PutBucketLogging

func (Bucket) PutReferer

func (b Bucket) PutReferer(rc RefererConfiguration, args ...Params) error

PutReferer set the referer white list for preventing hotlinking.

The first optional Params is for Header, the second is for Query.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/bucket&PutBucketReferer https://docs.aliyun.com/#/pub/oss/product-documentation/function&referer-white-list

func (Bucket) PutWebsite

func (b Bucket) PutWebsite(wc WebsiteConfiguration, args ...Params) error

PutWebsite set the bucket as a static site.

The first optional Params is for Header, the second is for Query.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/bucket&PutBucketWebsite

type BucketLoggingStatus

type BucketLoggingStatus struct {
	LoggingEnabled struct {
		TargetBucket string
		TargetPrefix string
	}
}

BucketLoggingStatus represents the logging status.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/bucket&PutBucketLogging https://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucketLogging

type CORSConfiguration

type CORSConfiguration struct {
	CORSRule []CORSRule
}

CORSConfiguration represents the CORS configuration.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/cors&PutBucketcors https://docs.aliyun.com/#/pub/oss/api-reference/cors&GetBucketcors

type CORSRule

type CORSRule struct {
	AllowedOrigin string
	AllowedMethod string
	AllowedHeader string
	ExposeHeader  string
	MaxAgeSeconds int
}

CORSRule represents a rule of the CORS configuration.

type CompleteMultipartUpload

type CompleteMultipartUpload struct {
	Part []CompleteMultipartUploadPart
}

CompleteMultipartUpload represents all the completed parts.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/multipart-upload&CompleteMultipartUpload

type CompleteMultipartUploadPart

type CompleteMultipartUploadPart struct {
	PartNumber int
	ETag       string
}

CompleteMultipartUploadPart represents a completed part.

type CompleteMultipartUploadResult

type CompleteMultipartUploadResult struct {
	Bucket   string
	ETag     string
	Location string
	Key      string
}

CompleteMultipartUploadResult represents the complete Multipart Upload result.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/multipart-upload&CompleteMultipartUpload

type CopyObjectResult

type CopyObjectResult struct {
	LastModified string
	ETag         string
}

CopyObjectResult represents the copy object result. Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/object&CopyObject

type CopyPartResult

type CopyPartResult struct {
	LastModified string
	ETag         string
}

CopyPartResult represents the upload a copy part result.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/multipart-upload&UploadPartCopy

type CreateBucketConfiguration

type CreateBucketConfiguration struct {
	LocationConstraint string
}

CreateBucketConfiguration represents the create bucket configuration.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/bucket&PutBucket

type Delete

type Delete struct {
	Quiet  bool
	Object []DeleteObject
}

Delete represents the delete objects.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/object&DeleteMultipleObjects

type DeleteObject

type DeleteObject struct {
	Key string
}

DeleteObject represents a delete object.

type DeleteResult

type DeleteResult struct {
	Deleted []DeleteObject
}

DeleteResult represents the delete objects result.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/object&DeleteMultipleObjects

type Error

type Error struct {
	Code      string
	RequestId string
	HostId    string
	Message   string
}

Error represents the OSS error response when the status code is 3xx, 4xx or 5xx.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/error-response

func (Error) Error

func (e Error) Error() string

type GetObjectInfoResult

type GetObjectInfoResult struct {
	Bucket       string
	Type         string
	Key          string
	ETag         string
	ContentType  string `xml:"Content-Type"`
	Size         int64
	LastModified string // 2006-01-02T15:04:05.000Z
}

GetObjectInfoResult represents the object info result.

type InitiateMultipartUploadResult

type InitiateMultipartUploadResult struct {
	Bucket   string
	Key      string
	UploadId string
}

InitiateMultipartUploadResult represents the initialize Multipart Upload result.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/multipart-upload&InitiateMultipartUpload

type LifecycleConfiguration

type LifecycleConfiguration struct {
	Rule []LifecycleRule
}

LifecycleConfiguration represents the objects lifecycle configuration.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/bucket&PutBucketLifecycle https://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucketLifecycle

type LifecycleRule

type LifecycleRule struct {
	ID         string `xml:",omitempty"`
	Prefix     string
	Status     string // Enabled, Disabled
	Expiration struct {
		Date string `xml:",omitempty"`
		Days int    `xml:",omitempty"`
	}
}

LifecycleRule represents a rule of the objects lifecycle configuration.

type ListAllMyBucketsResult

type ListAllMyBucketsResult struct {
	Prefix      string
	Marker      string
	MaxKeys     string
	IsTruncated bool
	NextMarker  string
	Owner       Owner
	Buckets     struct {
		Bucket []struct {
			Location     string
			Name         string
			CreationDate string
		}
	}
}

ListAllMyBucketsResult represents the get service result.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/service&GetService

type ListBucketResult

type ListBucketResult struct {
	Name        string
	Prefix      string
	Marker      string
	MaxKeys     string
	Delimiter   string
	IsTruncated bool
	Contents    []struct {
		Key          string
		LastModified string
		ETag         string
		Type         string
		Size         string
		StorageClass string
		Owner        Owner
	}
	CommonPrefixes struct {
		Prefix string
	}
	NextMarker   string
	EncodingType string `xml:"encoding-type,omitempty"`
}

ListBucketResult represents the get bucket result.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucket

type ListMultipartUploadsResult

type ListMultipartUploadsResult struct {
	Bucket           string
	EncodingType     string
	KeyMarker        string
	UploadIdMarker   string
	NextKeyMarker    string
	NextUploadMarker string
	MaxUploads       int
	IsTruncated      bool
	Upload           []struct {
		Key       string
		UploadId  string
		Initiated time.Time
	}
}

ListMultipartUploadsResult represents the list Multipart Uploads result.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/multipart-upload&ListMultipartUploads

type ListPartsResult

type ListPartsResult struct {
	Bucket               string
	EncodingType         string
	Key                  string
	UploadId             string
	PartNumberMarker     int
	NextPartNumberMarker string
	MaxParts             int
	IsTruncated          bool
	Part                 []struct {
		PartNumber   int
		LastModified time.Time
		ETag         string
		Size         int
	}
}

ListPartsResult represents the list parts result.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/multipart-upload&ListParts

type Object

type Object struct {
	Bucket
	Name string
	ACL  string
}

Object represents a OSS object, the Name is required.

func (Object) AbortMultipartUpload

func (o Object) AbortMultipartUpload(uploadId string, args ...Params) error

AbortMultipartUpload abort the Multipart Upload given a uploadId, all the already uploaded parts will be deleted.

To release all the OSS space call multiple times.

The first optional Params is for Header, the second is for Query.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/multipart-upload&AbortMultipartUpload

func (Object) Append

func (o Object) Append(position int64, data interface{}, args ...Params) (next int64, crc, etag string, err error)

Append the data to the object content, also send the ACL if it is not the empty string, returns ObjectNotAppendable Error if the object is not Appendable, returns the next append position, the hash crc64ecma and the ETag if success.

The first optional Params is for Header, the second is for Query.

The data's type must be []byte, *[]byte, *os.File, *bytes.Buffer, *bytes.Reader or *strings.Reader.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/object&AppendObject

func (Object) CompleteMultipartUpload

func (o Object) CompleteMultipartUpload(uploadId string, parts CompleteMultipartUpload, args ...Params) (*CompleteMultipartUploadResult, error)

CompleteMultipartUpload complete the Multipart Upload given a uploadId, all the partNumbers and ETags.

The first optional Params is for Header, the second is for Query.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/multipart-upload&CompleteMultipartUpload

func (Object) Copy

func (o Object) Copy(source Object, args ...Params) (*CopyObjectResult, error)

Copy the object content from the source object, also send the ACL if it is not the empty string.

The first optional Params is for Header, the second is for Query.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/object&CopyObject

func (Object) Delete

func (o Object) Delete(args ...Params) error

Delete the object.

The first optional Params is for Header, the second is for Query.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/object&DeleteObject

func (Object) Do

func (o Object) Do(method string, body, v interface{}, args ...Params) error

Do sends an HTTP request to OSS and read the HTTP response to v.

The first optional Params is for Header, the second is for Query.

Overwritten the Bucket.Do with the object name.

func (Object) FullName

func (o Object) FullName() string

FullName returns the string "/BucketName/ObjectName".

If the bucket name or the object name is invalid returns the empty string.

func (Object) Get

func (o Object) Get(data interface{}, args ...Params) error

Get the object content to the data.

The first optional Params is for Header, the second is for Query.

The data's type must be *[]byte, *os.File, *bytes.Buffer

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/object&GetObject

func (Object) GetACL

func (o Object) GetACL(args ...Params) (string, error)

GetACL returns the object ACL, if not set returns "default".

The first optional Params is for Header, the second is for Query.

Get and record:

o.ACL, err = o.GetACL()

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/object&GetObjectACL

func (Object) GetInfo

func (o Object) GetInfo(args ...Params) (*GetObjectInfoResult, error)

GetInfo returns the object info.

The first optional Params is for Header, the second is for Query.

func (Object) GetRequest

func (o Object) GetRequest(method string, body interface{}, args ...Params) (*http.Request, error)

GetRequest returns a new http.Request given a method and body.

The first optional Params is for Header, the second is for Query.

Overwritten the Bucket.GetRequest with the object name.

func (Object) GetResponse

func (o Object) GetResponse(method string, body interface{}, args ...Params) (*http.Response, error)

GetResponse sends an HTTP request to OSS and returns the HTTP response.

The first optional Params is for Header, the second is for Query.

Overwritten the Bucket.GetResponse with the object name.

func (Object) Head

func (o Object) Head(args ...Params) (http.Header, error)

Head the object and returns the response header.

The first optional Params is for Header, the second is for Query.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/object&HeadObject

func (Object) InitiateMultipartUpload

func (o Object) InitiateMultipartUpload(args ...Params) (*InitiateMultipartUploadResult, error)

InitiateMultipartUpload initialize a Multipart Upload event.

The first optional Params is for Header, the second is for Query.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/multipart-upload&InitiateMultipartUpload

func (Object) ListParts

func (o Object) ListParts(uploadId string, args ...Params) (*ListPartsResult, error)

ListParts returns the already uploaded parts given a uploadId.

The first optional Params is for Header, the second is for Query.

Query predefine parameters: max-parts, part-number-marker, encoding-type.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/multipart-upload&ListParts

func (Object) Options

func (o Object) Options(args ...Params) (http.Header, error)

Options the object and returns the response header.

The first optional Params is for Header, the second is for Query.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/cors&OptionObject

func (Object) Put

func (o Object) Put(data interface{}, args ...Params) (string, error)

Put the data as the object content, also send the ACL if it is not the empty string, returns the ETag.

The first optional Params is for Header, the second is for Query.

The data's type must be []byte, *[]byte, *os.File, *bytes.Buffer, *bytes.Reader or *strings.Reader.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/object&PutObject

func (Object) PutACL

func (o Object) PutACL(args ...Params) error

PutACL change the object acl if it is the empty string.

The first optional Params is for Header, the second is for Query.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/object&PutObjectACL

func (Object) Range

func (o Object) Range(first, length int64, data interface{}, args ...Params) (int64, int64, error)

Range get the object range content to the data given the first-byte-pos and the length, returns the range-length and the instance-length.

The range-length is less than or equal to the given length. The first-byte-pos add the range-length equal the instance-length indicate EOF.

The first optional Params is for Header, the second is for Query.

The data's type must be *[]byte, *os.File, *bytes.Buffer

The last range must be given exact length or length <= 0, because OSS not support last-byte-pos greater than or equal to the instance-length.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/object&GetObject

func (Object) UploadPart

func (o Object) UploadPart(partNumber int, uploadId string, data interface{}, args ...Params) (string, error)

UploadPart upload the data as a part given a partNumber and a uploadId returns the ETag.

The first optional Params is for Header, the second is for Query.

The partNumber must be gte 1 and lte 10000. The data's type must be []byte, *[]byte, *os.File, *bytes.Buffer, *bytes.Reader or *strings.Reader.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/multipart-upload&UploadPart

func (Object) UploadPartCopy

func (o Object) UploadPartCopy(partNumber int, uploadId string, source Object, args ...Params) (*CopyPartResult, error)

UploadPartCopy upload a part copy from the source object given a partNumber and a uploadId returns the ETag.

The first optional Params is for Header, the second is for Query.

The partNumber must be gte 1 and lte 10000.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/multipart-upload&UploadPartCopy

type Owner

type Owner struct {
	ID          string
	DisplayName string
}

Owner contains the information of the bucket owner.

type Params

type Params map[string][]string

A Params represents the http.Header or the url.Values.

func (Params) Add

func (args Params) Add(key, value string)

Add adds the value to key. It appends to any existing values associated with key.

func (Params) Copy

func (args Params) Copy(params Params)

Copy all the params's keys and values to args.

func (Params) Del

func (args Params) Del(key string)

Del deletes the values associated with key.

func (Params) Get

func (args Params) Get(key string) string

Get gets the first value associated with the given key. If there are no values associated with the key, Get returns the empty string. To access multiple values, use the map directly.

func (Params) Header

func (args Params) Header() http.Header

Header convert Params to http.Header.

func (Params) Set

func (args Params) Set(key, value string)

Set sets the key to value. It replaces any existing values.

func (Params) Values

func (args Params) Values() url.Values

Values convert Params to url.Values.

type RefererConfiguration

type RefererConfiguration struct {
	AllowEmptyReferer bool
	RefererList       struct {
		Referer []string
	}
}

RefererConfiguration represents the referer white list configuration.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/bucket&PutBucketReferer https://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucketReferer

type Service

type Service struct {
	Unsafe          bool
	Domain          string
	AccessKeyId     string
	AccessKeySecret string
	SecurityToken   string // STS
}

Service represents Aliyun Object Storage Service, the AccessKeyId and the AccessKeySecret are required.

func NewService

func NewService(accessKeyId, accessKeySecret string) Service

NewService returns a new Service given a accessKeyId and accessKeySecret.

func (Service) Do

func (s Service) Do(method, bucket, object string, body, v interface{}, args ...Params) error

Do sends an HTTP request to OSS and read the HTTP response to v.

The first optional Params is for Header, the second is for Query.

See the method GetResponse and the function ReadBody to get more.

func (Service) GetRequest

func (s Service) GetRequest(method, bucket, object string, body interface{}, args ...Params) (*http.Request, error)

GetRequest returns a new http.Request given a method and optional butcket, object, body.

The first optional Params is for Header, the second is for Query.

A nil body means no body, if the body's type is not []byte, *[]byte, *os.File, *bytes.Buffer, *bytes.Reader and *strings.Reader then encode XML as the body.

The headers Content-Type and Content-Md5 will be set, when encode XML as the body or the body's type is []byte, *[]byte, *bytes.Buffer.

It does not close the *os.File body.

To signature the request call the method Signature.

func (Service) GetResponse

func (s Service) GetResponse(method, bucket, object string, body interface{}, args ...Params) (*http.Response, error)

GetResponse sends an HTTP request to OSS and returns the HTTP response.

The first optional Params is for Header, the second is for Query.

See the method GetRequest to get more.

func (Service) Host

func (s Service) Host() string

Host returns the OSS access domain.

func (Service) ListBucket

func (s Service) ListBucket(args ...Params) (*ListAllMyBucketsResult, error)

ListBucket returns all the buckets.

The first optional Params is for Header, the second is for Query.

Query predefine parameters: prefix, marker, max-keys.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/service&GetService

func (Service) NewBucket

func (s Service) NewBucket(bucketName string) Bucket

NewBucket returns a new Bucket given a bucketName from the service.

func (Service) Scheme

func (s Service) Scheme() string

Scheme returns http if the Unsafe is ture otherwise returns https.

func (Service) Signature

func (s Service) Signature(req *http.Request, seconds int)

Signature url if the seconds > 0 and the Date Header add the seconds as the expires, otherwise signature and set the Authorization header.

If the SecurityToken is not the empty string, then STS be supported.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/access-control&signature-header https://docs.aliyun.com/#/pub/oss/api-reference/access-control&signature-url

type WebsiteConfiguration

type WebsiteConfiguration struct {
	IndexDocument struct {
		Suffix string
	}
	ErrorDocument struct {
		Key string
	}
}

WebsiteConfiguration represents the static site configuration.

Relevant documentation:

https://docs.aliyun.com/#/pub/oss/api-reference/bucket&PutBucketWebsite https://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucketWebsite

Directories

Path Synopsis
Aliyun OSS Go SDK Examples - Bucket Operations Aliyun OSS Go SDK Examples - List Bucket Aliyun OSS Go SDK Examples - Multipart Upload File Aliyun OSS Go SDK Examples - Object Operations Aliyun OSS Go SDK Examples - Object Range Get
Aliyun OSS Go SDK Examples - Bucket Operations Aliyun OSS Go SDK Examples - List Bucket Aliyun OSS Go SDK Examples - Multipart Upload File Aliyun OSS Go SDK Examples - Object Operations Aliyun OSS Go SDK Examples - Object Range Get

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL