vendorlessImportPath returns the devendorized version of the provided import path. e.g. "foo/bar/vendor/a/b" => "a/b"
(ipath string, currentPackagePath string)
| 154 | // vendorlessImportPath returns the devendorized version of the provided import path. |
| 155 | // e.g. "foo/bar/vendor/a/b" => "a/b" |
| 156 | func vendorlessImportPath(ipath string, currentPackagePath string) (string, bool) { |
| 157 | split := strings.Split(ipath, "vendor/") |
| 158 | // no vendor in path |
| 159 | if len(split) == 1 { |
| 160 | return ipath, true |
| 161 | } |
| 162 | // this import path does not belong to the current package |
| 163 | if currentPackagePath != "" && !strings.Contains(currentPackagePath, split[0]) { |
| 164 | return "", false |
| 165 | } |
| 166 | // Devendorize for use in import statement. |
| 167 | if i := strings.LastIndex(ipath, "/vendor/"); i >= 0 { |
| 168 | return ipath[i+len("/vendor/"):], true |
| 169 | } |
| 170 | if strings.HasPrefix(ipath, "vendor/") { |
| 171 | return ipath[len("vendor/"):], true |
| 172 | } |
| 173 | return ipath, true |
| 174 | } |
| 175 | |
| 176 | //------------------------------------------------------------------------- |
| 177 | // print_backtrace |
no outgoing calls
no test coverage detected