yos

package module
v0.0.0-...-13807bc Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2022 License: MIT Imports: 31 Imported by: 0

README

yos-go

You Object Storage Go Client

Documentation

Index

Constants

View Source
const (
	MaxJitter = 1.0
	NoJitter  = 0.0
)
View Source
const (
	ServiceTypeS3  = "s3"
	ServiceTypeSTS = "sts"
)
View Source
const (
	KB
	MB
	GB
	TB
	PB
	EB
)

Variables

View Source
var (
	MaxRetry         = 10
	DefaultRetryUnit = 200 * time.Millisecond
	DefaultRetryCap  = time.Second
)
View Source
var DefaultTransport = func(secure bool) (*http.Transport, error) {
	tr := &http.Transport{
		Proxy: http.ProxyFromEnvironment,
		DialContext: (&net.Dialer{
			Timeout:   30 * time.Second,
			KeepAlive: 30 * time.Second,
		}).DialContext,
		MaxIdleConns:          256,
		MaxIdleConnsPerHost:   16,
		ResponseHeaderTimeout: time.Minute,
		IdleConnTimeout:       time.Minute,
		TLSHandshakeTimeout:   10 * time.Second,
		ExpectContinueTimeout: 10 * time.Second,
		DisableCompression:    true,
	}
	if secure {
		tr.TLSClientConfig = &tls.Config{
			MinVersion: tls.VersionTLS12,
		}
	}
	return tr, nil
}

Functions

func CanonicalizeETag

func CanonicalizeETag(etag string) string

func CopySeekableBody

func CopySeekableBody(dst io.Writer, src io.ReadSeeker) (int64, error)

func EncodePath

func EncodePath(pathName string) string

func GetRegionFromURL

func GetRegionFromURL(endpointURL url.URL) string

func IsAliyunOSSEndpoint

func IsAliyunOSSEndpoint(endpointURL url.URL) bool

IsAliyunOSSEndpoint - Match if it is exactly Aliyun OSS endpoint.

func IsAmazonEndpoint

func IsAmazonEndpoint(endpointURL url.URL) bool

IsAmazonEndpoint - Match if it is exactly Amazon S3 endpoint.

func IsAmazonFIPSGovCloudEndpoint

func IsAmazonFIPSGovCloudEndpoint(endpointURL url.URL) bool

See https://aws.amazon.com/compliance/fips.

func IsAmazonGovCloudEndpoint

func IsAmazonGovCloudEndpoint(endpointURL url.URL) bool

IsAmazonGovCloudEndpoint - Match if it is exactly Amazon S3 GovCloud endpoint.

func IsQiniuKodoEndpoint

func IsQiniuKodoEndpoint(endpointURL url.URL) bool

IsQiniuKodoEndpoint - Match if it is exactly qiniu KODO endpoint.

func IsReaderSeekable

func IsReaderSeekable(r io.Reader) bool

func IsVirtualHostSupported

func IsVirtualHostSupported(endpointURL url.URL, bucketName string) bool

func PreSignV4

func PreSignV4(req http.Request, accessKeyID, secretAccessKey, sessionToken, location string, expires int64) *http.Request

func QueryEncode

func QueryEncode(v url.Values) string

func SeekerLen

func SeekerLen(s io.Seeker) (int64, error)

func SignServiceV4

func SignServiceV4(req http.Request, body io.ReadSeeker, accessKeyID, secretAccessKey, sessionToken, location, serviceType string) *http.Request

func SignV4

func SignV4(req http.Request, accessKeyID, secretAccessKey, sessionToken, location string) *http.Request

http://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-authenticating-requests.html.

func StreamingChunkSignV4

func StreamingChunkSignV4(req *http.Request, accessKeyID, secretAccessKey, sessionToken,
	region string, dataLen int64, reqTime time.Time) *http.Request

StreamingSignV4 - provides chunked upload signatureV4 support by implementing io.Reader.

func StreamingSignV4

func StreamingSignV4(req *http.Request, accessKeyID, secretAccessKey, sessionToken,
	region string, dataLen int64, reqTime time.Time) *http.Request

func TagDecode

func TagDecode(ctag string) map[string]string

func TagEncode

func TagEncode(tags map[string]string) string

func UTCNow

func UTCNow() time.Time

func UnescapePath

func UnescapePath(p string) (string, error)

func XmlDecoder

