refactoring

This commit is contained in:
Chris Lu
2018-05-25 23:27:06 -07:00
parent 6de84c64c6
commit c34feca59c
5 changed files with 129 additions and 79 deletions

31
weed/filer2/fullpath.go Normal file
View File

@@ -0,0 +1,31 @@
package filer2
import (
"path/filepath"
"strings"
)
type FullPath string
func NewFullPath(dir, name string) FullPath {
if strings.HasSuffix(dir, "/") {
return FullPath(dir + name)
}
return FullPath(dir + "/" + name)
}
func (fp FullPath) DirAndName() (string, string) {
dir, name := filepath.Split(string(fp))
if dir == "/" {
return dir, name
}
if len(dir) < 1 {
return "/", ""
}
return dir[:len(dir)-1], name
}
func (fp FullPath) Name() (string) {
_, name := filepath.Split(string(fp))
return name
}