github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/utils/alter/splitpath.go (about) 1 package alter 2 3 import ( 4 "errors" 5 "strings" 6 ) 7 8 // SplitPath takes a string with a prefixed delimiter and separates it into a slice of path elements 9 func SplitPath(path string) ([]string, error) { 10 split := strings.Split(path, string(path[0])) 11 if len(split) == 0 || (len(split) == 1 && split[0] == "") { 12 return nil, errors.New("empty path") 13 } 14 15 if split[0] == "" { 16 split = split[1:] 17 } 18 19 return split, nil 20 }