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-03 23:36:56 +03:00
|
|
|
info, 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
|
|
|
|
pt.Pkg = info.ImportPath
|
|
|
|
}
|
|
|
|
|
|
|
|
if pt.Pkg == pt.Name || len(pt.Name) == 0 {
|
|
|
|
pt.Pkg = info.ImportPath
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|