- return files, nil
-}
-
-func parseInputJSON(inputData []byte) (*jsongo.JSONNode, error) {
- jsonRoot := new(jsongo.JSONNode)
- if err := json.Unmarshal(inputData, jsonRoot); err != nil {
- return nil, fmt.Errorf("unmarshalling JSON failed: %v", err)
- }
- return jsonRoot, nil
-}
-
-// generateFromFile generates Go package from one input JSON file
-func generateFromFile(inputFile, outputDir string) error {
- // create generator context
- ctx, err := newContext(inputFile, outputDir)
- if err != nil {
- return err
- }
-
- logf("------------------------------------------------------------")
- logf("module: %s", ctx.moduleName)
- logf(" - input: %s", ctx.inputFile)
- logf(" - output: %s", ctx.outputFile)
- logf("------------------------------------------------------------")
-
- // prepare options
- ctx.includeAPIVersion = *includeAPIVer
- ctx.includeComments = *includeComments
- ctx.includeBinapiNames = *includeBinapiNames
- ctx.includeServices = *includeServices
-
- // read API definition from input file
- ctx.inputData, err = ioutil.ReadFile(ctx.inputFile)
- if err != nil {
- return fmt.Errorf("reading input file %s failed: %v", ctx.inputFile, err)
- }
- // parse JSON data into objects
- jsonRoot, err := parseInputJSON(ctx.inputData)
- if err != nil {
- return fmt.Errorf("parsing JSON input failed: %v", err)
- }
- ctx.packageData, err = parsePackage(ctx, jsonRoot)
- if err != nil {
- return fmt.Errorf("parsing package %s failed: %v", ctx.packageName, err)
- }