s3protocol

package module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2022 License: MIT Imports: 13 Imported by: 0

README

s3protocol

Go Reference

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")

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!

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL