cos

package
v0.0.0-...-f8cb937 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2018 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HTTPHeaderAcceptEncoding     string = "Accept-Encoding"
	HTTPHeaderAuthorization             = "Authorization"
	HTTPHeaderCacheControl              = "Cache-Control"
	HTTPHeaderContentDisposition        = "Content-Disposition"
	HTTPHeaderContentEncoding           = "Content-Encoding"
	HTTPHeaderContentLength             = "Content-Length"
	HTTPHeaderContentMD5                = "Content-MD5"
	HTTPHeaderContentType               = "Content-Type"
	HTTPHeaderContentLanguage           = "Content-Language"
	HTTPHeaderDate                      = "Date"
	HTTPHeaderEtag                      = "ETag"
	HTTPHeaderExpires                   = "Expires"
	HTTPHeaderHost                      = "Host"
	HTTPHeaderLastModified              = "Last-Modified"
	HTTPHeaderRange                     = "Range"
	HTTPHeaderLocation                  = "Location"
	HTTPHeaderOrigin                    = "Origin"
	HTTPHeaderServer                    = "Server"
	HTTPHeaderUserAgent                 = "User-Agent"
	HTTPHeaderIfModifiedSince           = "If-Modified-Since"
	HTTPHeaderIfUnmodifiedSince         = "If-Unmodified-Since"
	HTTPHeaderIfMatch                   = "If-Match"
	HTTPHeaderIfNoneMatch               = "If-None-Match"

	HTTPHeaderOssACL                         = "X-Oss-Acl"
	HTTPHeaderOssMetaPrefix                  = "X-Oss-Meta-"
	HTTPHeaderOssObjectACL                   = "X-Oss-Object-Acl"
	HTTPHeaderOssSecurityToken               = "X-Oss-Security-Token"
	HTTPHeaderOssServerSideEncryption        = "X-Oss-Server-Side-Encryption"
	HTTPHeaderOssCopySource                  = "X-Oss-Copy-Source"
	HTTPHeaderOssCopySourceRange             = "X-Oss-Copy-Source-Range"
	HTTPHeaderOssCopySourceIfMatch           = "X-Oss-Copy-Source-If-Match"
	HTTPHeaderOssCopySourceIfNoneMatch       = "X-Oss-Copy-Source-If-None-Match"
	HTTPHeaderOssCopySourceIfModifiedSince   = "X-Oss-Copy-Source-If-Modified-Since"
	HTTPHeaderOssCopySourceIfUnmodifiedSince = "X-Oss-Copy-Source-If-Unmodified-Since"
	HTTPHeaderOssMetadataDirective           = "X-Oss-Metadata-Directive"
	HTTPHeaderOssNextAppendPosition          = "X-Oss-Next-Append-Position"
	HTTPHeaderOssRequestID                   = "X-Oss-Request-Id"
	HTTPHeaderOssCRC64                       = "X-Oss-Hash-Crc64ecma"
	HTTPHeaderOssSymlinkTarget               = "X-Oss-Symlink-Target"
)

HTTP headers

View Source
const (
	QSignAlgorithm = "q-sign-algorithm"
	QAK            = "q-ak"
	QSignTime      = "q-sign-time"
	QKeyTime       = "q-key-time"
	QHeaderList    = "q-header-list"
	QUrlParamList  = "q-url-param-list"
	QSign          = "q-signature"

	SignAlgorithm = "sha1"

	URLSignPara = "sign"
)
View Source
const DefaultSignExpireTime = 86400

Variables

View Source
var (
	ErrForbidden = errors.New("bad athuntication")
	ErrNotFound  = errors.New("not found")
)

Functions

func CreateRandomString

func CreateRandomString() string

CreateRandomString create random string

func CreateSignature

func CreateSignature(stringToSignature, accessKeySecret string) string

CreateSignature creates signature for string

func Encode

func Encode(v url.Values) string

Encode encodes the values into “URL encoded” form ("acl&bar=baz&foo=quux") sorted by key.

func GetGMTime

func GetGMTime() string

func GetNowNanoSec

func GetNowNanoSec() int64

GetNowNanoSec returns t as a Unix time, the number of nanoseconds elapsed since January 1, 1970 UTC. The result is undefined if the Unix time in nanoseconds cannot be represented by an int64. Note that this means the result of calling UnixNano on the zero Time is undefined. 获取当前时间,从UTC开始的纳秒。

func GetNowSec

func GetNowSec() int64

