sabercat

package module
v0.0.0-...-ba7450d Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2015 License: BSD-3-Clause Imports: 11 Imported by: 0

README

sabercat is an implementation of net/http.FileSystem to serve files directly from MongoDB's GridFS.

Directory listing has not been implemented due to security concerns in our particular use case.


Version 1.4.12

Documentation

Index

Constants

View Source
const (
	// Per default items up to 20 Mibibytes in size will be cached
	DEFAULT_MAX_CACHEABLE_SIZE = 20 * (1 << (10 * 2))
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// Time for which a answer is held im memory. A TTL <= 0
	// makes the Cache pass all requests directly to the handler.
	TTL time.Duration
	// Handler, whose responses are supposed to be cached
	Handler http.Handler
	// Maximum number of bytes, with which an response is eligible
	// for caching (default: 20MiB)
	MaxCacheableSize int64
	// contains filtered or unexported fields
}

Cache is a `net/http.Handler`, which uses `net/http/httptest.ResponseRecorder` to record and recall the responses of the wrapped handler from memory if the same URL is requested again. The `net/http.Request.URL.Path` is used as the caching key.

func NewCache

func NewCache(d time.Duration, handler http.Handler) *Cache

NewCache returns a new Cache, which records the responses of the given handler for the given duration.

func (*Cache) ServeHTTP

func (ch *Cache) ServeHTTP(w http.ResponseWriter, r *http.Request)

type GridDir

type GridDir struct {
	GridFS *mgo.GridFS
	// If true, the leading slash will be stripped from requests
	StripSlash bool
}

GridDir implements net/http.FileSystem to serve contents directly from MongoDB's GridFS.

To serve all files from a database containing a GridFS called `fs` via http:

session, err := mgo.Dial("mongodb://localhost/database")
if err != nil {
    log.Fatalf("Could not connect to mongodb: %s", err)
}
gfs := session.DB("").GridFS("fs")
http.Handle("/", http.FileServer(sabercat.GridDir{gfs})

Directory listing has not been implemented.

func (GridDir) Open

func (gd GridDir) Open(filename string) (http.File, error)

Tries to open a file with the corresponding GridFS path. If the connection to the server broke, a single retry is issued.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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