MCPcopy Create free account
hub / github.com/goadesign/goa / AddImport

Function AddImport

codegen/header.go:39–60  ·  view source on GitHub ↗

AddImport adds imports to a section template that was generated with Header.

(section *SectionTemplate, imprts ...*ImportSpec)

Source from the content-addressed store, hash-verified

37// AddImport adds imports to a section template that was generated with
38// Header.
39func 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}

Callers 3

AddUserTypeImportsFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected