s3

package module
v0.0.0-...-66beaf3 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2013 License: MIT Imports: 7 Imported by: 0

README

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

Documentation:
http://godoc.org/github.com/AlekSi/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"
	"github.com/AlekSi/s3"
	"log"
	"net/http"
	"os"
	"strings"
	"time"
)

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.

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
y or Y : Canonical URL