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 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-09 05:35:01 +03:00
|
|
|
pathsCache.Store(p, pt)
|
2019-08-02 00:35:42 +03:00
|
|
|
return pt, nil
|
|
|
|
}
|