2018-05-26 06:27:06 +00:00
|
|
|
package filer2
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
type FullPath string
|
|
|
|
|
|
|
|
func NewFullPath(dir, name string) FullPath {
|
2019-03-31 06:08:29 +00:00
|
|
|
return FullPath(dir).Child(name)
|
2018-05-26 06:27:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2018-05-27 18:52:26 +00:00
|
|
|
func (fp FullPath) Name() string {
|
2018-05-26 06:27:06 +00:00
|
|
|
_, name := filepath.Split(string(fp))
|
|
|
|
return name
|
|
|
|
}
|
2019-03-31 06:08:29 +00:00
|
|
|
|
|
|
|
func (fp FullPath) Child(name string) FullPath {
|
|
|
|
dir := string(fp)
|
|
|
|
if strings.HasSuffix(dir, "/") {
|
|
|
|
return FullPath(dir + name)
|
|
|
|
}
|
|
|
|
return FullPath(dir + "/" + name)
|
|
|
|
}
|