(packageName string, si []*StructInfo, importName string)
| 165 | } |
| 166 | |
| 167 | func (im *InceptionMain) Generate(packageName string, si []*StructInfo, importName string) error { |
| 168 | var err error |
| 169 | if importName == "" { |
| 170 | importName, err = getImportName(im.goCmd, im.inputPath) |
| 171 | if err != nil { |
| 172 | return err |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | im.tempDir, err = ioutil.TempDir(filepath.Dir(im.inputPath), "ffjson-inception") |
| 177 | if err != nil { |
| 178 | return err |
| 179 | } |
| 180 | |
| 181 | importName = filepath.ToSlash(importName) |
| 182 | // for `go run` to work, we must have a file ending in ".go". |
| 183 | im.tempMain, err = TempFileWithPostfix(im.tempDir, "ffjson-inception", ".go") |
| 184 | if err != nil { |
| 185 | return err |
| 186 | } |
| 187 | |
| 188 | im.TempMainPath = im.tempMain.Name() |
| 189 | sn := make([]structName, len(si)) |
| 190 | for i, st := range si { |
| 191 | sn[i].Name = st.Name |
| 192 | sn[i].Options = st.Options |
| 193 | } |
| 194 | |
| 195 | tc := &templateCtx{ |
| 196 | ImportName: importName, |
| 197 | PackageName: packageName, |
| 198 | StructNames: sn, |
| 199 | InputPath: im.inputPath, |
| 200 | OutputPath: im.outputPath, |
| 201 | ResetFields: im.resetFields, |
| 202 | } |
| 203 | |
| 204 | t := template.Must(template.New("inception.go").Parse(inceptionMainTemplate)) |
| 205 | |
| 206 | err = im.renderTpl(im.tempMain, t, tc) |
| 207 | if err != nil { |
| 208 | return err |
| 209 | } |
| 210 | |
| 211 | im.tempExpose, err = os.Create(im.exposePath) |
| 212 | if err != nil { |
| 213 | return err |
| 214 | } |
| 215 | |
| 216 | t = template.Must(template.New("ffjson_expose.go").Parse(ffjsonExposeTemplate)) |
| 217 | |
| 218 | err = im.renderTpl(im.tempExpose, t, tc) |
| 219 | if err != nil { |
| 220 | return err |
| 221 | } |
| 222 | |
| 223 | return nil |
| 224 | } |
no test coverage detected