func (i *index) Get(path string) (string, bool) {
	i.RLock()
	defer i.RUnlock()
	x, ok := i.files[path]
	return x, ok
}
Get implements Index.
package cafs
import (
	"bytes"
	"crypto/sha1"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
	"sync"
	"golang.org/x/net/context"
	"tchaik.com/store"
)
type Index interface {
	Get(path string) (string, bool)
	Add(path string, sum string) (bool, error)
	Exists(sum string) bool
}
type index struct {
	sync.RWMutex
	files map[string]string  
	index map[string]bool    
	fs store.RWFileSystem
}
func NewIndex(fs store.RWFileSystem) (*index, error) {
	idx := &index{
		files: make(map[string]string),
		index: make(map[string]bool),
		fs:    fs,
	}
	f, err := fs.Open(context.TODO(), "index.json")
	if err != nil {
		return idx, nil
	}
	defer f.Close()
	dec := json.NewDecoder(f)
	err = dec.Decode(&idx)
	if err != nil {
		if err == io.EOF {
			return idx, nil
		}
		return nil, fmt.Errorf("error decoding index: %v", err)
	}
	fmt.Printf("Index initialised: %d files (%d paths)", len(idx.index), len(idx.files))
	return idx, nil
}
func (i *index) UnmarshalJSON(b []byte) error {
	i.Lock()
	defer i.Unlock()
	var exp struct {
		Files map[string]string
	}
	err := json.Unmarshal(b, &exp)
	if err != nil {
		return err
	}
	i.files = make(map[string]string)
	i.index = make(map[string]bool)
	for k, v := range exp.Files {
		i.index[v] = true
		i.files[k] = v
	}
	return nil
}