Skip to content

Commit

Permalink
Replace slash with underscore (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
knqyf263 committed May 13, 2019
1 parent 15c98ac commit e1980f9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io"
"os"
"path/filepath"
"strings"

"github.com/knqyf263/fanal/utils"

Expand All @@ -12,10 +13,11 @@ import (

var (
cacheDir = utils.CacheDir()
replacer = strings.NewReplacer("/", "_")
)

func Get(key string) io.Reader {
filePath := filepath.Join(cacheDir, key)
filePath := filepath.Join(cacheDir, replacer.Replace(key))
f, err := os.Open(filePath)
if err != nil {
return nil
Expand All @@ -24,7 +26,7 @@ func Get(key string) io.Reader {
}

func Set(key string, file io.Reader) (io.Reader, error) {
filePath := filepath.Join(cacheDir, key)
filePath := filepath.Join(cacheDir, replacer.Replace(key))
if err := os.MkdirAll(cacheDir, os.ModePerm); err != nil {
return nil, xerrors.Errorf("failed to mkdir all: %w", err)
}
Expand Down

0 comments on commit e1980f9

Please sign in to comment.