Documentation
¶
Overview ¶
Package couchapp implements a mapping from files to CouchDB documents.
CouchDB design documents, which contain view definitions etc., are stored as JSON objects in the database. A 'couchapp' is a directory structure that is compiled into a design document and then installed into the database. The functions in this package are probably most useful for uploading design documents, but can be used for any kind of document.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultIgnorePatterns = []string{
"*~",
".*",
"_*",
}
DefaultIgnorePatterns contains the default list of glob patterns that are ignored when building a document from a directory.
Functions ¶
func Store ¶
Store updates the given document in a database. If the document exists, it will be overwritten. The new revision of the document is returned.
func StoreAttachments ¶
func StoreAttachments( db *couchdb.DB, docid, rev, dir string, ignores []string, ) (newrev string, err error)
StoreAttachments uploads the files in a directory as attachments to a document extension. The document does not need to exist in the database. The MIME type of each file is guessed by x the filename.
As with LoadDirectory, ignores is a slice of glob patterns that are matched against the file/directory basename. If any one of them matches, the file is not uploaded. If a nil slice is given, the default patterns are used.
A correct revision id is returned in all cases, even if there was an error.
Types ¶
type Doc ¶
type Doc map[string]interface{}
Doc represents CouchDB documents.
func LoadDirectory ¶
LoadDirectory transforms a directory structure on disk into a JSON object. All directories become JSON objects whose keys are file and directory names. For regular files, the file extension is stripped from the key. Files with the .json extension are included as JSON.
Example tree:
<root>/ a.txt // contains `text-a` b.json // contains `{"key": 1}` c/ d.xyz/ e/ f // contains `text-f`
This would be compiled into the following JSON object:
{ "a": "text-a", "b": {"key": 1}, "c": { "d.xyz": {}, "e": { "f": "text-f" } } }
The second argument is a slice of glob patterns for ignored files. If nil is given, the default patterns are used. The patterns are matched against the basename, not the full path.