Skip to content

Commit

Permalink
Merge pull request #38 from foomo/fix/package-prefix-resolution
Browse files Browse the repository at this point in the history
fix: issue with same package prefix
  • Loading branch information
franklinkim committed Nov 16, 2023
2 parents 31ed425 + 9483bec commit f9cd69e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ name: checks
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ v2 ]
branches: [ main ]
pull_request:
branches: [ v2 ]
branches: [ main ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

Expand Down
6 changes: 3 additions & 3 deletions gotsrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func Reply(response []interface{}, stats *CallStats, r *http.Request, w http.Res
stats.ErrorCode = 1
stats.ErrorType = fmt.Sprintf("%T", v)
stats.ErrorMessage = v.Error()
if v, ok := v.(interface {
if v, ok := v.(interface { //nolint:errorlint
ErrorCode() int
}); ok {
stats.ErrorCode = v.ErrorCode()
Expand Down Expand Up @@ -146,7 +146,7 @@ func parseDir(goPaths []string, gomod config.Namespace, packageName string) (map
fset := token.NewFileSet()
if gomod.ModFile != nil {
for _, rep := range gomod.ModFile.Replace {
if strings.HasPrefix(packageName, rep.Old.Path) {
if packageName == rep.Old.Path || strings.HasPrefix(packageName, rep.Old.Path+"/") {
if strings.HasPrefix(rep.New.String(), ".") || strings.HasPrefix(rep.New.Path, "/") {
trace("replacing package with local dir", packageName, rep.Old.String(), rep.New.String())
dir = strings.Replace(packageName, rep.Old.Path, filepath.Join(gomod.Path, rep.New.Path), 1)
Expand All @@ -159,7 +159,7 @@ func parseDir(goPaths []string, gomod config.Namespace, packageName string) (map
}
if dir == "" {
for _, req := range gomod.ModFile.Require {
if strings.HasPrefix(packageName, req.Mod.Path) {
if packageName == req.Mod.Path || strings.HasPrefix(packageName, req.Mod.Path+"/") {
trace("resolving mod package", packageName, req.Mod.String())
dir = strings.TrimSuffix(path.Join(goPath, "pkg", "mod", req.Mod.String(), strings.TrimPrefix(packageName, req.Mod.Path)), "/")
break
Expand Down

0 comments on commit f9cd69e

Please sign in to comment.