blobstore

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2017 License: MIT Imports: 17 Imported by: 0

README

stakmachine/blobstore

GoDoc Build Status

Install

This repository does not include a vendor directory, so you'll need to use dep to manage your dependencies.

dep ensure stackmachine.com/blobstore

Usage

package main

import (
	"github.com/aws/aws-sdk-go/aws/session"
	"github.com/aws/aws-sdk-go/service/s3"

	"stackmachine.com/blobstore"
)

func main() {
	// Create a store backed by an S3 bucket
	sess := session.Must(session.NewSession())
	bucket := blobstore.NewS3(s3.New(session), "example-bucket-name")

	// Create another store backed by a local folder
	fs, _ := blobstore.NewFileSystem("cas")

	// Limit the size of this folder to 500MB
	lru := blobstore.LRU(int64(500)*1e+6, fs)

	// Sychnorize access to the LRU store
	cache := blobstore.NewSynchronized(lru)

	// Use the filesystem to cache the S3 bucket
	store := blobstore.Cached(main, cache)

	// Start all keys with a shared prefix
	final := blobstore.Prefixed("prefix", store)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// Return the contents at a given key. Returns an error if the key doesn't
	// exist.
	Get(key string) (io.ReadCloser, int64, error)

	// Store the contents of the input reader in the blobstore under the given key.
	Put(key string, blob io.Reader, length int64) error

	// Delete the contents stored at the given key
	Delete(key string) error

	// Returns true if the given key is already in the store. May return a
	// error if the store in unavailable
	Contains(key string) (bool, error)
}

func Cached

func Cached(authority Client, caches ...Client) Client

func LRU

func LRU(size int64, i Client) Client

Create a new LRU cache. Size is in bytes

func NewFileSystem

func NewFileSystem(path string) (Client, error)

func NewS3

func NewS3(svc *s3.S3, bucketName string) Client

func NewSynchronized

func NewSynchronized(c Client) Client

func Prefixed

func Prefixed(prefix string, i Client) Client

type Map

type Map struct {
	sync.Mutex
	Values map[string][]byte
}

useful for testing

func NewMap

func NewMap() *Map

func (*Map) Contains

func (m *Map) Contains(key string) (bool, error)

func (*Map) Delete

func (m *Map) Delete(key string) error

func (*Map) Get

func (m *Map) Get(key string) (io.ReadCloser, int64, error)

func (*Map) Put

func (m *Map) Put(key string, blob io.Reader, length int64) error

Jump to

Keyboard shortcuts

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