Documentation ¶
Overview ¶
Package googleapi contains the common code shared by all Google API libraries.
Index ¶
- Constants
- Variables
- func CheckResponse(res *http.Response) error
- func CloseBody(res *http.Response)
- func CombineFields(s []Field) string
- func ConditionallyIncludeMedia(media io.Reader, bodyp *io.Reader, ctypep *string) (cancel func(), ok bool)
- func ConvertVariant(v map[string]interface{}, dst interface{}) bool
- func DetectMediaType(media io.ReaderAt) string
- func Expand(u *url.URL, expansions map[string]string)
- func ResolveRelative(basestr, relstr string) string
- func SetOpaque(u *url.URL)
- func VariantType(t map[string]interface{}) string
- type ContentTyper
- type Error
- type ErrorItem
- type Field
- type Float64s
- type Int32s
- type Int64s
- type Lengther
- type MarshalStyle
- type ProgressUpdater
- type ResumableUpload
- type SizeReaderAt
- type Uint32s
- type Uint64s
Constants ¶
const ( Version = "0.5" // UserAgent is the header string used to identify this package. UserAgent = "google-api-go-client/" + Version )
Variables ¶
var WithDataWrapper = MarshalStyle(true)
var WithoutDataWrapper = MarshalStyle(false)
Functions ¶
func CheckResponse ¶
CheckResponse returns an error (of type *Error) if the response status code is not 2xx.
func CloseBody ¶
CloseBody is used to close res.Body. Prior to calling Close, it also tries to Read a small amount to see an EOF. Not seeing an EOF can prevent HTTP Transports from reusing connections.
func CombineFields ¶
CombineFields combines fields into a single string.
func ConditionallyIncludeMedia ¶
func ConditionallyIncludeMedia(media io.Reader, bodyp *io.Reader, ctypep *string) (cancel func(), ok bool)
ConditionallyIncludeMedia does nothing if media is nil.
bodyp is an in/out parameter. It should initially point to the reader of the application/json (or whatever) payload to send in the API request. It's updated to point to the multipart body reader.
ctypep is an in/out parameter. It should initially point to the content type of the bodyp, usually "application/json". It's updated to the "multipart/related" content type, with random boundary.
The return value is the content-length of the entire multpart body.
func ConvertVariant ¶
ConvertVariant uses the JSON encoder/decoder to fill in the struct 'dst' with the fields found in variant 'v'. This is used to support "variant" APIs that can return one of a number of different types. It reports whether the conversion was successful.
func DetectMediaType ¶ added in v0.5.0
DetectMediaType detects and returns the content type of the provided media. If the type can not be determined, "application/octet-stream" is returned.
func Expand ¶
Expand subsitutes any {encoded} strings in the URL passed in using the map supplied.
This calls SetOpaque to avoid encoding of the parameters in the URL path.
func ResolveRelative ¶
func SetOpaque ¶
SetOpaque sets u.Opaque from u.Path such that HTTP requests to it don't alter any hex-escaped characters in u.Path.
func VariantType ¶
VariantType returns the type name of the given variant. If the map doesn't contain the named key or the value is not a []interface{}, "" is returned. This is used to support "variant" APIs that can return one of a number of different types.
Types ¶
type ContentTyper ¶
type ContentTyper interface {
ContentType() string
}
ContentTyper is an interface for Readers which know (or would like to override) their Content-Type. If a media body doesn't implement ContentTyper, the type is sniffed from the content using http.DetectContentType.
type Error ¶
type Error struct { // Code is the HTTP response status code and will always be populated. Code int `json:"code"` // Message is the server response message and is only populated when // explicitly referenced by the JSON server response. Message string `json:"message"` // Body is the raw response returned by the server. // It is often but not always JSON, depending on how the request fails. Body string Errors []ErrorItem }
Error contains an error response from the server.
type ErrorItem ¶
type ErrorItem struct { // Reason is the typed error code. For example: "some_example". Reason string `json:"reason"` // Message is the human-readable description of the error. Message string `json:"message"` }
ErrorItem is a detailed error code & message from the Google API frontend.
type Field ¶
type Field string
A Field names a field to be retrieved with a partial response. See https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
Partial responses can dramatically reduce the amount of data that must be sent to your application. In order to request partial responses, you can specify the full list of fields that your application needs by adding the Fields option to your request.
Field strings use camelCase with leading lower-case characters to identify fields within the response.
For example, if your response has a "NextPageToken" and a slice of "Items" with "Id" fields, you could request just those fields like this:
svc.Events.List().Fields("nextPageToken", "items/id").Do()
or if you were also interested in each Item's "Updated" field, you can combine them like this:
svc.Events.List().Fields("nextPageToken", "items(id,updated)").Do()
More information about field formatting can be found here: https://developers.google.com/+/api/#fields-syntax
Another way to find field names is through the Google API explorer: https://developers.google.com/apis-explorer/#p/
type Float64s ¶
type Float64s []float64
Float64s is a slice of float64s that marshal as quoted strings in JSON.
func (Float64s) MarshalJSON ¶
func (*Float64s) UnmarshalJSON ¶
type Int32s ¶
type Int32s []int32
Int32s is a slice of int32s that marshal as quoted strings in JSON.
func (Int32s) MarshalJSON ¶
func (*Int32s) UnmarshalJSON ¶
type Int64s ¶
type Int64s []int64
Int64s is a slice of int64s that marshal as quoted strings in JSON.
func (Int64s) MarshalJSON ¶
func (*Int64s) UnmarshalJSON ¶
type MarshalStyle ¶
type MarshalStyle bool
func (MarshalStyle) JSONReader ¶
func (wrap MarshalStyle) JSONReader(v interface{}) (io.Reader, error)
type ProgressUpdater ¶ added in v0.5.0
type ProgressUpdater func(current, total int64)
ProgressUpdater is a function that is called upon every progress update of a resumable upload. This is the only part of a resumable upload (from googleapi) that is usable by the developer. The remaining usable pieces of resumable uploads is exposed in each auto-generated API.
type ResumableUpload ¶ added in v0.5.0
type ResumableUpload struct { Client *http.Client // URI is the resumable resource destination provided by the server after specifying "&uploadType=resumable". URI string UserAgent string // User-Agent for header of the request // Media is the object being uploaded. Media io.ReaderAt // MediaType defines the media type, e.g. "image/jpeg". MediaType string // ContentLength is the full size of the object being uploaded. ContentLength int64 // Callback is an optional function that will be called upon every progress update. Callback ProgressUpdater // contains filtered or unexported fields }
ResumableUpload is used by the generated APIs to provide resumable uploads. It is not used by developers directly.
func (*ResumableUpload) Progress ¶ added in v0.5.0
func (rx *ResumableUpload) Progress() int64
Progress returns the number of bytes uploaded at this point.
func (*ResumableUpload) Upload ¶ added in v0.5.0
Upload starts the process of a resumable upload with a cancellable context. It retries indefinitely (with a pause of uploadPause between attempts) until cancelled. It is called from the auto-generated API code and is not visible to the user. rx is private to the auto-generated API code.
type SizeReaderAt ¶ added in v0.5.0
A SizeReaderAt is a ReaderAt with a Size method. An io.SectionReader implements SizeReaderAt.
type Uint32s ¶
type Uint32s []uint32
Uint32s is a slice of uint32s that marshal as quoted strings in JSON.
func (Uint32s) MarshalJSON ¶
func (*Uint32s) UnmarshalJSON ¶
Directories ¶
Path | Synopsis |
---|---|
internal
|
|
uritemplates
Package uritemplates is a level 4 implementation of RFC 6570 (URI Template, http://tools.ietf.org/html/rfc6570).
|
Package uritemplates is a level 4 implementation of RFC 6570 (URI Template, http://tools.ietf.org/html/rfc6570). |
Package transport contains HTTP transports used to make authenticated API requests.
|
Package transport contains HTTP transports used to make authenticated API requests. |