github.com/friesencr/pop/v6@v6.1.6/genny/model/imports.go (about) 1 package model 2 3 import ( 4 "path" 5 "sort" 6 "strings" 7 ) 8 9 func buildImports(opts *Options) []string { 10 imps := map[string]bool{ 11 "github.com/gobuffalo/validate/v3": true, 12 "github.com/friesencr/pop/v6": true, 13 } 14 if opts.Encoding == "jsonapi" { 15 imps["github.com/google/jsonapi"] = true 16 imps["strings"] = true 17 } else { 18 imps[path.Join("encoding", strings.ToLower(opts.Encoding))] = true 19 } 20 ats := opts.Attrs 21 for _, a := range ats { 22 switch a.GoType() { 23 case "uuid", "uuid.UUID": 24 imps["github.com/gofrs/uuid/v5"] = true 25 case "time.Time": 26 imps["time"] = true 27 default: 28 if strings.HasPrefix(a.GoType(), "nulls") { 29 imps["github.com/gobuffalo/nulls"] = true 30 } 31 if strings.HasPrefix(a.GoType(), "slices") { 32 imps["github.com/friesencr/pop/v6/slices"] = true 33 } 34 } 35 } 36 i := make([]string, 0, len(imps)) 37 for k := range imps { 38 i = append(i, k) 39 } 40 sort.Strings(i) 41 return i 42 }