Skip to content

Commit

Permalink
case insensitive compare to determine self package
Browse files Browse the repository at this point in the history
  • Loading branch information
vektah committed Jun 23, 2018
1 parent c0158f5 commit 4ffa2b2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions codegen/import_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ func (s *Imports) add(path string) *Import {
return nil
}

if stringHasSuffixFold(s.destDir, path) {
return nil
}

if existing := s.findByPath(path); existing != nil {
return existing
}
Expand All @@ -66,17 +70,17 @@ func (s *Imports) add(path string) *Import {
return imp
}

func stringHasSuffixFold(s, suffix string) bool {
return len(s) >= len(suffix) && strings.EqualFold(s[len(s)-len(suffix):], suffix)
}

func (s Imports) finalize() []*Import {
// ensure stable ordering by sorting
sort.Slice(s.imports, func(i, j int) bool {
return s.imports[i].Path > s.imports[j].Path
})

for _, imp := range s.imports {
if strings.HasSuffix(s.destDir, imp.Path) {
imp.Alias = ""
continue
}
alias := imp.Name

i := 1
Expand Down
2 changes: 1 addition & 1 deletion codegen/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func bindObject(t types.Type, object *Object, imports *Imports) error {
pkg, typ := pkgAndType(structField.Type().String())
imp := imports.findByPath(pkg)
field.CastType = typ
if imp.Alias != "" {
if imp != nil {
field.CastType = imp.Alias + "." + typ
}

Expand Down

0 comments on commit 4ffa2b2

Please sign in to comment.