Version: v0.1.0 Latest Latest

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

Go to latest
Published: Nov 8, 2020 License: MIT Imports: 9 Imported by: 0



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.



This section is empty.


View Source
var DefaultIgnorePatterns = []string{

DefaultIgnorePatterns contains the default list of glob patterns that are ignored when building a document from a directory.


func Store

func Store(db *couchdb.DB, docid string, doc Doc) (string, error)

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.


type Doc

type Doc map[string]interface{}

Doc represents CouchDB documents.

func LoadDirectory

func LoadDirectory(dirname string, ignores []string) (Doc, error)

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:

  a.txt           // contains `text-a`
  b.json          // contains `{"key": 1}`
      f           // contains `text-f`

This would be compiled into the following JSON object:

  "a": "text-a",
  "b": {"key": 1},
  "c": {
    "": {},
    "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.

func LoadFile

func LoadFile(file string) (Doc, error)

LoadFile creates a document from a single JSON file.

Source Files

Jump to

Keyboard shortcuts

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