forked from go-gorm/gen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
import.go
59 lines (54 loc) · 987 Bytes
/
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
package gen
import "strings"
var (
importList = 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 = 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 {
for _, p := range paths {
p = strings.TrimSpace(p)
if p == "" {
ip.paths = append(ip.paths, 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 {
ip.paths = append(ip.paths, p)
}
}
ip.paths = append(ip.paths, "")
return &ip
}
func (ip *importPkgS) Output() []string { return ip.paths }