- // generate Go package code
- w := bufio.NewWriter(f)
- if err := generatePackage(ctx, w); err != nil {
- return err
- }
-
- // go format the output file (fail probably means the output is not compilable)
- cmd := exec.Command("gofmt", "-w", ctx.outputFile)
- if output, err := cmd.CombinedOutput(); err != nil {
- return fmt.Errorf("gofmt failed: %v\n%s", err, string(output))
- }
-
- // count number of lines in generated output file
- cmd = exec.Command("wc", "-l", ctx.outputFile)
- if output, err := cmd.CombinedOutput(); err != nil {
- log.Warnf("wc command failed: %v\n%s", err, string(output))
- } else {
- logf("generated lines: %s", output)
- }
-
- return nil
-}
-
-// readFile reads content of a file into memory
-func readFile(inputFile string) ([]byte, error) {
- inputData, err := ioutil.ReadFile(inputFile)
- if err != nil {
- return nil, fmt.Errorf("reading data from file failed: %v", err)
- }
-
- return inputData, nil
-}
-
-// parseJSON parses a JSON data into an in-memory tree
-func parseJSON(inputData []byte) (*jsongo.JSONNode, error) {
- root := jsongo.JSONNode{}
-
- if err := json.Unmarshal(inputData, &root); err != nil {
- return nil, fmt.Errorf("unmarshalling JSON failed: %v", err)
- }
-
- return &root, nil
-}
-
-func logf(f string, v ...interface{}) {
- if *debug {
- logrus.Debugf(f, v...)
- }
+ binapigen.Run(apiDir, filesToGenerate, opts, func(gen *binapigen.Generator) error {
+ for _, file := range gen.Files {
+ if !file.Generate {
+ continue
+ }
+ binapigen.GenerateAPI(gen, file)
+ for _, p := range genPlugins {
+ if err := binapigen.RunPlugin(p, gen, file); err != nil {
+ return err
+ }
+ }
+ }
+ return nil
+ })