forked from go-gorm/gen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
import.go
67 lines (58 loc) · 1.07 KB
/
import.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package gen
import "strings"
var (
importList = new(importPkgS).Add(
"context",
"database/sql",
"strings",
"",
"gorm.io/gorm",
"gorm.io/gorm/schema",
"gorm.io/gorm/clause",
"",
"gorm.io/gen",
"gorm.io/gen/field",
"gorm.io/gen/helper",
"",
"gorm.io/plugin/dbresolver",
)
unitTestImportList = new(importPkgS).Add(
"context",
"fmt",
"strconv",
"testing",
"",
"gorm.io/driver/sqlite",
"gorm.io/gorm",
)
)
type importPkgS struct {
paths []string
}
func (ip importPkgS) Add(paths ...string) *importPkgS {
purePaths := make([]string, 0, len(paths)+1)
for _, p := range paths {
p = strings.TrimSpace(p)
if p == "" {
purePaths = append(purePaths, p)
continue
}
if p[len(p)-1] != '"' {
p = `"` + p + `"`
}
var exists bool
for _, existsP := range ip.paths {
if p == existsP {
exists = true
break
}
}
if !exists {
purePaths = append(purePaths, p)
}
}
purePaths = append(purePaths, "")
ip.paths = append(ip.paths, purePaths...)
return &ip
}
func (ip importPkgS) Paths() []string { return ip.paths }