Source File
resumable.go
Belonging Package
google.golang.org/api/internal/gensupport
package gensupport
import (
gax
)
var (
retryDeadline = 32 * time.Second
backoff = func() Backoff {
return &gax.Backoff{Initial: 100 * time.Millisecond}
statusTooManyRequests = 429
)
type ResumableUpload struct {
func ( *ResumableUpload) ( context.Context, io.Reader, , int64, bool) (*http.Response, error) {
, := http.NewRequest("POST", .URI, )
if != nil {
return nil,
}
.ContentLength =
var string
if {
if == 0 {
= fmt.Sprintf("bytes */%v", )
} else {
= fmt.Sprintf("bytes %v-%v/%v", , +-1, +)
}
} else {
= fmt.Sprintf("bytes %v-%v/*", , +-1)
}
.Header.Set("Content-Range", )
.Header.Set("Content-Type", .MediaType)
.Header.Set("User-Agent", .UserAgent)
.Header.Set("X-GUploader-No-308", "yes")
return SendRequest(, .Client, )
}
if .StatusCode == 308 {
return nil, errors.New("unexpected 308 response status code")
}
if .StatusCode == http.StatusOK {
.reportProgress(, +int64())
}
if statusResumeIncomplete() {
.Media.Next()
}
return , nil
}
:= backoff()
:= time.After(retryDeadline)
if statusResumeIncomplete() {
.Body.Close()
continue
}
return (, )
}
}
func ( int, error) bool {
if 500 <= && <= 599 {
return true
}
if == statusTooManyRequests {
return true
}
if == io.ErrUnexpectedEOF {
return true
if syscallRetryable() {
return true
}
if , := .(interface{ () bool }); {
if .() {
return true
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |