Documentation
¶
Overview ¶
Package gsprotocol provides the http.RoundTripper interface for Google Cloud Storage.
The typical use case is to register the "gs" protocol with a http.Transport, as in:
tr := &http.Transport{}
gs, err := gsprotocol.NewTransport(context.Background(), option.WithoutAuthentication())
if err != nil {
// handle error
}
tr.RegisterProtocol("gs", gs)
c := &http.Client{Transport: tr}
resp, err := c.Get("gs://shogo82148-gsprotocol/example.txt")
if err != nil {
// handle error
}
defer resp.Body.Close()
// read resp.Body
Google Cloud Storage supports object versioning. To access the noncurrent version of an object, use a uri like gs://[BUCKET_NAME]/[OBJECT_NAME]#[GENERATION_NUMBER]. For example,
resp, err := c.Get("gs://shogo82148-gsprotocol/example.txt#1587160158394554")
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport serving the Google Cloud Storage objects.
func NewTransport ¶
NewTransport returns a new Transport.
Example ¶
package main
import (
"context"
"io"
"net/http"
"os"
"github.com/shogo82148/gsprotocol"
"google.golang.org/api/option"
)
func main() {
tr := &http.Transport{}
gs, err := gsprotocol.NewTransport(context.Background(), option.WithoutAuthentication())
if err != nil {
panic(err)
}
tr.RegisterProtocol("gs", gs)
c := &http.Client{Transport: tr}
resp, err := c.Get("gs://shogo82148-gsprotocol/example.txt")
if err != nil {
panic(err)
}
defer resp.Body.Close()
if _, err := io.Copy(os.Stdout, resp.Body); err != nil {
panic(err)
}
}
Output: Hello Google Cloud Storage!
func NewTransportWithClient ¶
NewTransportWithClient returns a new Transport.
Click to show internal directories.
Click to hide internal directories.