1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-09-10 09:52:20 +08:00

address concerns about user interface with new Path type

This commit is contained in:
Jeromy
2015-01-30 19:55:38 +00:00
parent 1c891dbdc1
commit 9ddfafb40a
5 changed files with 27 additions and 12 deletions

View File

@ -3,12 +3,24 @@ package path
import (
"path"
"strings"
u "github.com/jbenet/go-ipfs/util"
)
// TODO: debate making this a private struct wrapped in a public interface
// would allow us to control creation, and cache segments.
type Path string
// FromString safely converts a string type to a Path type
func FromString(s string) Path {
return Path(s)
}
// FromKey safely converts a Key type to a Path type
func FromKey(k u.Key) Path {
return Path(k.String())
}
func (p Path) Segments() []string {
cleaned := path.Clean(string(p))
segments := strings.Split(cleaned, "/")