forked from gobuffalo/pop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
imports.go
42 lines (40 loc) · 898 Bytes
/
imports.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
package model
import (
"path"
"sort"
"strings"
)
func buildImports(opts *Options) []string {
imps := map[string]bool{
"github.com/gobuffalo/validate": true,
"github.com/gobuffalo/pop": true,
}
if opts.Encoding == "jsonapi" {
imps["github.com/google/jsonapi"] = true
imps["strings"] = true
} else {
imps[path.Join("encoding", strings.ToLower(opts.Encoding))] = true
}
ats := opts.Attrs
for _, a := range ats {
switch a.GoType() {
case "uuid", "uuid.UUID":
imps["github.com/gofrs/uuid"] = true
case "time.Time":
imps["time"] = true
default:
if strings.HasPrefix(a.GoType(), "nulls") {
imps["github.com/gobuffalo/nulls"] = true
}
if strings.HasPrefix(a.GoType(), "slices") {
imps["github.com/gobuffalo/pop/slices"] = true
}
}
}
i := make([]string, 0, len(imps))
for k := range imps {
i = append(i, k)
}
sort.Strings(i)
return i
}