diff --git a/cheapcash.go b/cheapcash.go index fc75eb6..891adc0 100644 --- a/cheapcash.go +++ b/cheapcash.go @@ -2,6 +2,7 @@ package cheapcash import ( "errors" + "strings" "sync" ) @@ -22,6 +23,10 @@ func Default() *Cache { } func New(path string) *Cache { + if !strings.HasSuffix(path, "/") { + path += "/" + } + return &Cache{ Path: path, } diff --git a/cheapcash_test.go b/cheapcash_test.go index 0bd1cda..e257fec 100644 --- a/cheapcash_test.go +++ b/cheapcash_test.go @@ -24,8 +24,8 @@ func TestDefault(t *testing.T) { func TestNew(t *testing.T) { c := cheapcash.New("/somewhere") - if c.Path != "/somewhere" { - t.Error("expected path to return /somewhere, got:", c.Path) + if c.Path != "/somewhere/" { + t.Error("expected path to return /somewhere/, got:", c.Path) } } diff --git a/delete.go b/delete.go index bf6835c..f5e2c7f 100644 --- a/delete.go +++ b/delete.go @@ -3,7 +3,7 @@ package cheapcash import "os" func (c *Cache) Delete(key string) error { - check, err := c.Exists(c.Path + "/" + key) + check, err := c.Exists(c.Path + key) if err != nil { return err } @@ -12,7 +12,7 @@ func (c *Cache) Delete(key string) error { return ErrNotExists } - err = os.Remove(sanitizePath(c.Path + "/" + key)) + err = os.Remove(sanitizePath(c.Path + key)) if err != nil { return err } diff --git a/writer.go b/writer.go index 74318dc..69787d1 100644 --- a/writer.go +++ b/writer.go @@ -8,7 +8,7 @@ func (c *Cache) Write(key string, value []byte) error { return err } - check, err := c.Exists(key) + check, err := c.Exists(c.Path + key) if err != nil { return err }