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:
12
path/path.go
12
path/path.go
@ -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, "/")
|
||||
|
Reference in New Issue
Block a user