path string
}
+type NotFoundError struct {
+ path string
+}
+
+func (e NotFoundError) Error() string {
+ return "not found: " + e.path
+}
+
func Open(root string) (c *Conn, err error) {
c = new(Conn)
c.path, err = filepath.Abs(root)
}
func (c *Conn) Get(name, k string) (v []byte, err error) {
- return ioutil.ReadFile(filepath.Join(c.path, name, k))
+ v, err = ioutil.ReadFile(filepath.Join(c.path, name, k))
+ if err != nil {
+ if p, ok := err.(*os.PathError); ok && p.Err == os.ENOENT {
+ err = NotFoundError{name+"/"+k}
+ }
+ }
+ return
}
func (c *Conn) Ensure(name string) (err error) {