Skip to content

Commit

Permalink
interfaces: remove vendor prefix from a package path (rjeczalik#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
kohkimakimoto authored Aug 7, 2022
1 parent 6a73761 commit 915e862
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions type.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,15 @@ func fixup(typ *Type, q *Query) {
}

typ.Name = strings.Replace(typ.Name, q.Package, path.Base(q.Package), -1)
typ.ImportPath = trimVendorPath(typ.ImportPath)
}

// trimVendorPath removes the vendor dir prefix from a package path.
// example: github.com/foo/bar/vendor/github.com/pkg/errors -> github.com/pkg/errors.
func trimVendorPath(p string) string {
parts := strings.Split(p, "/vendor/")
if len(parts) == 1 {
return p
}
return strings.TrimLeft(path.Join(parts[1:]...), "/")
}

0 comments on commit 915e862

Please sign in to comment.