Move all the code to a lib folder

This commit is contained in:
Las Zenow 2016-05-02 21:36:49 -04:00
parent e963d00014
commit 9d1f1ad5c0
31 changed files with 123 additions and 98 deletions

42
lib/storage/dir.go Normal file
View file

@ -0,0 +1,42 @@
package storage
import (
p "path"
"os"
)
const (
dir_depth = 2
encodeURL = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
)
func mkstore(path string) error {
return _mkstore(path, dir_depth)
}
func _mkstore(path string, depth int) error {
err := os.MkdirAll(path, os.ModePerm)
if err != nil || depth == 0 {
return err
}
for _, l := range encodeURL {
next_path := p.Join(path, string(l))
err = _mkstore(next_path, depth-1)
if err != nil {
return err
}
}
return nil
}
func idPath(storePath string, id string) string {
path := storePath
for i := 0; i < dir_depth; i++ {
dir := string(id[i])
path = p.Join(path, dir)
}
path = p.Join(path, id)
return path
}