Source File
googleapi.go
Belonging Package
google.golang.org/api/googleapi
package googleapi // import "google.golang.org/api/googleapi"
import (
)
type ContentTyper interface {
ContentType() string
}
type SizeReaderAt interface {
io.ReaderAt
Size() int64
}
Version = "0.5"
DefaultUploadChunkSize = 16 * 1024 * 1024
MinUploadChunkSize = 256 * 1024
)
Message string `json:"message"`
}
func ( *Error) () string {
if len(.Errors) == 0 && .Message == "" {
return fmt.Sprintf("googleapi: got HTTP response code %d with body: %v", .Code, .Body)
}
var bytes.Buffer
fmt.Fprintf(&, "googleapi: Error %d: ", .Code)
if .Message != "" {
fmt.Fprintf(&, "%s", .Message)
}
if len(.Details) > 0 {
var bytes.Buffer
:= json.NewEncoder(&)
.SetIndent("", " ")
if := .Encode(.Details); == nil {
fmt.Fprint(&, "\nDetails:")
fmt.Fprintf(&, "\n%s", .String())
}
}
if len(.Errors) == 0 {
return strings.TrimSpace(.String())
}
if len(.Errors) == 1 && .Errors[0].Message == .Message {
fmt.Fprintf(&, ", %s", .Errors[0].Reason)
return .String()
}
fmt.Fprintln(&, "\nMore details:")
for , := range .Errors {
fmt.Fprintf(&, "Reason: %s, Message: %s\n", .Reason, .Message)
}
return .String()
}
type errorReply struct {
Error *Error `json:"error"`
}
func ( *http.Response) error {
if .StatusCode >= 200 && .StatusCode <= 299 {
return nil
}
, := ioutil.ReadAll(.Body)
if == nil {
:= new(errorReply)
= json.Unmarshal(, )
if == nil && .Error != nil {
if .Error.Code == 0 {
.Error.Code = .StatusCode
}
.Error.Body = string()
return .Error
}
}
return &Error{
Code: .StatusCode,
Body: string(),
Header: .Header,
}
}
func ( *http.Response) error {
if .StatusCode >= 200 && .StatusCode <= 299 {
return nil
}
, := ioutil.ReadAll(io.LimitReader(.Body, 1<<20))
return &Error{
Code: .StatusCode,
Body: string(),
}
}
type MarshalStyle bool
var WithDataWrapper = MarshalStyle(true)
var WithoutDataWrapper = MarshalStyle(false)
func ( MarshalStyle) ( interface{}) (io.Reader, error) {
:= new(bytes.Buffer)
if {
.Write([]byte(`{"data": `))
}
:= json.NewEncoder().Encode()
if != nil {
return nil,
}
if {
.Write([]byte(`}`))
}
return , nil
}
type ProgressUpdater func(current, total int64)
type MediaOption interface {
setOptions(o *MediaOptions)
}
type contentTypeOption string
func ( contentTypeOption) ( *MediaOptions) {
.ContentType = string()
if .ContentType == "" {
.ForceEmptyContentType = true
}
}
func ( string) MediaOption {
return contentTypeOption()
}
type chunkSizeOption int
func ( chunkSizeOption) ( *MediaOptions) {
:= int()
if %MinUploadChunkSize != 0 {
+= MinUploadChunkSize - ( % MinUploadChunkSize)
}
.ChunkSize =
}
func ( int) MediaOption {
return chunkSizeOption()
}
type MediaOptions struct {
ContentType string
ForceEmptyContentType bool
ChunkSize int
}
func ( []MediaOption) *MediaOptions {
:= &MediaOptions{ChunkSize: DefaultUploadChunkSize}
for , := range {
.setOptions()
}
return
}
func (, string) string {
, := url.Parse()
if != nil {
panic(fmt.Sprintf("failed to parse %q", ))
}
:= ""
if := strings.IndexRune(, ':'); > 0 {
= [+1:]
= [:]
}
, := url.Parse()
if != nil {
panic(fmt.Sprintf("failed to parse %q", ))
}
= .ResolveReference()
:= .String()
if != "" {
= fmt.Sprintf("%s:%s", , )
}
= strings.Replace(, "%7B", "{", -1)
= strings.Replace(, "%7D", "}", -1)
= strings.Replace(, "%2A", "*", -1)
return
}
type CallOption interface {
Get() (key, value string)
}
![]() |
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. |