GetNowSec returns Unix time, the number of seconds elapsed since January 1, 1970 UTC. 获取当前时间,从UTC开始的秒数。

func GetURIPath

func GetURIPath(u *url.URL) string

func IsNotFoundError

func IsNotFoundError(err error) bool

IsNotFoundError return true if the error is 404 error

func MakeSha1

func MakeSha1(data string) string

func NewRequest

func NewRequest(method, urlStr string) (*request, error)

Types

type Bucket

type Bucket struct {
	*Client
	// contains filtered or unexported fields
}

func NewBucketFromURL

func NewBucketFromURL(url string, client *Client) *Bucket

func (*Bucket) DeleteObject

func (b *Bucket) DeleteObject(key string) error

func (*Bucket) DoGetObject

func (b *Bucket) DoGetObject(key string, options ...Option) (*GetObjectResult, error)

func (*Bucket) Exists

func (b *Bucket) Exists() (bool, error)

func (*Bucket) GetObject

func (b *Bucket) GetObject(key string, options ...Option) (io.ReadCloser, error)

func (*Bucket) GetObjectMeta

func (b *Bucket) GetObjectMeta(key string) (http.Header, error)

func (*Bucket) ListObjects

func (b *Bucket) ListObjects(options ...Option) (*ListObjectsResult, error)

func (*Bucket) PutObject

func (b *Bucket) PutObject(key string, body interface{}, options ...Option) error

PutObject upload a file, body could be io.Reader, []byte, string

type Client

type Client struct {
	*req.Req
	SecretId  string
	SecretKey string
}

func NewClient

func NewClient(secretId, secretKey string) *Client

func (*Client) Do

func (client *Client) Do(req *request, options ...Option) (*req.Resp, error)

type Error

type Error struct {
	StatusCode int    // HTTP status code (200, 403, ...)
	Code       string // COS error code ("UnsupportedOperation", ...)
	Message    string // The human-oriented error message
	Resource   string
	RequestId  string
	TraceId    string
}

func (*Error) Error

func (e *Error) Error() string

type GetObjectResult

type GetObjectResult struct {
	Response *http.Response
}

GetObjectResult is the result of DoGetObject

type ListObjectsResult

type ListObjectsResult struct {
	XMLName xml.Name `xml:"ListBucketResult"`
	Name    string   `xml:"Name"`
	Prefix  string   `xml:"Prefix"`
	Marker  string   `xml:"Marker"`
	MaxKeys int      `xml:"MaxKeys"`
	// IsTruncated is true if the results have been truncated because
	// there are more keys and prefixes than can fit in MaxKeys.
	// N.B. this is the opposite sense to that documented (incorrectly) in
	// http://goo.gl/YjQTc
	IsTruncated    bool               `xml:"IsTruncated"`
	Objects        []ObjectProperties `xml:"Contents"`
	CommonPrefixes []string           `xml:"CommonPrefixes>Prefix"`
	// if IsTruncated is true, pass NextMarker as marker argument to List()
	// to get the next set of keys
	NextMarker string `xml:"NextMarker"`
}

The ListObjectsResult type holds the results of a List bucket operation.

type ObjectProperties

type ObjectProperties struct {
	XMLName      xml.Name  `xml:"Contents"`
	Key          string    `xml:"Key"`          // Object key
	LastModified time.Time `xml:"LastModified"` // Object last modified time
	Size         int64     `xml:"Size"`         // Object size
	// ETag gives the hex-encoded MD5 sum of the contents,
	// surrounded with double-quotes.
	ETag         string `xml:"ETag"`         // Object ETag
	Owner        Owner  `xml:"Owner"`        // Object owner information
	StorageClass string `xml:"StorageClass"` // Object storage class (Standard, IA, Archive)
}

The ObjectProperties type represents an item stored in an bucket.

type Option

type Option func(*request) error

func Body

func Body(body interface{}) Option

func ContentType

func ContentType(contentType string) Option

func Delimiter

func Delimiter(delimiter string) Option

func Marker

func Marker(marker string) Option

func MaxKeys

func MaxKeys(maxKeys int) Option

func Prefix

func Prefix(prefix string) Option

type Owner

type Owner struct {
	XMLName     xml.Name `xml:"Owner"`
	ID          string   `xml:"ID"`
	DisplayName string   `xml:"DisplayName"`
}

The Owner type represents the owner of the object in an bucket.

Jump to

Keyboard shortcuts

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