@@ -195,44 +195,54 @@ func (r Result) Imports(settings PackageSettings) func(string) [][]string {
195
195
}
196
196
197
197
func (r Result ) ModelImports () [][]string {
198
- var std [] string
198
+ std := make ( map [ string ] struct {})
199
199
if r .UsesType ("sql.Null" ) {
200
- std = append ( std , "database/sql" )
200
+ std [ "database/sql" ] = struct {}{}
201
201
}
202
202
if r .UsesType ("json.RawMessage" ) {
203
- std = append ( std , "encoding/json" )
203
+ std [ "encoding/json" ] = struct {}{}
204
204
}
205
205
if r .UsesType ("time.Time" ) {
206
- std = append ( std , "time" )
206
+ std [ "time" ] = struct {}{}
207
207
}
208
208
if r .UsesType ("net.IP" ) {
209
- std = append ( std , "net" )
209
+ std [ "net" ] = struct {}{}
210
210
}
211
211
212
212
// Custom imports
213
- var pkg [] string
213
+ pkg := make ( map [ string ] struct {})
214
214
overrideTypes := map [string ]string {}
215
215
for _ , o := range append (r .Settings .Overrides , r .packageSettings .Overrides ... ) {
216
216
overrideTypes [o .goTypeName ] = o .goPackage
217
217
}
218
218
219
219
_ , overrideNullTime := overrideTypes ["pq.NullTime" ]
220
220
if r .UsesType ("pq.NullTime" ) && ! overrideNullTime {
221
- pkg = append ( pkg , "github.com/lib/pq" )
221
+ pkg [ "github.com/lib/pq" ] = struct {}{}
222
222
}
223
223
224
224
_ , overrideUUID := overrideTypes ["uuid.UUID" ]
225
225
if r .UsesType ("uuid.UUID" ) && ! overrideUUID {
226
- pkg = append ( pkg , "github.com/google/uuid" )
226
+ pkg [ "github.com/google/uuid" ] = struct {}{}
227
227
}
228
228
229
229
for goType , importPath := range overrideTypes {
230
- if r .UsesType (goType ) {
231
- pkg = append ( pkg , importPath )
230
+ if _ , ok := std [ importPath ]; ! ok && r .UsesType (goType ) {
231
+ pkg [ importPath ] = struct {}{}
232
232
}
233
233
}
234
234
235
- return [][]string {std , pkg }
235
+ pkgs := make ([]string , 0 , len (pkg ))
236
+ for p , _ := range pkg {
237
+ pkgs = append (pkgs , p )
238
+ }
239
+
240
+ stds := make ([]string , 0 , len (std ))
241
+ for s , _ := range std {
242
+ stds = append (stds , s )
243
+ }
244
+
245
+ return [][]string {stds , pkgs }
236
246
}
237
247
238
248
func (r Result ) QueryImports (filename string ) [][]string {
@@ -314,46 +324,58 @@ func (r Result) QueryImports(filename string) [][]string {
314
324
return false
315
325
}
316
326
317
- std := []string {"context" }
327
+ std := map [string ]struct {}{
328
+ "context" : struct {}{},
329
+ }
318
330
if uses ("sql.Null" ) {
319
- std = append ( std , "database/sql" )
331
+ std [ "database/sql" ] = struct {}{}
320
332
}
321
333
if uses ("json.RawMessage" ) {
322
- std = append ( std , "encoding/json" )
334
+ std [ "encoding/json" ] = struct {}{}
323
335
}
324
336
if uses ("time.Time" ) {
325
- std = append ( std , "time" )
337
+ std [ "time" ] = struct {}{}
326
338
}
327
339
if uses ("net.IP" ) {
328
- std = append ( std , "net" )
340
+ std [ "net" ] = struct {}{}
329
341
}
330
342
331
- var pkg [] string
343
+ pkg := make ( map [ string ] struct {})
332
344
overrideTypes := map [string ]string {}
333
345
for _ , o := range append (r .Settings .Overrides , r .packageSettings .Overrides ... ) {
334
346
overrideTypes [o .goTypeName ] = o .goPackage
335
347
}
336
348
337
349
if sliceScan () {
338
- pkg = append ( pkg , "github.com/lib/pq" )
350
+ pkg [ "github.com/lib/pq" ] = struct {}{}
339
351
}
340
352
_ , overrideNullTime := overrideTypes ["pq.NullTime" ]
341
353
if uses ("pq.NullTime" ) && ! overrideNullTime {
342
- pkg = append ( pkg , "github.com/lib/pq" )
354
+ pkg [ "github.com/lib/pq" ] = struct {}{}
343
355
}
344
356
_ , overrideUUID := overrideTypes ["uuid.UUID" ]
345
357
if uses ("uuid.UUID" ) && ! overrideUUID {
346
- pkg = append ( pkg , "github.com/google/uuid" )
358
+ pkg [ "github.com/google/uuid" ] = struct {}{}
347
359
}
348
360
349
361
// Custom imports
350
362
for goType , importPath := range overrideTypes {
351
- if uses (goType ) {
352
- pkg = append ( pkg , importPath )
363
+ if _ , ok := std [ importPath ]; ! ok && uses (goType ) {
364
+ pkg [ importPath ] = struct {}{}
353
365
}
354
366
}
355
367
356
- return [][]string {std , pkg }
368
+ pkgs := make ([]string , 0 , len (pkg ))
369
+ for p , _ := range pkg {
370
+ pkgs = append (pkgs , p )
371
+ }
372
+
373
+ stds := make ([]string , 0 , len (std ))
374
+ for s , _ := range std {
375
+ stds = append (stds , s )
376
+ }
377
+
378
+ return [][]string {stds , pkgs }
357
379
}
358
380
359
381
func (r Result ) Enums () []GoEnum {
0 commit comments