You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
627 B

7 years ago
7 years ago
7 years ago
7 years ago
  1. package filer2
  2. import (
  3. "path/filepath"
  4. "strings"
  5. )
  6. type FullPath string
  7. func NewFullPath(dir, name string) FullPath {
  8. return FullPath(dir).Child(name)
  9. }
  10. func (fp FullPath) DirAndName() (string, string) {
  11. dir, name := filepath.Split(string(fp))
  12. if dir == "/" {
  13. return dir, name
  14. }
  15. if len(dir) < 1 {
  16. return "/", ""
  17. }
  18. return dir[:len(dir)-1], name
  19. }
  20. func (fp FullPath) Name() string {
  21. _, name := filepath.Split(string(fp))
  22. return name
  23. }
  24. func (fp FullPath) Child(name string) FullPath {
  25. dir := string(fp)
  26. if strings.HasSuffix(dir, "/") {
  27. return FullPath(dir + name)
  28. }
  29. return FullPath(dir + "/" + name)
  30. }