2019-08-02 05:34:32 +03:00
|
|
|
package pkger
|
2019-08-02 00:35:42 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"regexp"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
var pathrx = regexp.MustCompile("([^:]+)(:(/.+))?")
|
|
|
|
|
|
|
|
func Parse(p string) (Path, error) {
|
2019-08-03 23:36:56 +03:00
|
|
|
return rootIndex.Parse(p)
|
2019-08-02 00:35:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func build(p, pkg, name string) (Path, error) {
|
|
|
|
pt := Path{
|
|
|
|
Pkg: pkg,
|
|
|
|
Name: name,
|
|
|
|
}
|
|
|
|
|
2019-08-05 00:13:27 +03:00
|
|
|
current, err := Stat()
|
2019-08-02 00:35:42 +03:00
|
|
|
if err != nil {
|
|
|
|
return pt, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if strings.HasPrefix(pt.Pkg, "/") || len(pt.Pkg) == 0 {
|
|
|
|
pt.Name = pt.Pkg
|
2019-08-05 00:13:27 +03:00
|
|
|
pt.Pkg = current.ImportPath
|
2019-08-02 00:35:42 +03:00
|
|
|
}
|
|
|
|
|
2019-08-05 00:13:27 +03:00
|
|
|
if len(pt.Name) == 0 {
|
|
|
|
pt.Name = "/"
|
|
|
|
}
|
|
|
|
|
|
|
|
if pt.Pkg == pt.Name {
|
|
|
|
pt.Pkg = current.ImportPath
|
|
|
|
pt.Name = "/"
|
2019-08-02 00:35:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.HasPrefix(pt.Name, "/") {
|
|
|
|
pt.Name = "/" + pt.Name
|
|
|
|
}
|
2019-08-03 23:36:56 +03:00
|
|
|
rootIndex.Paths.Store(p, pt)
|
2019-08-02 00:35:42 +03:00
|
|
|
return pt, nil
|
|
|
|
}
|