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 ¶
- Variables
- func Register(impl AppEngine)
- type AppEngine
- type CacheKey
- type Context
- func (c *Context) CacheLoad(name, path string, value interface{}) (ckey CacheKey, found bool)
- func (c *Context) CacheRead(name, path string) (ckey CacheKey, data []byte, found bool)
- func (c *Context) CacheStore(ckey CacheKey, value interface{})
- func (c *Context) CacheWrite(ckey CacheKey, data []byte)
- func (c *Context) Criticalf(format string, args ...interface{})
- func (c *Context) Mkdir(path string) error
- func (c *Context) Read(path string) ([]byte, *proto.FileInfo, error)
- func (c *Context) ReadDir(path string) ([]proto.FileInfo, error)
- func (c *Context) Remove(path string) error
- func (c *Context) ServeFile(w http.ResponseWriter, req *http.Request, name string)
- func (c *Context) User() string
- func (c *Context) Write(path string, data []byte) error
Constants ¶
This section is empty.
Variables ¶
var Root = "."
Root is the root of the local file system. It has no effect on App Engine.
Functions ¶
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 ¶
NewContext returns a context associated with the given HTTP request.
func (*Context) CacheLoad ¶
CacheLoad uses CacheRead to load gob-encoded data and decodes it into value.
func (*Context) CacheRead ¶
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 ¶
CacheStore uses CacheWrite to save the gob-encoded form of value.
func (*Context) CacheWrite ¶
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) Mkdir ¶
Mkdir creates a directory with the given path. If the path already exists and is a directory, Mkdir returns no error.
func (*Context) Read ¶
Read returns the data associated with the file named by path. It is a copy and can be modified without affecting the file.