Skip to content

Commit

Permalink
Merge pull request #26 from Stebalien/fix/map-type-name
Browse files Browse the repository at this point in the history
correctly map typegen to cbg in all cases
  • Loading branch information
whyrusleeping authored Jul 10, 2020
2 parents 3f18919 + 226a6ff commit ef07013
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,17 @@ func typeName(pkg string, t reflect.Type) string {
case reflect.Map:
return "map[" + typeName(pkg, t.Key()) + "]" + typeName(pkg, t.Elem())
default:
return strings.TrimPrefix(t.String(), pkg+".")
name := t.String()
if t.PkgPath() == "github.com/whyrusleeping/cbor-gen" {
name = "cbg." + strings.TrimPrefix(name, "typegen.")
} else {
name = strings.TrimPrefix(name, pkg+".")
}
return name
}
}

func (f Field) TypeName() string {
if f.Type.PkgPath() == "github.com/whyrusleeping/cbor-gen" {
return "cbg" + strings.TrimPrefix(typeName(f.Pkg, f.Type), "typegen")
}
return typeName(f.Pkg, f.Type)
}

Expand Down

0 comments on commit ef07013

Please sign in to comment.