code
stringlengths
11
335k
docstring
stringlengths
20
11.8k
func_name
stringlengths
1
100
language
stringclasses
1 value
repo
stringclasses
245 values
path
stringlengths
4
144
url
stringlengths
43
214
license
stringclasses
4 values
func TeeReader(reader io.Reader, writer io.Writer, totalBytes int64, listener ProgressListener, tracker *readerTracker) io.ReadCloser { return &teeReader{ reader: reader, writer: writer, listener: listener, consumedBytes: 0, totalBytes: totalBytes, tracker: tracker, } }
TeeReader returns a Reader that writes to w what it reads from r. All reads from r performed through it are matched with corresponding writes to w. There is no internal buffering - the write must complete before the read completes. Any error encountered while writing is reported as a read error.
TeeReader
go
aliyun/aliyun-oss-go-sdk
oss/progress.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/progress.go
MIT
func (s *OssCopySuite) SetUpSuite(c *C) { bucketName := bucketNamePrefix + RandLowStr(6) if cloudboxControlEndpoint == "" { client, err := New(endpoint, accessID, accessKey) c.Assert(err, IsNil) s.client = client s.client.CreateBucket(bucketName) bucket, err := s.client.Bucket(bucketName) c.Assert(err, IsNil) s.bucket = bucket } else { client, err := New(cloudboxEndpoint, accessID, accessKey) c.Assert(err, IsNil) s.client = client controlClient, err := New(cloudboxControlEndpoint, accessID, accessKey) c.Assert(err, IsNil) s.cloudBoxControlClient = controlClient controlClient.CreateBucket(bucketName) bucket, err := s.client.Bucket(bucketName) c.Assert(err, IsNil) s.bucket = bucket } testLogger.Println("test copy started") }
SetUpSuite runs once when the suite starts running
SetUpSuite
go
aliyun/aliyun-oss-go-sdk
oss/multicopy_test.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/multicopy_test.go
MIT
func (s *OssCopySuite) TearDownSuite(c *C) { // Delete Part keyMarker := KeyMarker("") uploadIDMarker := UploadIDMarker("") for { lmur, err := s.bucket.ListMultipartUploads(keyMarker, uploadIDMarker) c.Assert(err, IsNil) for _, upload := range lmur.Uploads { var imur = InitiateMultipartUploadResult{Bucket: bucketName, Key: upload.Key, UploadID: upload.UploadID} err = s.bucket.AbortMultipartUpload(imur) c.Assert(err, IsNil) } keyMarker = KeyMarker(lmur.NextKeyMarker) uploadIDMarker = UploadIDMarker(lmur.NextUploadIDMarker) if !lmur.IsTruncated { break } } // Delete objects marker := Marker("") for { lor, err := s.bucket.ListObjects(marker) c.Assert(err, IsNil) for _, object := range lor.Objects { err = s.bucket.DeleteObject(object.Key) c.Assert(err, IsNil) } marker = Marker(lor.NextMarker) if !lor.IsTruncated { break } } // Delete bucket if s.cloudBoxControlClient != nil { err := s.cloudBoxControlClient.DeleteBucket(s.bucket.BucketName) c.Assert(err, IsNil) } else { err := s.client.DeleteBucket(s.bucket.BucketName) c.Assert(err, IsNil) } testLogger.Println("test copy completed") }
TearDownSuite runs before each test or benchmark starts running
TearDownSuite
go
aliyun/aliyun-oss-go-sdk
oss/multicopy_test.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/multicopy_test.go
MIT
func (s *OssCopySuite) SetUpTest(c *C) { err := removeTempFiles("../oss", ".jpg") c.Assert(err, IsNil) }
SetUpTest runs after each test or benchmark runs
SetUpTest
go
aliyun/aliyun-oss-go-sdk
oss/multicopy_test.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/multicopy_test.go
MIT
func (s *OssCopySuite) TearDownTest(c *C) { err := removeTempFiles("../oss", ".jpg") c.Assert(err, IsNil) }
TearDownTest runs once after all tests or benchmarks have finished running
TearDownTest
go
aliyun/aliyun-oss-go-sdk
oss/multicopy_test.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/multicopy_test.go
MIT
func CopyErrorHooker(part copyPart) error { if part.Number == 5 { time.Sleep(time.Second) return fmt.Errorf("ErrorHooker") } return nil }
CopyErrorHooker is a copypart request hook
CopyErrorHooker
go
aliyun/aliyun-oss-go-sdk
oss/multicopy_test.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/multicopy_test.go
MIT
func (conn Conn) getAdditionalHeaderKeys(req *http.Request) ([]string, map[string]string) { var keysList []string keysMap := make(map[string]string) srcKeys := make(map[string]string) for k := range req.Header { srcKeys[strings.ToLower(k)] = "" } for _, v := range conn.config.AdditionalHeaders { if _, ok := srcKeys[strings.ToLower(v)]; ok { keysMap[strings.ToLower(v)] = "" } } for k := range keysMap { keysList = append(keysList, k) } sort.Strings(keysList) return keysList, keysMap }
getAdditionalHeaderKeys get exist key in http header
getAdditionalHeaderKeys
go
aliyun/aliyun-oss-go-sdk
oss/auth.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/auth.go
MIT
func (conn Conn) getAdditionalHeaderKeysV4(req *http.Request) ([]string, map[string]string) { var keysList []string keysMap := make(map[string]string) srcKeys := make(map[string]string) for k := range req.Header { srcKeys[strings.ToLower(k)] = "" } for _, v := range conn.config.AdditionalHeaders { if _, ok := srcKeys[strings.ToLower(v)]; ok { if !strings.EqualFold(v, HTTPHeaderContentMD5) && !strings.EqualFold(v, HTTPHeaderContentType) { keysMap[strings.ToLower(v)] = "" } } } for k := range keysMap { keysList = append(keysList, k) } sort.Strings(keysList) return keysList, keysMap }
getAdditionalHeaderKeysV4 get exist key in http header
getAdditionalHeaderKeysV4
go
aliyun/aliyun-oss-go-sdk
oss/auth.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/auth.go
MIT
func (conn Conn) signHeader(req *http.Request, canonicalizedResource string, credentials Credentials) { akIf := credentials authorizationStr := "" if conn.config.AuthVersion == AuthV4 { strDay := "" strDate := req.Header.Get(HttpHeaderOssDate) if strDate == "" { strDate = req.Header.Get(HTTPHeaderDate) t, _ := time.Parse(http.TimeFormat, strDate) strDay = t.Format("20060102") } else { t, _ := time.Parse(timeFormatV4, strDate) strDay = t.Format("20060102") } signHeaderProduct := conn.config.GetSignProduct() signHeaderRegion := conn.config.GetSignRegion() additionalList, _ := conn.getAdditionalHeaderKeysV4(req) if len(additionalList) > 0 { authorizationFmt := "OSS4-HMAC-SHA256 Credential=%v/%v/%v/" + signHeaderProduct + "/aliyun_v4_request,AdditionalHeaders=%v,Signature=%v" additionnalHeadersStr := strings.Join(additionalList, ";") authorizationStr = fmt.Sprintf(authorizationFmt, akIf.GetAccessKeyID(), strDay, signHeaderRegion, additionnalHeadersStr, conn.getSignedStrV4(req, canonicalizedResource, akIf.GetAccessKeySecret(), nil)) } else { authorizationFmt := "OSS4-HMAC-SHA256 Credential=%v/%v/%v/" + signHeaderProduct + "/aliyun_v4_request,Signature=%v" authorizationStr = fmt.Sprintf(authorizationFmt, akIf.GetAccessKeyID(), strDay, signHeaderRegion, conn.getSignedStrV4(req, canonicalizedResource, akIf.GetAccessKeySecret(), nil)) } } else if conn.config.AuthVersion == AuthV2 { additionalList, _ := conn.getAdditionalHeaderKeys(req) if len(additionalList) > 0 { authorizationFmt := "OSS2 AccessKeyId:%v,AdditionalHeaders:%v,Signature:%v" additionnalHeadersStr := strings.Join(additionalList, ";") authorizationStr = fmt.Sprintf(authorizationFmt, akIf.GetAccessKeyID(), additionnalHeadersStr, conn.getSignedStr(req, canonicalizedResource, akIf.GetAccessKeySecret())) } else { authorizationFmt := "OSS2 AccessKeyId:%v,Signature:%v" authorizationStr = fmt.Sprintf(authorizationFmt, akIf.GetAccessKeyID(), conn.getSignedStr(req, canonicalizedResource, akIf.GetAccessKeySecret())) } } else { // Get the final authorization string authorizationStr = "OSS " + akIf.GetAccessKeyID() + ":" + conn.getSignedStr(req, canonicalizedResource, akIf.GetAccessKeySecret()) } // Give the parameter "Authorization" value req.Header.Set(HTTPHeaderAuthorization, authorizationStr) }
signHeader signs the header and sets it as the authorization header.
signHeader
go
aliyun/aliyun-oss-go-sdk
oss/auth.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/auth.go
MIT
func newHeaderSorter(m map[string]string) *headerSorter { hs := &headerSorter{ Keys: make([]string, 0, len(m)), Vals: make([]string, 0, len(m)), } for k, v := range m { hs.Keys = append(hs.Keys, k) hs.Vals = append(hs.Vals, v) } return hs }
newHeaderSorter is an additional function for function SignHeader.
newHeaderSorter
go
aliyun/aliyun-oss-go-sdk
oss/auth.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/auth.go
MIT
func (hs *headerSorter) Sort() { sort.Sort(hs) }
Sort is an additional function for function SignHeader.
Sort
go
aliyun/aliyun-oss-go-sdk
oss/auth.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/auth.go
MIT
func (hs *headerSorter) Len() int { return len(hs.Vals) }
Len is an additional function for function SignHeader.
Len
go
aliyun/aliyun-oss-go-sdk
oss/auth.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/auth.go
MIT
func (hs *headerSorter) Less(i, j int) bool { return bytes.Compare([]byte(hs.Keys[i]), []byte(hs.Keys[j])) < 0 }
Less is an additional function for function SignHeader.
Less
go
aliyun/aliyun-oss-go-sdk
oss/auth.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/auth.go
MIT
func (hs *headerSorter) Swap(i, j int) { hs.Vals[i], hs.Vals[j] = hs.Vals[j], hs.Vals[i] hs.Keys[i], hs.Keys[j] = hs.Keys[j], hs.Keys[i] }
Swap is an additional function for function SignHeader.
Swap
go
aliyun/aliyun-oss-go-sdk
oss/auth.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/auth.go
MIT
func (bucket Bucket) CopyFile(srcBucketName, srcObjectKey, destObjectKey string, partSize int64, options ...Option) error { destBucketName := bucket.BucketName if partSize < MinPartSize || partSize > MaxPartSize { return errors.New("oss: part size invalid range (1024KB, 5GB]") } cpConf := getCpConfig(options) routines := getRoutines(options) var strVersionId string versionId, _ := FindOption(options, "versionId", nil) if versionId != nil { strVersionId = versionId.(string) } if cpConf != nil && cpConf.IsEnable { cpFilePath := getCopyCpFilePath(cpConf, srcBucketName, srcObjectKey, destBucketName, destObjectKey, strVersionId) if cpFilePath != "" { return bucket.copyFileWithCp(srcBucketName, srcObjectKey, destBucketName, destObjectKey, partSize, options, cpFilePath, routines) } } return bucket.copyFile(srcBucketName, srcObjectKey, destBucketName, destObjectKey, partSize, options, routines) }
CopyFile is multipart copy object srcBucketName source bucket name srcObjectKey source object name destObjectKey target object name in the form of bucketname.objectkey partSize the part size in byte. options object's contraints. Check out function InitiateMultipartUpload. error it's nil if the operation succeeds, otherwise it's an error object.
CopyFile
go
aliyun/aliyun-oss-go-sdk
oss/multicopy.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/multicopy.go
MIT
func copyWorker(id int, arg copyWorkerArg, jobs <-chan copyPart, results chan<- UploadPart, failed chan<- error, die <-chan bool) { for chunk := range jobs { if err := arg.hook(chunk); err != nil { failed <- err break } chunkSize := chunk.End - chunk.Start + 1 part, err := arg.bucket.UploadPartCopy(arg.imur, arg.srcBucketName, arg.srcObjectKey, chunk.Start, chunkSize, chunk.Number, arg.options...) if err != nil { failed <- err break } select { case <-die: return default: } results <- part } }
copyWorker copies worker
copyWorker
go
aliyun/aliyun-oss-go-sdk
oss/multicopy.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/multicopy.go
MIT
func getCopyParts(objectSize, partSize int64) []copyPart { parts := []copyPart{} part := copyPart{} i := 0 for offset := int64(0); offset < objectSize; offset += partSize { part.Number = i + 1 part.Start = offset part.End = GetPartEnd(offset, objectSize, partSize) parts = append(parts, part) i++ } return parts }
getCopyParts calculates copy parts
getCopyParts
go
aliyun/aliyun-oss-go-sdk
oss/multicopy.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/multicopy.go
MIT
func getSrcObjectBytes(parts []copyPart) int64 { var ob int64 for _, part := range parts { ob += (part.End - part.Start + 1) } return ob }
getSrcObjectBytes gets the source file size
getSrcObjectBytes
go
aliyun/aliyun-oss-go-sdk
oss/multicopy.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/multicopy.go
MIT
func (bucket Bucket) copyFile(srcBucketName, srcObjectKey, destBucketName, destObjectKey string, partSize int64, options []Option, routines int) error { descBucket, err := bucket.Client.Bucket(destBucketName) srcBucket, err := bucket.Client.Bucket(srcBucketName) listener := GetProgressListener(options) // choice valid options headerOptions := ChoiceHeadObjectOption(options) partOptions := ChoiceTransferPartOption(options) completeOptions := ChoiceCompletePartOption(options) abortOptions := ChoiceAbortPartOption(options) meta, err := srcBucket.GetObjectDetailedMeta(srcObjectKey, headerOptions...) if err != nil { return err } objectSize, err := strconv.ParseInt(meta.Get(HTTPHeaderContentLength), 10, 0) if err != nil { return err } // Get copy parts parts := getCopyParts(objectSize, partSize) // Initialize the multipart upload imur, err := descBucket.InitiateMultipartUpload(destObjectKey, options...) if err != nil { return err } jobs := make(chan copyPart, len(parts)) results := make(chan UploadPart, len(parts)) failed := make(chan error) die := make(chan bool) var completedBytes int64 totalBytes := getSrcObjectBytes(parts) event := newProgressEvent(TransferStartedEvent, 0, totalBytes, 0) publishProgress(listener, event) // Start to copy workers arg := copyWorkerArg{descBucket, imur, srcBucketName, srcObjectKey, partOptions, copyPartHooker} for w := 1; w <= routines; w++ { go copyWorker(w, arg, jobs, results, failed, die) } // Start the scheduler go copyScheduler(jobs, parts) // Wait for the parts finished. completed := 0 ups := make([]UploadPart, len(parts)) for completed < len(parts) { select { case part := <-results: completed++ ups[part.PartNumber-1] = part copyBytes := (parts[part.PartNumber-1].End - parts[part.PartNumber-1].Start + 1) completedBytes += copyBytes event = newProgressEvent(TransferDataEvent, completedBytes, totalBytes, copyBytes) publishProgress(listener, event) case err := <-failed: close(die) descBucket.AbortMultipartUpload(imur, abortOptions...) event = newProgressEvent(TransferFailedEvent, completedBytes, totalBytes, 0) publishProgress(listener, event) return err } if completed >= len(parts) { break } } event = newProgressEvent(TransferCompletedEvent, completedBytes, totalBytes, 0) publishProgress(listener, event) // Complete the multipart upload _, err = descBucket.CompleteMultipartUpload(imur, ups, completeOptions...) if err != nil { bucket.AbortMultipartUpload(imur, abortOptions...) return err } return nil }
copyFile is a concurrently copy without checkpoint
copyFile
go
aliyun/aliyun-oss-go-sdk
oss/multicopy.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/multicopy.go
MIT
func (cp copyCheckpoint) isValid(meta http.Header) (bool, error) { // Compare CP's magic number and the MD5. cpb := cp cpb.MD5 = "" js, _ := json.Marshal(cpb) sum := md5.Sum(js) b64 := base64.StdEncoding.EncodeToString(sum[:]) if cp.Magic != downloadCpMagic || b64 != cp.MD5 { return false, nil } objectSize, err := strconv.ParseInt(meta.Get(HTTPHeaderContentLength), 10, 64) if err != nil { return false, err } // Compare the object size and last modified time and etag. if cp.ObjStat.Size != objectSize || cp.ObjStat.LastModified != meta.Get(HTTPHeaderLastModified) || cp.ObjStat.Etag != meta.Get(HTTPHeaderEtag) { return false, nil } return true, nil }
isValid checks if the data is valid which means CP is valid and object is not updated.
isValid
go
aliyun/aliyun-oss-go-sdk
oss/multicopy.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/multicopy.go
MIT
func (cp *copyCheckpoint) load(filePath string) error { contents, err := ioutil.ReadFile(filePath) if err != nil { return err } err = json.Unmarshal(contents, cp) return err }
load loads from the checkpoint file
load
go
aliyun/aliyun-oss-go-sdk
oss/multicopy.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/multicopy.go
MIT
func (cp *copyCheckpoint) update(part UploadPart) { cp.CopyParts[part.PartNumber-1] = part cp.PartStat[part.PartNumber-1] = true }
update updates the parts status
update
go
aliyun/aliyun-oss-go-sdk
oss/multicopy.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/multicopy.go
MIT
func (cp *copyCheckpoint) dump(filePath string) error { bcp := *cp // Calculate MD5 bcp.MD5 = "" js, err := json.Marshal(bcp) if err != nil { return err } sum := md5.Sum(js) b64 := base64.StdEncoding.EncodeToString(sum[:]) bcp.MD5 = b64 // Serialization js, err = json.Marshal(bcp) if err != nil { return err } // Dump return ioutil.WriteFile(filePath, js, FilePermMode) }
dump dumps the CP to the file
dump
go
aliyun/aliyun-oss-go-sdk
oss/multicopy.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/multicopy.go
MIT
func (cp copyCheckpoint) getCompletedBytes() int64 { var completedBytes int64 for i, part := range cp.Parts { if cp.PartStat[i] { completedBytes += (part.End - part.Start + 1) } } return completedBytes }
getCompletedBytes returns finished bytes count
getCompletedBytes
go
aliyun/aliyun-oss-go-sdk
oss/multicopy.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/multicopy.go
MIT
func (cp *copyCheckpoint) prepare(meta http.Header, srcBucket *Bucket, srcObjectKey string, destBucket *Bucket, destObjectKey string, partSize int64, options []Option) error { // CP cp.Magic = copyCpMagic cp.SrcBucketName = srcBucket.BucketName cp.SrcObjectKey = srcObjectKey cp.DestBucketName = destBucket.BucketName cp.DestObjectKey = destObjectKey objectSize, err := strconv.ParseInt(meta.Get(HTTPHeaderContentLength), 10, 64) if err != nil { return err } cp.ObjStat.Size = objectSize cp.ObjStat.LastModified = meta.Get(HTTPHeaderLastModified) cp.ObjStat.Etag = meta.Get(HTTPHeaderEtag) // Parts cp.Parts = getCopyParts(objectSize, partSize) cp.PartStat = make([]bool, len(cp.Parts)) for i := range cp.PartStat { cp.PartStat[i] = false } cp.CopyParts = make([]UploadPart, len(cp.Parts)) // Init copy imur, err := destBucket.InitiateMultipartUpload(destObjectKey, options...) if err != nil { return err } cp.CopyID = imur.UploadID return nil }
prepare initializes the multipart upload
prepare
go
aliyun/aliyun-oss-go-sdk
oss/multicopy.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/multicopy.go
MIT
func (bucket Bucket) copyFileWithCp(srcBucketName, srcObjectKey, destBucketName, destObjectKey string, partSize int64, options []Option, cpFilePath string, routines int) error { descBucket, err := bucket.Client.Bucket(destBucketName) srcBucket, err := bucket.Client.Bucket(srcBucketName) listener := GetProgressListener(options) // Load CP data ccp := copyCheckpoint{} err = ccp.load(cpFilePath) if err != nil { os.Remove(cpFilePath) } // choice valid options headerOptions := ChoiceHeadObjectOption(options) partOptions := ChoiceTransferPartOption(options) completeOptions := ChoiceCompletePartOption(options) meta, err := srcBucket.GetObjectDetailedMeta(srcObjectKey, headerOptions...) if err != nil { return err } // Load error or the CP data is invalid---reinitialize valid, err := ccp.isValid(meta) if err != nil || !valid { if err = ccp.prepare(meta, srcBucket, srcObjectKey, descBucket, destObjectKey, partSize, options); err != nil { return err } os.Remove(cpFilePath) } // Unfinished parts parts := ccp.todoParts() imur := InitiateMultipartUploadResult{ Bucket: destBucketName, Key: destObjectKey, UploadID: ccp.CopyID} jobs := make(chan copyPart, len(parts)) results := make(chan UploadPart, len(parts)) failed := make(chan error) die := make(chan bool) completedBytes := ccp.getCompletedBytes() event := newProgressEvent(TransferStartedEvent, completedBytes, ccp.ObjStat.Size, 0) publishProgress(listener, event) // Start the worker coroutines arg := copyWorkerArg{descBucket, imur, srcBucketName, srcObjectKey, partOptions, copyPartHooker} for w := 1; w <= routines; w++ { go copyWorker(w, arg, jobs, results, failed, die) } // Start the scheduler go copyScheduler(jobs, parts) // Wait for the parts completed. completed := 0 for completed < len(parts) { select { case part := <-results: completed++ ccp.update(part) ccp.dump(cpFilePath) copyBytes := (parts[part.PartNumber-1].End - parts[part.PartNumber-1].Start + 1) completedBytes += copyBytes event = newProgressEvent(TransferDataEvent, completedBytes, ccp.ObjStat.Size, copyBytes) publishProgress(listener, event) case err := <-failed: close(die) event = newProgressEvent(TransferFailedEvent, completedBytes, ccp.ObjStat.Size, 0) publishProgress(listener, event) return err } if completed >= len(parts) { break } } event = newProgressEvent(TransferCompletedEvent, completedBytes, ccp.ObjStat.Size, 0) publishProgress(listener, event) return ccp.complete(descBucket, ccp.CopyParts, cpFilePath, completeOptions) }
copyFileWithCp is concurrently copy with checkpoint
copyFileWithCp
go
aliyun/aliyun-oss-go-sdk
oss/multicopy.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/multicopy.go
MIT
func UseCname(isUseCname bool) ClientOption { return func(client *Client) { client.Config.IsCname = isUseCname } }
UseCname sets the flag of using CName. By default it's false. isUseCname true: the endpoint has the CName, false: the endpoint does not have cname. Default is false.
UseCname
go
aliyun/aliyun-oss-go-sdk
oss/client.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/client.go
MIT
func ForcePathStyle(isPathStyle bool) ClientOption { return func(client *Client) { client.Config.IsPathStyle = isPathStyle } }
ForcePathStyle sets the flag of using Path Style. By default it's false. isPathStyle true: the endpoint has the Path Style, false: the endpoint does not have Path Style. Default is false.
ForcePathStyle
go
aliyun/aliyun-oss-go-sdk
oss/client.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/client.go
MIT
func Timeout(connectTimeoutSec, readWriteTimeout int64) ClientOption { return func(client *Client) { client.Config.HTTPTimeout.ConnectTimeout = time.Second * time.Duration(connectTimeoutSec) client.Config.HTTPTimeout.ReadWriteTimeout = time.Second * time.Duration(readWriteTimeout) client.Config.HTTPTimeout.HeaderTimeout = time.Second * time.Duration(readWriteTimeout) client.Config.HTTPTimeout.IdleConnTimeout = time.Second * time.Duration(readWriteTimeout) client.Config.HTTPTimeout.LongTimeout = time.Second * time.Duration(readWriteTimeout*10) } }
Timeout sets the HTTP timeout in seconds. connectTimeoutSec HTTP timeout in seconds. Default is 10 seconds. 0 means infinite (not recommended) readWriteTimeout HTTP read or write's timeout in seconds. Default is 20 seconds. 0 means infinite.
Timeout
go
aliyun/aliyun-oss-go-sdk
oss/client.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/client.go
MIT
func MaxConns(maxIdleConns, maxIdleConnsPerHost, maxConnsPerHost int) ClientOption { return func(client *Client) { client.Config.HTTPMaxConns.MaxIdleConns = maxIdleConns client.Config.HTTPMaxConns.MaxIdleConnsPerHost = maxIdleConnsPerHost client.Config.HTTPMaxConns.MaxConnsPerHost = maxConnsPerHost } }
MaxConns sets the HTTP max connections for a client. maxIdleConns controls the maximum number of idle (keep-alive) connections across all hosts. Default is 100. maxIdleConnsPerHost controls the maximum idle (keep-alive) connections to keep per-host. Default is 100. maxConnsPerHost limits the total number of connections per host. Default is no limit.
MaxConns
go
aliyun/aliyun-oss-go-sdk
oss/client.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/client.go
MIT
func SecurityToken(token string) ClientOption { return func(client *Client) { client.Config.SecurityToken = strings.TrimSpace(token) } }
SecurityToken sets the temporary user's SecurityToken. token STS token
SecurityToken
go
aliyun/aliyun-oss-go-sdk
oss/client.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/client.go
MIT
func EnableMD5(isEnableMD5 bool) ClientOption { return func(client *Client) { client.Config.IsEnableMD5 = isEnableMD5 } }
EnableMD5 enables MD5 validation. isEnableMD5 true: enable MD5 validation; false: disable MD5 validation.
EnableMD5
go
aliyun/aliyun-oss-go-sdk
oss/client.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/client.go
MIT
func MD5ThresholdCalcInMemory(threshold int64) ClientOption { return func(client *Client) { client.Config.MD5Threshold = threshold } }
MD5ThresholdCalcInMemory sets the memory usage threshold for computing the MD5, default is 16MB. threshold the memory threshold in bytes. When the uploaded content is more than 16MB, the temp file is used for computing the MD5.
MD5ThresholdCalcInMemory
go
aliyun/aliyun-oss-go-sdk
oss/client.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/client.go
MIT
func EnableCRC(isEnableCRC bool) ClientOption { return func(client *Client) { client.Config.IsEnableCRC = isEnableCRC } }
EnableCRC enables the CRC checksum. Default is true. isEnableCRC true: enable CRC checksum; false: disable the CRC checksum.
EnableCRC
go
aliyun/aliyun-oss-go-sdk
oss/client.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/client.go
MIT
func UserAgent(userAgent string) ClientOption { return func(client *Client) { client.Config.UserAgent = userAgent client.Config.UserSetUa = true } }
UserAgent specifies UserAgent. The default is aliyun-sdk-go/1.2.0 (windows/-/amd64;go1.5.2). userAgent the user agent string.
UserAgent
go
aliyun/aliyun-oss-go-sdk
oss/client.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/client.go
MIT
func Proxy(proxyHost string) ClientOption { return func(client *Client) { client.Config.IsUseProxy = true client.Config.ProxyHost = proxyHost } }
Proxy sets the proxy (optional). The default is not using proxy. proxyHost the proxy host in the format "host:port". For example, proxy.com:80 .
Proxy
go
aliyun/aliyun-oss-go-sdk
oss/client.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/client.go
MIT
func AuthProxy(proxyHost, proxyUser, proxyPassword string) ClientOption { return func(client *Client) { client.Config.IsUseProxy = true client.Config.ProxyHost = proxyHost client.Config.IsAuthProxy = true client.Config.ProxyUser = proxyUser client.Config.ProxyPassword = proxyPassword } }
AuthProxy sets the proxy information with user name and password. proxyHost the proxy host in the format "host:port". For example, proxy.com:80 . proxyUser the proxy user name. proxyPassword the proxy password.
AuthProxy
go
aliyun/aliyun-oss-go-sdk
oss/client.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/client.go
MIT
func HTTPClient(HTTPClient *http.Client) ClientOption { return func(client *Client) { client.HTTPClient = HTTPClient } }
HTTPClient sets the http.Client in use to the one passed in
HTTPClient
go
aliyun/aliyun-oss-go-sdk
oss/client.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/client.go
MIT
func SetLogLevel(LogLevel int) ClientOption { return func(client *Client) { client.Config.LogLevel = LogLevel } }
SetLogLevel sets the oss sdk log level
SetLogLevel
go
aliyun/aliyun-oss-go-sdk
oss/client.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/client.go
MIT
func SetLogger(Logger *log.Logger) ClientOption { return func(client *Client) { client.Config.Logger = Logger } }
SetLogger sets the oss sdk logger
SetLogger
go
aliyun/aliyun-oss-go-sdk
oss/client.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/client.go
MIT
func SetCredentialsProvider(provider CredentialsProvider) ClientOption { return func(client *Client) { client.Config.CredentialsProvider = provider } }
SetCredentialsProvider sets function for get the user's ak
SetCredentialsProvider
go
aliyun/aliyun-oss-go-sdk
oss/client.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/client.go
MIT
func SetLocalAddr(localAddr net.Addr) ClientOption { return func(client *Client) { client.Config.LocalAddr = localAddr } }
SetLocalAddr sets function for local addr
SetLocalAddr
go
aliyun/aliyun-oss-go-sdk
oss/client.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/client.go
MIT
func AuthVersion(authVersion AuthVersionType) ClientOption { return func(client *Client) { client.Config.AuthVersion = authVersion } }
AuthVersion sets auth version: v1 or v2 signature which oss_server needed
AuthVersion
go
aliyun/aliyun-oss-go-sdk
oss/client.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/client.go
MIT
func AdditionalHeaders(headers []string) ClientOption { return func(client *Client) { client.Config.AdditionalHeaders = headers } }
AdditionalHeaders sets special http headers needed to be signed
AdditionalHeaders
go
aliyun/aliyun-oss-go-sdk
oss/client.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/client.go
MIT
func RedirectEnabled(enabled bool) ClientOption { return func(client *Client) { client.Config.RedirectEnabled = enabled } }
RedirectEnabled only effective from go1.7 onward,RedirectEnabled set http redirect enabled or not
RedirectEnabled
go
aliyun/aliyun-oss-go-sdk
oss/client.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/client.go
MIT
func InsecureSkipVerify(enabled bool) ClientOption { return func(client *Client) { client.Config.InsecureSkipVerify = enabled } }
InsecureSkipVerify skip verifying tls certificate file
InsecureSkipVerify
go
aliyun/aliyun-oss-go-sdk
oss/client.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/client.go
MIT
func CloudBoxId(cloudBoxId string) ClientOption { return func(client *Client) { client.Config.CloudBoxId = cloudBoxId } }
CloudBoxId set cloudBox id
CloudBoxId
go
aliyun/aliyun-oss-go-sdk
oss/client.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/client.go
MIT
func Product(product string) ClientOption { return func(client *Client) { client.Config.Product = product } }
Product set product type
Product
go
aliyun/aliyun-oss-go-sdk
oss/client.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/client.go
MIT
func VerifyObjectStrict(enable bool) ClientOption { return func(client *Client) { client.Config.VerifyObjectStrict = enable } }
VerifyObjectStrict sets the flag of verifying object name strictly.
VerifyObjectStrict
go
aliyun/aliyun-oss-go-sdk
oss/client.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/client.go
MIT
func (bucket Bucket) DownloadFile(objectKey, filePath string, partSize int64, options ...Option) error { if partSize < 1 { return errors.New("oss: part size smaller than 1") } uRange, err := GetRangeConfig(options) if err != nil { return err } cpConf := getCpConfig(options) routines := getRoutines(options) var strVersionId string versionId, _ := FindOption(options, "versionId", nil) if versionId != nil { strVersionId = versionId.(string) } if cpConf != nil && cpConf.IsEnable { cpFilePath := getDownloadCpFilePath(cpConf, bucket.BucketName, objectKey, strVersionId, filePath) if cpFilePath != "" { return bucket.downloadFileWithCp(objectKey, filePath, partSize, options, cpFilePath, routines, uRange) } } return bucket.downloadFile(objectKey, filePath, partSize, options, routines, uRange) }
DownloadFile downloads files with multipart download. objectKey the object key. filePath the local file to download from objectKey in OSS. partSize the part size in bytes. options object's constraints, check out GetObject for the reference. error it's nil when the call succeeds, otherwise it's an error object.
DownloadFile
go
aliyun/aliyun-oss-go-sdk
oss/download.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/download.go
MIT
func (listener *defaultDownloadProgressListener) ProgressChanged(event *ProgressEvent) { }
ProgressChanged no-ops
ProgressChanged
go
aliyun/aliyun-oss-go-sdk
oss/download.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/download.go
MIT
func getDownloadParts(objectSize, partSize int64, uRange *UnpackedRange) []downloadPart { parts := []downloadPart{} part := downloadPart{} i := 0 start, end := AdjustRange(uRange, objectSize) for offset := start; offset < end; offset += partSize { part.Index = i part.Start = offset part.End = GetPartEnd(offset, end, partSize) part.Offset = start part.CRC64 = 0 parts = append(parts, part) i++ } return parts }
getDownloadParts gets download parts
getDownloadParts
go
aliyun/aliyun-oss-go-sdk
oss/download.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/download.go
MIT
func getObjectBytes(parts []downloadPart) int64 { var ob int64 for _, part := range parts { ob += (part.End - part.Start + 1) } return ob }
getObjectBytes gets object bytes length
getObjectBytes
go
aliyun/aliyun-oss-go-sdk
oss/download.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/download.go
MIT
func combineCRCInParts(dps []downloadPart) uint64 { if dps == nil || len(dps) == 0 { return 0 } crc := dps[0].CRC64 for i := 1; i < len(dps); i++ { crc = CRC64Combine(crc, dps[i].CRC64, (uint64)(dps[i].End-dps[i].Start+1)) } return crc }
combineCRCInParts caculates the total CRC of continuous parts
combineCRCInParts
go
aliyun/aliyun-oss-go-sdk
oss/download.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/download.go
MIT
func (bucket Bucket) downloadFile(objectKey, filePath string, partSize int64, options []Option, routines int, uRange *UnpackedRange) error { tempFilePath := filePath + TempFileSuffix listener := GetProgressListener(options) // If the file does not exist, create one. If exists, the download will overwrite it. fd, err := os.OpenFile(tempFilePath, os.O_WRONLY|os.O_CREATE, FilePermMode) if err != nil { return err } fd.Close() // Get the object detailed meta for object whole size // must delete header:range to get whole object size skipOptions := DeleteOption(options, HTTPHeaderRange) meta, err := bucket.GetObjectDetailedMeta(objectKey, skipOptions...) if err != nil { return err } objectSize, err := strconv.ParseInt(meta.Get(HTTPHeaderContentLength), 10, 64) if err != nil { return err } enableCRC := false expectedCRC := (uint64)(0) if bucket.GetConfig().IsEnableCRC && meta.Get(HTTPHeaderOssCRC64) != "" { if uRange == nil || (!uRange.HasStart && !uRange.HasEnd) { enableCRC = true expectedCRC, _ = strconv.ParseUint(meta.Get(HTTPHeaderOssCRC64), 10, 64) } } // Get the parts of the file parts := getDownloadParts(objectSize, partSize, uRange) jobs := make(chan downloadPart, len(parts)) results := make(chan downloadPart, len(parts)) failed := make(chan error) die := make(chan bool) var completedBytes int64 totalBytes := getObjectBytes(parts) event := newProgressEvent(TransferStartedEvent, 0, totalBytes, 0) publishProgress(listener, event) // Start the download workers arg := downloadWorkerArg{&bucket, objectKey, tempFilePath, options, downloadPartHooker, enableCRC} for w := 1; w <= routines; w++ { go downloadWorker(w, arg, jobs, results, failed, die) } // Download parts concurrently go downloadScheduler(jobs, parts) // Waiting for parts download finished completed := 0 for completed < len(parts) { select { case part := <-results: completed++ downBytes := (part.End - part.Start + 1) completedBytes += downBytes parts[part.Index].CRC64 = part.CRC64 event = newProgressEvent(TransferDataEvent, completedBytes, totalBytes, downBytes) publishProgress(listener, event) case err := <-failed: close(die) event = newProgressEvent(TransferFailedEvent, completedBytes, totalBytes, 0) publishProgress(listener, event) return err } if completed >= len(parts) { break } } event = newProgressEvent(TransferCompletedEvent, completedBytes, totalBytes, 0) publishProgress(listener, event) if enableCRC { actualCRC := combineCRCInParts(parts) err = CheckDownloadCRC(actualCRC, expectedCRC) if err != nil { return err } } return os.Rename(tempFilePath, filePath) }
downloadFile downloads file concurrently without checkpoint.
downloadFile
go
aliyun/aliyun-oss-go-sdk
oss/download.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/download.go
MIT
func (cp downloadCheckpoint) isValid(meta http.Header, uRange *UnpackedRange) (bool, error) { // Compare the CP's Magic and the MD5 cpb := cp cpb.MD5 = "" js, _ := json.Marshal(cpb) sum := md5.Sum(js) b64 := base64.StdEncoding.EncodeToString(sum[:]) if cp.Magic != downloadCpMagic || b64 != cp.MD5 { return false, nil } objectSize, err := strconv.ParseInt(meta.Get(HTTPHeaderContentLength), 10, 64) if err != nil { return false, err } // Compare the object size, last modified time and etag if cp.ObjStat.Size != objectSize || cp.ObjStat.LastModified != meta.Get(HTTPHeaderLastModified) || cp.ObjStat.Etag != meta.Get(HTTPHeaderEtag) { return false, nil } // Check the download range if uRange != nil { start, end := AdjustRange(uRange, objectSize) if start != cp.Start || end != cp.End { return false, nil } } return true, nil }
isValid flags of checkpoint data is valid. It returns true when the data is valid and the checkpoint is valid and the object is not updated.
isValid
go
aliyun/aliyun-oss-go-sdk
oss/download.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/download.go
MIT
func (cp *downloadCheckpoint) load(filePath string) error { contents, err := ioutil.ReadFile(filePath) if err != nil { return err } err = json.Unmarshal(contents, cp) return err }
load checkpoint from local file
load
go
aliyun/aliyun-oss-go-sdk
oss/download.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/download.go
MIT
func (cp *downloadCheckpoint) dump(filePath string) error { bcp := *cp // Calculate MD5 bcp.MD5 = "" js, err := json.Marshal(bcp) if err != nil { return err } sum := md5.Sum(js) b64 := base64.StdEncoding.EncodeToString(sum[:]) bcp.MD5 = b64 // Serialize js, err = json.Marshal(bcp) if err != nil { return err } // Dump return ioutil.WriteFile(filePath, js, FilePermMode) }
dump funciton dumps to file
dump
go
aliyun/aliyun-oss-go-sdk
oss/download.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/download.go
MIT
func (cp downloadCheckpoint) getCompletedBytes() int64 { var completedBytes int64 for i, part := range cp.Parts { if cp.PartStat[i] { completedBytes += (part.End - part.Start + 1) } } return completedBytes }
getCompletedBytes gets completed size
getCompletedBytes
go
aliyun/aliyun-oss-go-sdk
oss/download.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/download.go
MIT
func (cp *downloadCheckpoint) prepare(meta http.Header, bucket *Bucket, objectKey, filePath string, partSize int64, uRange *UnpackedRange) error { // CP cp.Magic = downloadCpMagic cp.FilePath = filePath cp.Object = objectKey objectSize, err := strconv.ParseInt(meta.Get(HTTPHeaderContentLength), 10, 64) if err != nil { return err } cp.ObjStat.Size = objectSize cp.ObjStat.LastModified = meta.Get(HTTPHeaderLastModified) cp.ObjStat.Etag = meta.Get(HTTPHeaderEtag) if bucket.GetConfig().IsEnableCRC && meta.Get(HTTPHeaderOssCRC64) != "" { if uRange == nil || (!uRange.HasStart && !uRange.HasEnd) { cp.enableCRC = true cp.CRC, _ = strconv.ParseUint(meta.Get(HTTPHeaderOssCRC64), 10, 64) } } // Parts cp.Parts = getDownloadParts(objectSize, partSize, uRange) cp.PartStat = make([]bool, len(cp.Parts)) for i := range cp.PartStat { cp.PartStat[i] = false } return nil }
prepare initiates download tasks
prepare
go
aliyun/aliyun-oss-go-sdk
oss/download.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/download.go
MIT
func (bucket Bucket) downloadFileWithCp(objectKey, filePath string, partSize int64, options []Option, cpFilePath string, routines int, uRange *UnpackedRange) error { tempFilePath := filePath + TempFileSuffix listener := GetProgressListener(options) // Load checkpoint data. dcp := downloadCheckpoint{} err := dcp.load(cpFilePath) if err != nil { os.Remove(cpFilePath) } // Get the object detailed meta for object whole size // must delete header:range to get whole object size skipOptions := DeleteOption(options, HTTPHeaderRange) meta, err := bucket.GetObjectDetailedMeta(objectKey, skipOptions...) if err != nil { return err } // Load error or data invalid. Re-initialize the download. valid, err := dcp.isValid(meta, uRange) if err != nil || !valid { if err = dcp.prepare(meta, &bucket, objectKey, filePath, partSize, uRange); err != nil { return err } os.Remove(cpFilePath) } // Create the file if not exists. Otherwise the parts download will overwrite it. fd, err := os.OpenFile(tempFilePath, os.O_WRONLY|os.O_CREATE, FilePermMode) if err != nil { return err } fd.Close() // Unfinished parts parts := dcp.todoParts() jobs := make(chan downloadPart, len(parts)) results := make(chan downloadPart, len(parts)) failed := make(chan error) die := make(chan bool) completedBytes := dcp.getCompletedBytes() event := newProgressEvent(TransferStartedEvent, completedBytes, dcp.ObjStat.Size, 0) publishProgress(listener, event) // Start the download workers routine arg := downloadWorkerArg{&bucket, objectKey, tempFilePath, options, downloadPartHooker, dcp.enableCRC} for w := 1; w <= routines; w++ { go downloadWorker(w, arg, jobs, results, failed, die) } // Concurrently downloads parts go downloadScheduler(jobs, parts) // Wait for the parts download finished completed := 0 for completed < len(parts) { select { case part := <-results: completed++ dcp.PartStat[part.Index] = true dcp.Parts[part.Index].CRC64 = part.CRC64 dcp.dump(cpFilePath) downBytes := (part.End - part.Start + 1) completedBytes += downBytes event = newProgressEvent(TransferDataEvent, completedBytes, dcp.ObjStat.Size, downBytes) publishProgress(listener, event) case err := <-failed: close(die) event = newProgressEvent(TransferFailedEvent, completedBytes, dcp.ObjStat.Size, 0) publishProgress(listener, event) return err } if completed >= len(parts) { break } } event = newProgressEvent(TransferCompletedEvent, completedBytes, dcp.ObjStat.Size, 0) publishProgress(listener, event) if dcp.enableCRC { actualCRC := combineCRCInParts(dcp.Parts) err = CheckDownloadCRC(actualCRC, dcp.CRC) if err != nil { return err } } return dcp.complete(cpFilePath, tempFilePath) }
downloadFileWithCp downloads files with checkpoint.
downloadFileWithCp
go
aliyun/aliyun-oss-go-sdk
oss/download.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/download.go
MIT
func (r *Response) Close() error { return r.Body.Close() }
Close close http reponse body
Close
go
aliyun/aliyun-oss-go-sdk
oss/model.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/model.go
MIT
func (s *OssProgressSuite) SetUpSuite(c *C) { bucketName = bucketNamePrefix + RandLowStr(6) if cloudboxControlEndpoint == "" { client, err := New(endpoint, accessID, accessKey) c.Assert(err, IsNil) s.client = client s.client.CreateBucket(bucketName) bucket, err := s.client.Bucket(bucketName) c.Assert(err, IsNil) s.bucket = bucket } else { client, err := New(cloudboxEndpoint, accessID, accessKey) c.Assert(err, IsNil) s.client = client controlClient, err := New(cloudboxControlEndpoint, accessID, accessKey) c.Assert(err, IsNil) s.cloudBoxControlClient = controlClient controlClient.CreateBucket(bucketName) bucket, err := s.client.Bucket(bucketName) c.Assert(err, IsNil) s.bucket = bucket } testLogger.Println("test progress started") }
SetUpSuite runs once when the suite starts running
SetUpSuite
go
aliyun/aliyun-oss-go-sdk
oss/progress_test.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/progress_test.go
MIT
func (s *OssProgressSuite) TearDownSuite(c *C) { // Abort multipart uploads keyMarker := KeyMarker("") uploadIDMarker := UploadIDMarker("") for { lmu, err := s.bucket.ListMultipartUploads(keyMarker, uploadIDMarker) c.Assert(err, IsNil) for _, upload := range lmu.Uploads { imur := InitiateMultipartUploadResult{Bucket: bucketName, Key: upload.Key, UploadID: upload.UploadID} err = s.bucket.AbortMultipartUpload(imur) c.Assert(err, IsNil) } keyMarker = KeyMarker(lmu.NextKeyMarker) uploadIDMarker = UploadIDMarker(lmu.NextUploadIDMarker) if !lmu.IsTruncated { break } } // Delete objects marker := Marker("") for { lor, err := s.bucket.ListObjects(marker) c.Assert(err, IsNil) for _, object := range lor.Objects { err = s.bucket.DeleteObject(object.Key) c.Assert(err, IsNil) } marker = Marker(lor.NextMarker) if !lor.IsTruncated { break } } // Delete bucket if s.cloudBoxControlClient != nil { err := s.cloudBoxControlClient.DeleteBucket(s.bucket.BucketName) c.Assert(err, IsNil) } else { err := s.client.DeleteBucket(s.bucket.BucketName) c.Assert(err, IsNil) } testLogger.Println("test progress completed") }
TearDownSuite runs before each test or benchmark starts running
TearDownSuite
go
aliyun/aliyun-oss-go-sdk
oss/progress_test.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/progress_test.go
MIT
func (s *OssProgressSuite) SetUpTest(c *C) { err := removeTempFiles("../oss", ".jpg") c.Assert(err, IsNil) err = removeTempFiles("../oss", ".txt") c.Assert(err, IsNil) err = removeTempFiles("../oss", ".html") c.Assert(err, IsNil) }
SetUpTest runs after each test or benchmark runs
SetUpTest
go
aliyun/aliyun-oss-go-sdk
oss/progress_test.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/progress_test.go
MIT
func (s *OssProgressSuite) TearDownTest(c *C) { err := removeTempFiles("../oss", ".jpg") c.Assert(err, IsNil) err = removeTempFiles("../oss", ".txt") c.Assert(err, IsNil) err = removeTempFiles("../oss", ".html") c.Assert(err, IsNil) }
TearDownTest runs once after all tests or benchmarks have finished running
TearDownTest
go
aliyun/aliyun-oss-go-sdk
oss/progress_test.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/progress_test.go
MIT
func (listener *OssProgressListener) ProgressChanged(event *ProgressEvent) { switch event.EventType { case TransferStartedEvent: testLogger.Printf("Transfer Started, ConsumedBytes: %d, TotalBytes %d.\n", event.ConsumedBytes, event.TotalBytes) case TransferDataEvent: atomic.AddInt64(&listener.TotalRwBytes, event.RwBytes) testLogger.Printf("Transfer Data, ConsumedBytes: %d, TotalBytes %d, %d%%.\n", event.ConsumedBytes, event.TotalBytes, event.ConsumedBytes*100/event.TotalBytes) case TransferCompletedEvent: testLogger.Printf("Transfer Completed, ConsumedBytes: %d, TotalBytes %d.\n", event.ConsumedBytes, event.TotalBytes) case TransferFailedEvent: testLogger.Printf("Transfer Failed, ConsumedBytes: %d, TotalBytes %d.\n", event.ConsumedBytes, event.TotalBytes) default: } }
ProgressChanged handles progress event
ProgressChanged
go
aliyun/aliyun-oss-go-sdk
oss/progress_test.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/progress_test.go
MIT
func (config *Config) LimitUploadSpeed(uploadSpeed int) error { if uploadSpeed < 0 { return fmt.Errorf("invalid argument, the value of uploadSpeed is less than 0") } else if uploadSpeed == 0 { config.UploadLimitSpeed = 0 config.UploadLimiter = nil return nil } var err error config.UploadLimiter, err = GetOssLimiter(uploadSpeed) if err == nil { config.UploadLimitSpeed = uploadSpeed } return err }
LimitUploadSpeed uploadSpeed:KB/s, 0 is unlimited,default is 0
LimitUploadSpeed
go
aliyun/aliyun-oss-go-sdk
oss/conf.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/conf.go
MIT
func (config *Config) LimitDownloadSpeed(downloadSpeed int) error { if downloadSpeed < 0 { return fmt.Errorf("invalid argument, the value of downloadSpeed is less than 0") } else if downloadSpeed == 0 { config.DownloadLimitSpeed = 0 config.DownloadLimiter = nil return nil } var err error config.DownloadLimiter, err = GetOssLimiter(downloadSpeed) if err == nil { config.DownloadLimitSpeed = downloadSpeed } return err }
LimitDownLoadSpeed downloadSpeed:KB/s, 0 is unlimited,default is 0
LimitDownloadSpeed
go
aliyun/aliyun-oss-go-sdk
oss/conf.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/conf.go
MIT
func (config *Config) WriteLog(LogLevel int, format string, a ...interface{}) { if config.LogLevel < LogLevel || config.Logger == nil { return } var logBuffer bytes.Buffer logBuffer.WriteString(LogTag[LogLevel-1]) logBuffer.WriteString(fmt.Sprintf(format, a...)) config.Logger.Printf("%s", logBuffer.String()) }
WriteLog output log function
WriteLog
go
aliyun/aliyun-oss-go-sdk
oss/conf.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/conf.go
MIT
func (config *Config) GetSignProduct() string { if config.CloudBoxId != "" { return "oss-cloudbox" } return "oss" }
for get Sign Product
GetSignProduct
go
aliyun/aliyun-oss-go-sdk
oss/conf.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/conf.go
MIT
func getDefaultOssConfig() *Config { config := Config{} config.Endpoint = "" config.AccessKeyID = "" config.AccessKeySecret = "" config.RetryTimes = 5 config.IsDebug = false config.UserAgent = userAgent() config.Timeout = 60 // Seconds config.SecurityToken = "" config.IsCname = false config.IsPathStyle = false config.HTTPTimeout.ConnectTimeout = time.Second * 30 // 30s config.HTTPTimeout.ReadWriteTimeout = time.Second * 60 // 60s config.HTTPTimeout.HeaderTimeout = time.Second * 60 // 60s config.HTTPTimeout.LongTimeout = time.Second * 300 // 300s config.HTTPTimeout.IdleConnTimeout = time.Second * 50 // 50s config.HTTPMaxConns.MaxIdleConns = 100 config.HTTPMaxConns.MaxIdleConnsPerHost = 100 config.IsUseProxy = false config.ProxyHost = "" config.IsAuthProxy = false config.ProxyUser = "" config.ProxyPassword = "" config.MD5Threshold = 16 * 1024 * 1024 // 16MB config.IsEnableMD5 = false config.IsEnableCRC = true config.LogLevel = LogOff config.Logger = log.New(os.Stdout, "", log.LstdFlags) provider := &defaultCredentialsProvider{config: &config} config.CredentialsProvider = provider config.AuthVersion = AuthV1 config.RedirectEnabled = true config.InsecureSkipVerify = false config.Product = "oss" config.VerifyObjectStrict = true return &config }
getDefaultOssConfig gets the default configuration.
getDefaultOssConfig
go
aliyun/aliyun-oss-go-sdk
oss/conf.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/conf.go
MIT
func ACL(acl ACLType) Option { return setHeader(HTTPHeaderOssACL, string(acl)) }
ACL is an option to set X-Oss-Acl header
ACL
go
aliyun/aliyun-oss-go-sdk
oss/option.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/option.go
MIT
func ContentType(value string) Option { return setHeader(HTTPHeaderContentType, value) }
ContentType is an option to set Content-Type header
ContentType
go
aliyun/aliyun-oss-go-sdk
oss/option.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/option.go
MIT
func ContentLength(length int64) Option { return setHeader(HTTPHeaderContentLength, strconv.FormatInt(length, 10)) }
ContentLength is an option to set Content-Length header
ContentLength
go
aliyun/aliyun-oss-go-sdk
oss/option.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/option.go
MIT
func CacheControl(value string) Option { return setHeader(HTTPHeaderCacheControl, value) }
CacheControl is an option to set Cache-Control header
CacheControl
go
aliyun/aliyun-oss-go-sdk
oss/option.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/option.go
MIT
func ContentDisposition(value string) Option { return setHeader(HTTPHeaderContentDisposition, value) }
ContentDisposition is an option to set Content-Disposition header
ContentDisposition
go
aliyun/aliyun-oss-go-sdk
oss/option.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/option.go
MIT
func ContentEncoding(value string) Option { return setHeader(HTTPHeaderContentEncoding, value) }
ContentEncoding is an option to set Content-Encoding header
ContentEncoding
go
aliyun/aliyun-oss-go-sdk
oss/option.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/option.go
MIT
func ContentLanguage(value string) Option { return setHeader(HTTPHeaderContentLanguage, value) }
ContentLanguage is an option to set Content-Language header
ContentLanguage
go
aliyun/aliyun-oss-go-sdk
oss/option.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/option.go
MIT
func ContentMD5(value string) Option { return setHeader(HTTPHeaderContentMD5, value) }
ContentMD5 is an option to set Content-MD5 header
ContentMD5
go
aliyun/aliyun-oss-go-sdk
oss/option.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/option.go
MIT
func Expires(t time.Time) Option { return setHeader(HTTPHeaderExpires, t.Format(http.TimeFormat)) }
Expires is an option to set Expires header
Expires
go
aliyun/aliyun-oss-go-sdk
oss/option.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/option.go
MIT
func Meta(key, value string) Option { return setHeader(HTTPHeaderOssMetaPrefix+key, value) }
Meta is an option to set Meta header
Meta
go
aliyun/aliyun-oss-go-sdk
oss/option.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/option.go
MIT
func Range(start, end int64) Option { return setHeader(HTTPHeaderRange, fmt.Sprintf("bytes=%d-%d", start, end)) }
Range is an option to set Range header, [start, end]
Range
go
aliyun/aliyun-oss-go-sdk
oss/option.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/option.go
MIT
func NormalizedRange(nr string) Option { return setHeader(HTTPHeaderRange, fmt.Sprintf("bytes=%s", strings.TrimSpace(nr))) }
NormalizedRange is an option to set Range header, such as 1024-2048 or 1024- or -2048
NormalizedRange
go
aliyun/aliyun-oss-go-sdk
oss/option.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/option.go
MIT
func AcceptEncoding(value string) Option { return setHeader(HTTPHeaderAcceptEncoding, value) }
AcceptEncoding is an option to set Accept-Encoding header
AcceptEncoding
go
aliyun/aliyun-oss-go-sdk
oss/option.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/option.go
MIT
func IfModifiedSince(t time.Time) Option { return setHeader(HTTPHeaderIfModifiedSince, t.Format(http.TimeFormat)) }
IfModifiedSince is an option to set If-Modified-Since header
IfModifiedSince
go
aliyun/aliyun-oss-go-sdk
oss/option.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/option.go
MIT
func IfUnmodifiedSince(t time.Time) Option { return setHeader(HTTPHeaderIfUnmodifiedSince, t.Format(http.TimeFormat)) }
IfUnmodifiedSince is an option to set If-Unmodified-Since header
IfUnmodifiedSince
go
aliyun/aliyun-oss-go-sdk
oss/option.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/option.go
MIT
func IfMatch(value string) Option { return setHeader(HTTPHeaderIfMatch, value) }
IfMatch is an option to set If-Match header
IfMatch
go
aliyun/aliyun-oss-go-sdk
oss/option.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/option.go
MIT
func IfNoneMatch(value string) Option { return setHeader(HTTPHeaderIfNoneMatch, value) }
IfNoneMatch is an option to set IfNoneMatch header
IfNoneMatch
go
aliyun/aliyun-oss-go-sdk
oss/option.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/option.go
MIT
func CopySource(sourceBucket, sourceObject string) Option { return setHeader(HTTPHeaderOssCopySource, "/"+sourceBucket+"/"+sourceObject) }
CopySource is an option to set X-Oss-Copy-Source header
CopySource
go
aliyun/aliyun-oss-go-sdk
oss/option.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/option.go
MIT
func CopySourceVersion(sourceBucket, sourceObject string, versionId string) Option { return setHeader(HTTPHeaderOssCopySource, "/"+sourceBucket+"/"+sourceObject+"?"+"versionId="+versionId) }
CopySourceVersion is an option to set X-Oss-Copy-Source header,include versionId
CopySourceVersion
go
aliyun/aliyun-oss-go-sdk
oss/option.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/option.go
MIT
func CopySourceRange(startPosition, partSize int64) Option { val := "bytes=" + strconv.FormatInt(startPosition, 10) + "-" + strconv.FormatInt((startPosition+partSize-1), 10) return setHeader(HTTPHeaderOssCopySourceRange, val) }
CopySourceRange is an option to set X-Oss-Copy-Source header
CopySourceRange
go
aliyun/aliyun-oss-go-sdk
oss/option.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/option.go
MIT
func CopySourceIfMatch(value string) Option { return setHeader(HTTPHeaderOssCopySourceIfMatch, value) }
CopySourceIfMatch is an option to set X-Oss-Copy-Source-If-Match header
CopySourceIfMatch
go
aliyun/aliyun-oss-go-sdk
oss/option.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/option.go
MIT
func CopySourceIfNoneMatch(value string) Option { return setHeader(HTTPHeaderOssCopySourceIfNoneMatch, value) }
CopySourceIfNoneMatch is an option to set X-Oss-Copy-Source-If-None-Match header
CopySourceIfNoneMatch
go
aliyun/aliyun-oss-go-sdk
oss/option.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/option.go
MIT
func CopySourceIfModifiedSince(t time.Time) Option { return setHeader(HTTPHeaderOssCopySourceIfModifiedSince, t.Format(http.TimeFormat)) }
CopySourceIfModifiedSince is an option to set X-Oss-CopySource-If-Modified-Since header
CopySourceIfModifiedSince
go
aliyun/aliyun-oss-go-sdk
oss/option.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/option.go
MIT
func CopySourceIfUnmodifiedSince(t time.Time) Option { return setHeader(HTTPHeaderOssCopySourceIfUnmodifiedSince, t.Format(http.TimeFormat)) }
CopySourceIfUnmodifiedSince is an option to set X-Oss-Copy-Source-If-Unmodified-Since header
CopySourceIfUnmodifiedSince
go
aliyun/aliyun-oss-go-sdk
oss/option.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/option.go
MIT
func MetadataDirective(directive MetadataDirectiveType) Option { return setHeader(HTTPHeaderOssMetadataDirective, string(directive)) }
MetadataDirective is an option to set X-Oss-Metadata-Directive header
MetadataDirective
go
aliyun/aliyun-oss-go-sdk
oss/option.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/option.go
MIT
func ServerSideEncryption(value string) Option { return setHeader(HTTPHeaderOssServerSideEncryption, value) }
ServerSideEncryption is an option to set X-Oss-Server-Side-Encryption header
ServerSideEncryption
go
aliyun/aliyun-oss-go-sdk
oss/option.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/option.go
MIT
func ServerSideEncryptionKeyID(value string) Option { return setHeader(HTTPHeaderOssServerSideEncryptionKeyID, value) }
ServerSideEncryptionKeyID is an option to set X-Oss-Server-Side-Encryption-Key-Id header
ServerSideEncryptionKeyID
go
aliyun/aliyun-oss-go-sdk
oss/option.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/option.go
MIT
func ServerSideDataEncryption(value string) Option { return setHeader(HTTPHeaderOssServerSideDataEncryption, value) }
ServerSideDataEncryption is an option to set X-Oss-Server-Side-Data-Encryption header
ServerSideDataEncryption
go
aliyun/aliyun-oss-go-sdk
oss/option.go
https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/option.go
MIT