func Store(db *couchdb.DB, docid string, doc Doc) (string, error) {
	if rev, err := db.Rev(docid); err == nil {
		return db.Put(docid, doc, rev)
	} else if couchdb.NotFound(err) {
		return db.Put(docid, doc, "")
	} else {
		return "", err
	}
}
Store updates the given document in a database.
If the document exists, it will be overwritten.
The new revision of the document is returned.
package couchapp
import (
	"bytes"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"mime"
	"os"
	"path"
	"strings"
	"github.com/fjl/go-couchdb"
)
var DefaultIgnorePatterns = []string{
	"*~",  
	".*",  
	"_*",  
}
type Doc map[string]interface{}
func LoadFile(file string) (Doc, error) {
	val, err := loadJSON(file)
	if err != nil {
		return nil, err
	}
	mapval, ok := val.(map[string]interface{})
	if !ok {
		return nil, fmt.Errorf("%s does not contain a JSON object", file)
	}
	return Doc(mapval), nil
}
func LoadDirectory(dirname string, ignores []string) (Doc, error) {
	stack := &objstack{obj: make(Doc)}
	err := walk(dirname, ignores, func(p string, isDir, dirEnd bool) error {
		if dirEnd {
			stack = stack.parent  
			return nil
		}
		name := path.Base(p)
		if isDir {
			val := make(map[string]interface{})
			stack.obj[name] = val
			stack = &objstack{obj: val, parent: stack}  
		} else {
			content, err := load(p)
			if err != nil {
				return err
			}
			stack.obj[stripExtension(name)] = content
		}
		return nil
	})
	if err != nil {
		return nil, err
	}
	return stack.obj, err
}
type objstack struct {
	obj    map[string]interface{}
	parent *objstack
}
func load(filename string) (interface{}, error) {
	if path.Ext(filename) == ".json" {
		return loadJSON(filename)
	}
	return loadString(filename)
}
func loadString(file string) (string, error) {
	data, err := ioutil.ReadFile(file)
	if err != nil {
		return "", err
	}
	return string(bytes.Trim(data, " \n\r")), nil
}
func loadJSON(file string) (interface{}, error) {
	content, err := ioutil.ReadFile(file)
	if err != nil {
		return nil, err
	}
	var val interface{}
	if err := json.Unmarshal(content, &val); err != nil {
		if syntaxerr, ok := err.(*json.SyntaxError); ok {
			line := findLine(content, syntaxerr.Offset)
			err = fmt.Errorf("JSON syntax error at %v:%v: %v", file, line, err)
			return nil, err
		}
		return nil, fmt.Errorf("JSON unmarshal error in %v: %v", file, err)
	}
	return val, nil
}
func findLine(data []byte, offset int64) (line int) {
	line = 1
	for i, r := range string(data) {
		if int64(i) >= offset {
			return
		}
		if r == '\n' {
			line++
		}
	}
	return
}
func stripExtension(filename string) string {
	if i := strings.LastIndex(filename, "."); i != -1 {
		return filename[:i]
	}
	return filename
}