AddImport adds imports to a section template that was generated with Header.
(section *SectionTemplate, imprts ...*ImportSpec)
| 37 | // AddImport adds imports to a section template that was generated with |
| 38 | // Header. |
| 39 | func AddImport(section *SectionTemplate, imprts ...*ImportSpec) { |
| 40 | if len(imprts) == 0 { |
| 41 | return |
| 42 | } |
| 43 | var specs []*ImportSpec |
| 44 | data := section.Data.(map[string]any) |
| 45 | if imports, ok := data["Imports"]; ok { |
| 46 | specs = imports.([]*ImportSpec) |
| 47 | } |
| 48 | seen := make(map[ImportSpec]struct{}, len(specs)+len(imprts)) |
| 49 | for _, spec := range specs { |
| 50 | seen[*spec] = struct{}{} |
| 51 | } |
| 52 | for _, spec := range imprts { |
| 53 | if _, ok := seen[*spec]; ok { |
| 54 | continue |
| 55 | } |
| 56 | seen[*spec] = struct{}{} |
| 57 | specs = append(specs, spec) |
| 58 | } |
| 59 | data["Imports"] = specs |
| 60 | } |
no outgoing calls
no test coverage detected