Skip to content

Commit 903b060

Browse files
committed
internal/config: use strings.Trim{Prefix,Suffix}
This is equivalent and slightly simpler.
1 parent b0d6f13 commit 903b060

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

internal/config/go_type.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,12 @@ func (gt GoType) Parse() (*ParsedGoType, error) {
138138
return nil, fmt.Errorf("Package override `go_type` specifier %q is not the proper format, expected 'package.type', e.g. 'github.com/segmentio/ksuid.KSUID'", input)
139139
}
140140
typename = input[lastSlash+1:]
141-
if strings.HasPrefix(typename, "go-") {
142-
// a package name beginning with "go-" will give syntax errors in
143-
// generated code. We should do the right thing and get the actual
144-
// import name, but in lieu of that, stripping the leading "go-" may get
145-
// us what we want.
146-
typename = typename[len("go-"):]
147-
}
148-
if strings.HasSuffix(typename, "-go") {
149-
typename = typename[:len(typename)-len("-go")]
150-
}
141+
// a package name beginning with "go-" will give syntax errors in
142+
// generated code. We should do the right thing and get the actual
143+
// import name, but in lieu of that, stripping the leading "go-" may get
144+
// us what we want.
145+
typename = strings.TrimPrefix(typename, "go-")
146+
typename = strings.TrimSuffix(typename, "-go")
151147
o.ImportPath = input[:lastDot]
152148
}
153149
o.TypeName = typename

0 commit comments

Comments
 (0)