From 75c1eae7f26fc6a18573e84a1fc90b8735a1ae8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zlatko=20=C4=8Calu=C5=A1i=C4=87?= Date: Fri, 11 Nov 2016 01:29:55 +0100 Subject: [PATCH] Add isHashed() --- handlers.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/handlers.go b/handlers.go index a834b59..6239439 100644 --- a/handlers.go +++ b/handlers.go @@ -17,6 +17,10 @@ type Context struct { path string } +func isHashed(dir string) bool { + return dir == "data" +} + // AuthHandler wraps h with a http.HandlerFunc that performs basic authentication against the user/passwords pairs // stored in f and returns the http.HandlerFunc. func AuthHandler(f *HtpasswdFile, h http.Handler) http.HandlerFunc { @@ -91,7 +95,7 @@ func ListBlobs(c *Context) http.HandlerFunc { var names []string for _, i := range items { - if dir == "data" { + if isHashed(dir) { subpath := filepath.Join(path, i.Name()) subitems, err := ioutil.ReadDir(subpath) if err != nil { @@ -123,7 +127,7 @@ func CheckBlob(c *Context) http.HandlerFunc { dir := vars[1] name := vars[2] - if dir == "data" { + if isHashed(dir) { name = filepath.Join(name[:2], name) } path := filepath.Join(c.path, dir, name) @@ -145,7 +149,7 @@ func GetBlob(c *Context) http.HandlerFunc { dir := vars[1] name := vars[2] - if dir == "data" { + if isHashed(dir) { name = filepath.Join(name[:2], name) } path := filepath.Join(c.path, dir, name) @@ -194,7 +198,7 @@ func SaveBlob(c *Context) http.HandlerFunc { return } - if dir == "data" { + if isHashed(dir) { name = filepath.Join(name[:2], name) } path := filepath.Join(c.path, dir, name) @@ -217,7 +221,7 @@ func DeleteBlob(c *Context) http.HandlerFunc { dir := vars[1] name := vars[2] - if dir == "data" { + if isHashed(dir) { name = filepath.Join(name[:2], name) } path := filepath.Join(c.path, dir, name)