func XmlDecoder(body io.Reader, v interface{}, size int64) error

Types

type Client

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

func NewClient

func NewClient(endpoint string, creds *Credentials, opts ...ClientOption) (*Client, error)

func (*Client) EndpointURL

func (c *Client) EndpointURL() *url.URL

type ClientOption

type ClientOption interface {
	// contains filtered or unexported methods
}

type CommonPrefix

type CommonPrefix struct {
	Prefix string
}

type CompleteMultipartUpload

type CompleteMultipartUpload struct {
	Parts []CompletePart `xml:"Part"`
}

type CompletePart

type CompletePart struct {
	XMLName    xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ Part" json:"-"`
	PartNumber int
	ETag       string
}

type CompletedParts

type CompletedParts []CompletePart

func (CompletedParts) Len

func (a CompletedParts) Len() int

func (CompletedParts) Less

func (a CompletedParts) Less(i, j int) bool

func (CompletedParts) Swap

func (a CompletedParts) Swap(i, j int)

type CopySrcOptions

type CopySrcOptions struct {
	Bucket, Object       string
	VersionID            string
	MatchETag            string
	NoMatchETag          string
	MatchModifiedSince   time.Time
	MatchUnmodifiedSince time.Time
	MatchRange           bool
	Start, End           int64
}

type Credentials

type Credentials struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewCredentials

func NewCredentials(provider Provider) *Credentials

func NewStatic

func NewStatic(id, secret, token string) *Credentials

func NewStaticV4

func NewStaticV4(id, secret, token string) *Credentials

func (*Credentials) Expire

func (c *Credentials) Expire()

func (*Credentials) Get

func (c *Credentials) Get() (Value, error)

func (*Credentials) IsExpired

func (c *Credentials) IsExpired() bool

type ErrorResponse

type ErrorResponse struct {
	XMLName    xml.Name `xml:"Error" json:"-"`
	Code       string
	Message    string
	BucketName string
	Key        string
	RequestID  string `xml:"RequestId"`
	HostID     string `xml:"HostId"`
	Region     string
	Server     string
	StatusCode int `xml:"-" json:"-"`
}

