s3

package
Version: v0.0.0-...-9c27ee3 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2016 License: MIT, MIT Imports: 7 Imported by: 2

README

Package s3 signs HTTP requests for use with Amazon’s S3 API.

Documentation:
http://godoc.org/github.com/kr/s3

Documentation

Overview

Package s3 signs HTTP requests for Amazon S3 and compatible services.

Index

Examples

Constants

This section is empty.

Variables

View Source
var DefaultService = &Service{Domain: "amazonaws.com"}

DefaultService is the default Service used by Sign.

Functions

func AmazonBucket

func AmazonBucket(subdomain string) string

AmazonBucket returns everything up to the last '.' in subdomain. It is designed to be used with the Amazon service.

"johnsmith.s3"           becomes "johnsmith"
"johnsmith.s3-eu-west-1" becomes "johnsmith"
"www.example.com.s3"     becomes "www.example.com"

func IdentityBucket

func IdentityBucket(subdomain string) string

IdentityBucket returns subdomain. It is designed to be used with S3-compatible services that treat the entire subdomain as the bucket name, for example storage.io.

func Sign

func Sign(r *http.Request, k Keys)

Sign signs an HTTP request with the given S3 keys.

This function is a wrapper around DefaultService.Sign.

Example
package main

import (
	"fmt"
	"log"
	"net/http"
	"os"
	"strings"
	"time"

	"github.com/heroku/hk/Godeps/_workspace/src/github.com/kr/s3"
)

func main() {
	keys := s3.Keys{
		AccessKey: os.Getenv("S3_ACCESS_KEY"),
		SecretKey: os.Getenv("S3_SECRET_KEY"),
	}
	data := strings.NewReader("hello, world")
	r, _ := http.NewRequest("PUT", "https://example.s3.amazonaws.com/foo", data)
	r.ContentLength = int64(data.Len())
	r.Header.Set("Date", time.Now().UTC().Format(http.TimeFormat))
	r.Header.Set("X-Amz-Acl", "public-read")
	s3.Sign(r, keys)
	resp, err := http.DefaultClient.Do(r)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(resp.StatusCode)
}
Output:

Types

type Keys

type Keys struct {
	AccessKey string
	SecretKey string

	// SecurityToken is used for temporary security credentials.
	// If set, it will be added to header field X-Amz-Security-Token
	// before signing a request.
	SecurityToken string
}

Keys holds a set of Amazon Security Credentials.

type Service

type Service struct {
	// Domain is the service's root domain. It is used to extract
	// the subdomain from an http.Request before passing the
	// subdomain to Bucket.
	Domain string

	// Bucket derives the bucket name from a subdomain.
	// If nil, AmazonBucket is used.
	Bucket func(subdomain string) string
}

Service represents an S3-compatible service.

func (*Service) Sign

func (s *Service) Sign(r *http.Request, k Keys)

Sign signs an HTTP request with the given S3 keys for use on service s.

Source Files

Directories

Path Synopsis
Command s3cp copies a file to or from Amazon S3.
Command s3cp copies a file to or from Amazon S3.
Package s3util provides streaming transfers to and from Amazon S3.
Package s3util provides streaming transfers to and from Amazon S3.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL