This implementation is based on the legacy layout of GOPATH
which is deprecated now. It seems like CurrentModule()
should be used for the same purpose. Any idea?
|
func importPath(path string) string { |
|
path = strings.TrimPrefix(path, "/private") |
|
for _, gopath := range GoPaths() { |
|
srcpath := filepath.Join(gopath, "src") |
|
rel, err := filepath.Rel(srcpath, path) |
|
if err == nil { |
|
return filepath.ToSlash(rel) |
|
} |
|
} |
|
|
|
// fallback to trim |
|
rel := strings.TrimPrefix(path, filepath.Join(GoPath(), "src")) |
|
rel = strings.TrimPrefix(rel, string(filepath.Separator)) |
|
return filepath.ToSlash(rel) |
|
} |
|
func CurrentPackage() string { |
|
if Mods() { |
|
} |
|
pwd, _ := os.Getwd() |
|
return importPath(pwd) |
|
} |