1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-09-09 17:22:21 +08:00
Files
kubo/path/path.go
gatesvp 31ff954539 Move IPNS resolutions into the core library
Move IPNS resolutions into the core library via the pathresolver.go
file. Fix the CLI commands to leverage this core component.
2015-04-20 01:04:30 -07:00

42 lines
799 B
Go

package path
import (
u "github.com/ipfs/go-ipfs/util"
"path"
"strings"
)
// 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, "/")
// Ignore leading slash
if len(segments[0]) == 0 {
segments = segments[1:]
}
return segments
}
func (p Path) String() string {
return string(p)
}
func FromSegments(seg ...string) Path {
return Path(strings.Join(seg, "/"))
}