mirror of https://github.com/aldy505/cheapcash.git
fix: bug on file location
This commit is contained in:
parent
e6f33ca1d4
commit
012b2befd3
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue