| 28 | } |
| 29 | |
| 30 | func mergeImports(imps ...fileImports) [][]ImportSpec { |
| 31 | if len(imps) == 1 { |
| 32 | return [][]ImportSpec{ |
| 33 | imps[0].Std, |
| 34 | imps[0].Dep, |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | var stds, pkgs []ImportSpec |
| 39 | seenStd := map[string]struct{}{} |
| 40 | seenPkg := map[string]struct{}{} |
| 41 | for i := range imps { |
| 42 | for _, spec := range imps[i].Std { |
| 43 | if _, ok := seenStd[spec.Path]; ok { |
| 44 | continue |
| 45 | } |
| 46 | stds = append(stds, spec) |
| 47 | seenStd[spec.Path] = struct{}{} |
| 48 | } |
| 49 | for _, spec := range imps[i].Dep { |
| 50 | if _, ok := seenPkg[spec.Path]; ok { |
| 51 | continue |
| 52 | } |
| 53 | pkgs = append(pkgs, spec) |
| 54 | seenPkg[spec.Path] = struct{}{} |
| 55 | } |
| 56 | } |
| 57 | return [][]ImportSpec{stds, pkgs} |
| 58 | } |
| 59 | |
| 60 | type importer struct { |
| 61 | Options *opts.Options |