golang http API (https://github.com/golang/go/issues/29768)

func ToErrorResponse

func ToErrorResponse(err error) ErrorResponse

func (ErrorResponse) Error

func (e ErrorResponse) Error() string

Error - Returns S3 error string.

type GetObjectOptions

type GetObjectOptions struct {
	VersionID  string
	Decryption bool
	// contains filtered or unexported fields
}

during GET requests.

func (GetObjectOptions) Header

func (o GetObjectOptions) Header() http.Header

func (*GetObjectOptions) Set

func (o *GetObjectOptions) Set(key, value string)

func (*GetObjectOptions) SetMatchETag

func (o *GetObjectOptions) SetMatchETag(etag string) error

SetMatchETag - set match etag.

func (*GetObjectOptions) SetMatchETagExcept

func (o *GetObjectOptions) SetMatchETagExcept(etag string) error

func (*GetObjectOptions) SetModified

func (o *GetObjectOptions) SetModified(modTime time.Time) error

func (*GetObjectOptions) SetRange

func (o *GetObjectOptions) SetRange(start, end int64) error

See https://tools.ietf.org/html/rfc7233#section-3.1 for reference.

func (*GetObjectOptions) SetUnmodified

func (o *GetObjectOptions) SetUnmodified(modTime time.Time) error

type HTTPRangeSpec

type HTTPRangeSpec struct {
	IsSuffixLength bool
	Start, End     int64
}

func ParseRequestRangeSpec

func ParseRequestRangeSpec(rangeString string) (hrange *HTTPRangeSpec, err error)

func (*HTTPRangeSpec) GetLength

func (h *HTTPRangeSpec) GetLength(resourceSize int64) (rangeLength int64, err error)

func (*HTTPRangeSpec) GetOffsetLength

func (h *HTTPRangeSpec) GetOffsetLength(resourceSize int64) (start, length int64, err error)

func (*HTTPRangeSpec) String

func (h *HTTPRangeSpec) String(resourceSize int64) string

type Hasher

type Hasher interface {
	hash.Hash
	Close()
}

type InitiateMultipartUploadResult

type InitiateMultipartUploadResult struct {
	Bucket   string
	Key      string
	UploadID string `xml:"UploadId"`
}

type ListBucketResult

type ListBucketResult struct {
	CommonPrefixes []CommonPrefix
	Contents       []ObjectInfo
	Delimiter      string
	EncodingType   string
	IsTruncated    bool
	Marker         string
	MaxKeys        int64
	Name           string
	NextMarker     string
	Prefix         string
}

type ListBucketV2Result

type ListBucketV2Result struct {
	CommonPrefixes        []CommonPrefix
	Contents              []ObjectInfo
	Delimiter             string
	EncodingType          string
	IsTruncated           bool
	MaxKeys               int64
	Name                  string
	NextContinuationToken string
	ContinuationToken     string
	Prefix                string
	FetchOwner            string
	StartAfter            string
}

type ListMultipartUploadsResult

type ListMultipartUploadsResult struct {
	Bucket             string
	KeyMarker          string
	UploadIDMarker     string `xml:"UploadIdMarker"`
	NextKeyMarker      string
	NextUploadIDMarker string `xml:"NextUploadIdMarker"`
	EncodingType       string
	MaxUploads         int64
	IsTruncated        bool
	Uploads            []ObjectMultipartInfo `xml:"Upload"`
	Prefix             string
	Delimiter          string
	// A response can contain CommonPrefixes only if you specify a delimiter.
	CommonPrefixes []CommonPrefix
}

type ListObjectPartsResult

type ListObjectPartsResult struct {
	Bucket   string
	Key      string
	UploadID string `xml:"UploadId"`

	Initiator initiator
	Owner     owner

	StorageClass         string
	PartNumberMarker     int
	NextPartNumberMarker int
	MaxParts             int

	// Indicates whether the returned list of parts is truncated.
	IsTruncated bool
	ObjectParts []ObjectPart `xml:"Part"`

	EncodingType string
}

type MultiCloser

type MultiCloser []io.Closer

func (MultiCloser) Close

func (m MultiCloser) Close() error

type ObjectInfo

type ObjectInfo struct {
	// An ETag is optionally set to md5sum of an object.  In case of multipart objects,
	// ETag is of the form MD5SUM-N where MD5SUM is md5sum of all individual md5sums of
	// each parts concatenated into one string.
	ETag string `json:"etag"`

	Key          string    `json:"name"`         // Name of the object
	LastModified time.Time `json:"lastModified"` // Date and time the object was last modified.
	Size         int64     `json:"size"`         // Size in bytes of the object.
	ContentType  string    `json:"contentType"`  // A standard MIME type describing the format of the object data.
	Expires      time.Time `json:"expires"`      // The date and time at which the object is no longer able to be cached.

	// Collection of additional metadata on the object.
	// eg: x-amz-meta-*, content-encoding etc.
	Metadata http.Header `json:"metadata" xml:"-"`

	// x-amz-meta-* headers stripped "x-amz-meta-" prefix containing the first value.
	UserMetadata StringMap `json:"userMetadata"`

	// x-amz-tagging values in their k/v values.
	UserTags map[string]string `json:"userTags"`

	// x-amz-tagging-count value
	UserTagCount int

	// Owner name.
	Owner Owner

	// ACL grant.
	Grant []struct {
		Grantee struct {
			ID          string `xml:"ID"`
			DisplayName string `xml:"DisplayName"`
			URI         string `xml:"URI"`
		} `xml:"Grantee"`
		Permission string `xml:"Permission"`
	} `xml:"Grant"`

	// The class of storage used to store the object.
	StorageClass string `json:"storageClass"`

	// Versioning related information
	IsLatest       bool
	IsDeleteMarker bool
	VersionID      string `xml:"VersionId"`

	// x-amz-replication-status value is either in one of the following states
	// - COMPLETE
	// - PENDING
	// - FAILED
	// - REPLICA (on the destination)
	ReplicationStatus string `xml:"ReplicationStatus"`

	// Lifecycle expiry-date and ruleID associated with the expiry
	// not to be confused with `Expires` HTTP header.
	Expiration       time.Time
	ExpirationRuleID string

	// Error
	Err error `json:"-"`
}

func ToObjectInfo

func ToObjectInfo(bucketName string, objectName string, h http.Header) (ObjectInfo, error)

type ObjectMultipartInfo

type ObjectMultipartInfo struct {
	// Date and time at which the multipart upload was initiated.
	Initiated time.Time `type:"timestamp" timestampFormat:"iso8601"`

	Initiator initiator
	Owner     owner

	// The type of storage to use for the object. Defaults to 'STANDARD'.
	StorageClass string

	// Key of the object for which the multipart upload was initiated.
	Key string

	// Size in bytes of the object.
	Size int64

	// Upload ID that identifies the multipart upload.
	UploadID string `xml:"UploadId"`

	// Error
	Err error
}

type ObjectPart

type ObjectPart struct {
	// Part number identifies the part.
	PartNumber int

	// Date and time the part was uploaded.
	LastModified time.Time

	// Entity tag returned when the part was uploaded, usually md5sum
	// of the part.
	ETag string

	// Size of the uploaded part data.
	Size int64
}

type Owner

type Owner struct {
	DisplayName string `json:"name"`
	ID          string `json:"id"`
}

Owner name.

type Provider

type Provider interface {
	Retrieve() (Value, error)
	IsExpired() bool
}

type PutObjectOptions

type PutObjectOptions struct {
	UserMetadata            map[string]string
	UserTags                map[string]string
	Progress                io.Reader
	ContentType             string
	ContentEncoding         string
	ContentDisposition      string
	ContentLanguage         string
	CacheControl            string
	RetainUntilDate         time.Time
	NumThreads              uint
	StorageClass            string
	WebsiteRedirectLocation string
	PartSize                uint64
	SendContentMd5          bool
	DisableMultipart        bool
}

func (PutObjectOptions) Header

func (opts PutObjectOptions) Header() (header http.Header)

Header - constructs the headers from metadata entered by user in PutObjectOptions struct

type ReaderSeekerCloser

type ReaderSeekerCloser struct {
	// contains filtered or unexported fields
}

func ReadSeekCloser

func ReadSeekCloser(r io.Reader) ReaderSeekerCloser

func (ReaderSeekerCloser) Close

func (r ReaderSeekerCloser) Close() error

func (ReaderSeekerCloser) GetLen

func (r ReaderSeekerCloser) GetLen() (int64, error)

func (ReaderSeekerCloser) HasLen

func (r ReaderSeekerCloser) HasLen() (int, bool)

func (ReaderSeekerCloser) IsSeeker

func (r ReaderSeekerCloser) IsSeeker() bool

func (ReaderSeekerCloser) Read

func (r ReaderSeekerCloser) Read(p []byte) (int, error)

func (ReaderSeekerCloser) Seek

func (r ReaderSeekerCloser) Seek(offset int64, whence int) (int64, error)

type RemoveObjectOptions

type RemoveObjectOptions struct {
	GovernanceBypass bool
	VersionID        string
}

type StatObjectOptions

type StatObjectOptions = GetObjectOptions

type Static

type Static struct {
	Value
}

func (*Static) IsExpired

func (s *Static) IsExpired() bool

func (*Static) Retrieve

func (s *Static) Retrieve() (Value, error)

type StreamingChunkReader

type StreamingChunkReader struct {
	// contains filtered or unexported fields
}

func (*StreamingChunkReader) Close

func (s *StreamingChunkReader) Close() error

func (*StreamingChunkReader) Read

func (s *StreamingChunkReader) Read(buf []byte) (int, error)

type StreamingReader

type StreamingReader struct {
	// contains filtered or unexported fields
}

type StringMap

type StringMap map[string]string

func (*StringMap) UnmarshalXML

func (m *StringMap) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type UploadInfo

type UploadInfo struct {
	Bucket           string
	Key              string
	ETag             string
	Size             int64
	LastModified     time.Time
	Location         string
	VersionID        string
	Expiration       time.Time
	ExpirationRuleID string
}

type Value

type Value struct {
	AccessKeyID     string
	SecretAccessKey string
	SessionToken    string
}

type WriteAtBuffer

type WriteAtBuffer struct {
	GrowthCoeff float64
	// contains filtered or unexported fields
}

func NewWriteAtBuffer

func NewWriteAtBuffer(buf []byte) *WriteAtBuffer

func (*WriteAtBuffer) Bytes

func (b *WriteAtBuffer) Bytes() []byte

func (*WriteAtBuffer) WriteAt

func (b *WriteAtBuffer) WriteAt(p []byte, pos int64) (n int, err error)

Jump to

Keyboard shortcuts

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