Documentation
¶
Overview ¶
Package s3protocol provides the http.RoundTripper interface for Amazon S3 (Simple Storage Service).
The typical use case is to register the "s3" protocol with a http.Transport, as in:
s := session.Must(session.NewSession(&aws.Config{
Credentials: credentials.AnonymousCredentials,
}))
s3 := s3protocol.NewTransport(s)
t := &http.Transport{}
t.RegisterProtocol("s3", s3)
c := &http.Client{Transport: t}
resp, err := c.Get("s3://shogo82148-s3protocol/example.txt")
if err != nil {
// handle error
}
defer resp.Body.Close()
// read resp.Body
Amazon S3 supports object versioning. To access the noncurrent version of an object, use a uri like s3://[BUCKET_NAME]/[OBJECT_NAME]?versionId=[VERSION_ID]. For example,
resp, err := c.Get("s3://shogo82148-s3protocol/example.txt?versionId=null")
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 S3 objects.
func NewTransport ¶
func NewTransport(c client.ConfigProvider) *Transport
NewTransport returns a new Transport.
Example ¶
package main
import (
"io"
"net/http"
"os"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/shogo82148/s3protocol"
)
func main() {
s := session.Must(session.NewSession(&aws.Config{
Credentials: credentials.AnonymousCredentials,
}))
s3 := s3protocol.NewTransport(s)
t := &http.Transport{}
t.RegisterProtocol("s3", s3)
c := &http.Client{Transport: t}
resp, err := c.Get("s3://shogo82148-s3protocol/example.txt")
if err != nil {
panic(err)
}
defer resp.Body.Close()
io.Copy(os.Stdout, resp.Body)
}
Output: Hello Amazon S3!
Click to show internal directories.
Click to hide internal directories.