fs

package
v0.0.0-...-6ad75e1 Latest Latest
Warning

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

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

Documentation

Overview

Package fs is an indirection layer, allowing code to use a file system without knowing whether it is the host file system (running without App Engine) or the datastore-based app file system (running on App Engine).

When compiled locally, fs refers to files in the local file system, and the cache saves nothing.

When compiled for App Engine, fs uses the appfs file system and the memcache-based cache.

Index

Constants

This section is empty.

Variables

View Source
var Root = "."

Root is the root of the local file system. It has no effect on App Engine.

Functions

func Register

func Register(impl AppEngine)

Types

type AppEngine

type AppEngine interface {
	NewContext(req *http.Request) interface{}
	CacheRead(ctxt interface{}, name, path string) (key interface{}, data []byte, found bool)
	CacheWrite(ctxt, key interface{}, data []byte)
	Read(ctxt interface{}, path string) ([]byte, *proto.FileInfo, error)
	Write(ctxt interface{}, path string, data []byte) error
	Remove(ctxt interface{}, path string) error
	Mkdir(ctxt interface{}, path string) error
	ReadDir(ctxt interface{}, path string) ([]proto.FileInfo, error)
	Criticalf(ctxt interface{}, format string, args ...interface{})
	User(ctxt interface{}) string
}

type CacheKey

type CacheKey struct {
	// contains filtered or unexported fields
}

A CacheKey is an opaque cache key that can be used to store new entries in the cache. To ensure that the cache remains consistent with the underlying file system, the correct procedure is:

1. Use CacheRead (or CacheLoad) to attempt to load the entry. If it succeeds, use it. If not, continue, saving the CacheKey.

2. Read from the file system and construct the entry that would have been in the cache. In order to be consistent, all the file system reads should only refer to parts of the file system in the tree rooted at the path passed to CacheRead.

3. Save the entry using CacheWrite (or CacheStore), using the key that was created by the CacheRead (or CacheLoad) executed before reading from the file system.

type Context

type Context struct {
	// contains filtered or unexported fields
}

A Context is an opaque context that is needed to perform file system operations. Each context is associated with a single HTTP request.

func NewContext

func NewContext(req *http.Request) *Context

NewContext returns a context associated with the given HTTP request.

func (*Context) CacheLoad

func (c *Context) CacheLoad(name, path string, value interface{}) (ckey CacheKey, found bool)

CacheLoad uses CacheRead to load gob-encoded data and decodes it into value.

func (*Context) CacheRead

func (c *Context) CacheRead(name, path string) (ckey CacheKey, data []byte, found bool)

CacheRead reads from cache the entry with the given name and path. The path specifies the scope of information stored in the cache entry. An entry is invalidated by a write to any location in the file tree rooted at path. The name is an uninterpreted identifier to distinguish the cache entry from other entries using the same path.

If it finds a cache entry, CacheRead returns the data and found=true. If it does not find a cache entry, CacheRead returns data=nil and found=false. Either way, CacheRead returns an appropriate cache key for storing to the cache entry using CacheWrite.

func (*Context) CacheStore

func (c *Context) CacheStore(ckey CacheKey, value interface{})

CacheStore uses CacheWrite to save the gob-encoded form of value.

func (*Context) CacheWrite

func (c *Context) CacheWrite(ckey CacheKey, data []byte)

CacheWrite writes an entry to the cache with the given key, path, and data. The cache entry will be invalidated the next time the file tree rooted at path is modified in anyway.

func (*Context) Criticalf

func (c *Context) Criticalf(format string, args ...interface{})

Criticalf logs the message at critical priority.

func (*Context) Mkdir

func (c *Context) Mkdir(path string) error

Mkdir creates a directory with the given path. If the path already exists and is a directory, Mkdir returns no error.

func (*Context) Read

func (c *Context) Read(path string) ([]byte, *proto.FileInfo, error)

Read returns the data associated with the file named by path. It is a copy and can be modified without affecting the file.

func (*Context) ReadDir

func (c *Context) ReadDir(path string) ([]proto.FileInfo, error)

ReadDir returns the contents of the directory named by the path.

func (*Context) Remove

func (c *Context) Remove(path string) error

Remove removes the file named by path.

func (*Context) ServeFile

func (c *Context) ServeFile(w http.ResponseWriter, req *http.Request, name string)

ServeFile serves the named file as the response to the HTTP request.

func (*Context) User

func (c *Context) User() string

User returns the name of the user running the request.

func (*Context) Write

func (c *Context) Write(path string, data []byte) error

Write replaces the data associated with the file named by path.

Jump to

Keyboard shortcuts

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