Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use reflectutils.TypeName() for versioned type names #58

Merged
merged 2 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion error.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func duplicateTypes() string {
return duplicates
}
names := make(map[string]struct{})
for i := 1; i <= typeCounter; i++ {
for i := 1; i <= max; i++ {
n := typeCode(i).String()
if _, ok := names[n]; ok {
if _, ok := duplicatesFound[n]; !ok {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.16

require (
github.com/kr/pretty v0.2.0 // indirect
github.com/muir/reflectutils v0.6.0
github.com/muir/reflectutils v0.7.0
github.com/stretchr/testify v1.8.1
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfn
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/muir/reflectutils v0.6.0 h1:jXfbW60Nx+STn78vwUWVCUwInXkqAC5kWS5oeY/xPgM=
github.com/muir/reflectutils v0.6.0/go.mod h1:l8W7iTj6zMdmsWcPfsdnaAYLEuipJ7baVROqpfuonIc=
github.com/muir/reflectutils v0.7.0 h1:7ez7OLYTThDQ5kpEpxtOgFvJgtE4E11D6PVTVw+Lwl0=
github.com/muir/reflectutils v0.7.0/go.mod h1:l8W7iTj6zMdmsWcPfsdnaAYLEuipJ7baVROqpfuonIc=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
3 changes: 0 additions & 3 deletions internal/foo/foo.go

This file was deleted.

3 changes: 0 additions & 3 deletions internal/foo/v2/foo.go

This file was deleted.

20 changes: 3 additions & 17 deletions type_codes.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ package nject
// TODO: switch from typeCode to reflect.Type -- duplicate detection would be lost

import (
"path"
"reflect"
"regexp"
"strings"
"sync"

"github.com/muir/reflectutils"
)

type typeCode int
Expand Down Expand Up @@ -76,22 +75,9 @@ func (tc typeCode) Type() reflect.Type {
return reverseMap[tc]
}

var versionRE = regexp.MustCompile(`/v(\d+)$`)

// Type returns the reflect.Type for this typeCode
func (tc typeCode) String() string {
ts := tc.Type().String()
if versionRE.MatchString(tc.Type().PkgPath()) {
pp := tc.Type().PkgPath()
version := path.Base(pp)
pn := path.Base(path.Dir(pp))
revised := strings.Replace(ts, pn, pn+"/"+version, 1)
if revised != ts {
return revised
}
return "(" + version + ")" + ts
}
return ts
return reflectutils.TypeName(tc.Type())
}

func (tcs typeCodes) Types() []reflect.Type {
Expand Down
28 changes: 0 additions & 28 deletions type_codes_test.go

This file was deleted.