GenerateImports generates our import statements and package definition.
(t *template.Template, externalImports []string, packageName string, versionOverride *string)
| 1072 | |
| 1073 | // GenerateImports generates our import statements and package definition. |
| 1074 | func GenerateImports(t *template.Template, externalImports []string, packageName string, versionOverride *string) (string, error) { |
| 1075 | // Read build version for incorporating into generated files |
| 1076 | // Unit tests have ok=false, so we'll just use "unknown" for the |
| 1077 | // version if we can't read this. |
| 1078 | |
| 1079 | modulePath := "unknown module path" |
| 1080 | moduleVersion := "unknown version" |
| 1081 | if bi, ok := debug.ReadBuildInfo(); ok { |
| 1082 | if bi.Main.Path != "" { |
| 1083 | modulePath = bi.Main.Path |
| 1084 | } |
| 1085 | if bi.Main.Version != "" { |
| 1086 | moduleVersion = bi.Main.Version |
| 1087 | } |
| 1088 | if versionOverride != nil { |
| 1089 | moduleVersion = *versionOverride |
| 1090 | } |
| 1091 | } |
| 1092 | |
| 1093 | context := struct { |
| 1094 | ExternalImports []string |
| 1095 | PackageName string |
| 1096 | ModuleName string |
| 1097 | Version string |
| 1098 | AdditionalImports []AdditionalImport |
| 1099 | RouterImports []AdditionalImport |
| 1100 | }{ |
| 1101 | ExternalImports: externalImports, |
| 1102 | PackageName: packageName, |
| 1103 | ModuleName: modulePath, |
| 1104 | Version: moduleVersion, |
| 1105 | AdditionalImports: globalState.options.AdditionalImports, |
| 1106 | RouterImports: globalState.options.Generate.RouterImports(), |
| 1107 | } |
| 1108 | |
| 1109 | return GenerateTemplates([]string{"imports.tmpl"}, t, context) |
| 1110 | } |
| 1111 | |
| 1112 | // GenerateAdditionalPropertyBoilerplate generates all the glue code which provides |
| 1113 | // the API for interacting with additional properties and JSON-ification |
no test coverage detected