You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
internal/dinosql: strip leading "go-" or trailing "-go" from import (#262)
If I try to import from a package named "go-x" or "x-go" it will
generate a syntax error. We should do the right thing and determine
what the package name is and set it to that, but in lieu of that,
a good guess for the import name is just stripping that prefix or
suffix.
Updates #261.
Copy file name to clipboardExpand all lines: internal/dinosql/config.go
+14-3Lines changed: 14 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -102,13 +102,24 @@ func (o *Override) Parse() error {
102
102
// validate GoType
103
103
lastDot:=strings.LastIndex(o.GoType, ".")
104
104
iflastDot==-1 {
105
-
returnfmt.Errorf("Package override `go_type` specificier %q is not the proper format, expected 'package.type', e.g. 'github.com/segmentio/ksuid.KSUID'", o.GoType)
105
+
returnfmt.Errorf("Package override `go_type` specifier %q is not the proper format, expected 'package.type', e.g. 'github.com/segmentio/ksuid.KSUID'", o.GoType)
106
106
}
107
107
lastSlash:=strings.LastIndex(o.GoType, "/")
108
108
iflastSlash==-1 {
109
-
returnfmt.Errorf("Package override `go_type` specificier %q is not the proper format, expected 'package.type', e.g. 'github.com/segmentio/ksuid.KSUID'", o.GoType)
109
+
returnfmt.Errorf("Package override `go_type` specifier %q is not the proper format, expected 'package.type', e.g. 'github.com/segmentio/ksuid.KSUID'", o.GoType)
110
110
}
111
-
o.goTypeName=o.GoType[lastSlash+1:]
111
+
typename:=o.GoType[lastSlash+1:]
112
+
ifstrings.HasPrefix(typename, "go-") {
113
+
// a package name beginning with "go-" will give syntax errors in
114
+
// generated code. We should do the right thing and get the actual
115
+
// import name, but in lieu of that, stripping the leading "go-" may get
0 commit comments