func (s *MetaStore) Locks(repo string) ([]Lock, error) {
	var locks []Lock
	err := s.db.View(func(tx *bolt.Tx) error {
		bucket := tx.Bucket(locksBucket)
		if bucket == nil {
			return errNoBucket
		}
		data := bucket.Get([]byte(repo))
		if data != nil {
			if err := json.Unmarshal(data, &locks); err != nil {
				return err
			}
		}
		return nil
	})
	return locks, err
}
Locks retrieves locks for the repo from the store
package main
import (
	"bytes"
	"encoding/gob"
	"encoding/json"
	"errors"
	"fmt"
	"math"
	"sort"
	"strconv"
	"time"
	"github.com/boltdb/bolt"
)
type MetaStore struct {
	db *bolt.DB
}
var (
	errNoBucket       = errors.New("Bucket not found")
	errObjectNotFound = errors.New("Object not found")
	errNotOwner       = errors.New("Attempt to delete other user's lock")
)
var (
	usersBucket   = []byte("users")
	objectsBucket = []byte("objects")
	locksBucket   = []byte("locks")
)
func NewMetaStore(dbFile string) (*MetaStore, error) {
	db, err := bolt.Open(dbFile, 0600, &bolt.Options{Timeout: 1 * time.Second})
	if err != nil {
		return nil, err
	}
	db.Update(func(tx *bolt.Tx) error {
		if _, err := tx.CreateBucketIfNotExists(usersBucket); err != nil {
			return err
		}
		if _, err := tx.CreateBucketIfNotExists(objectsBucket); err != nil {
			return err
		}
		if _, err := tx.CreateBucketIfNotExists(locksBucket); err != nil {
			return err
		}
		return nil
	})
	return &MetaStore{db: db}, nil
}
func (s *MetaStore) Get(v *RequestVars) (*MetaObject, error) {
	meta, error := s.UnsafeGet(v)
	return meta, error
}
func (s *MetaStore) UnsafeGet(v *RequestVars) (*MetaObject, error) {
	var meta MetaObject
	err := s.db.View(func(tx *bolt.Tx) error {
		bucket := tx.Bucket(objectsBucket)
		if bucket == nil {
			return errNoBucket
		}
		value := bucket.Get([]byte(v.Oid))
		if len(value) == 0 {
			return errObjectNotFound
		}
		dec := gob.NewDecoder(bytes.NewBuffer(value))
		return dec.Decode(&meta)
	})
	if err != nil {
		return nil, err
	}
	return &meta, nil
}
func (s *MetaStore) Put(v *RequestVars) (*MetaObject, error) {
	if meta, err := s.Get(v); err == nil {
		meta.Existing = true
		return meta, nil
	}
	var buf bytes.Buffer
	enc := gob.NewEncoder(&buf)
	meta := MetaObject{Oid: v.Oid, Size: v.Size}
	err := enc.Encode(meta)
	if err != nil {
		return nil, err
	}
	err = s.db.Update(func(tx *bolt.Tx) error {
		bucket := tx.Bucket(objectsBucket)
		if bucket == nil {
			return errNoBucket
		}
		err = bucket.Put([]byte(v.Oid), buf.Bytes())
		if err != nil {
			return err
		}
		return nil
	})
	if err != nil {
		return nil, err
	}
	return &meta, nil
}
func (s *MetaStore) Delete(v *RequestVars) error {
	err := s.db.Update(func(tx *bolt.Tx) error {
		bucket := tx.Bucket(objectsBucket)
		if bucket == nil {
			return errNoBucket
		}
		err := bucket.Delete([]byte(v.Oid))
		if err != nil {
			return err
		}
		return nil
	})
	return err
}
func (s *MetaStore) AddLocks(repo string, l ...Lock) error {
	err := s.db.Update(func(tx *bolt.Tx) error {
		bucket := tx.Bucket(locksBucket)
		if bucket == nil {
			return errNoBucket
		}
		var locks []Lock
		data := bucket.Get([]byte(repo))
		if data != nil {
			if err := json.Unmarshal(data, &locks); err != nil {
				return err
			}
		}
		locks = append(locks, l...)
		sort.Sort(LocksByCreatedAt(locks))
		data, err := json.Marshal(&locks)
		if err != nil {
			return err
		}
		return bucket.Put([]byte(repo), data)
	})
	return err
}