Beispiel #1
0
func processFile(generateThrift bool, inputFile string, outputFile string) error {
	if generateThrift {
		if outFile, err := runThrift(inputFile, *apacheThriftImport); err != nil {
			return fmt.Errorf("Could not generate thrift output: %v", err)
		} else if outputFile == "" {
			outputFile = outFile
		}
	}

	parser := &parser.Parser{}
	parsed, _, err := parser.ParseFile(inputFile)
	if err != nil {
		return fmt.Errorf("Could not parse .thrift file: %v", err)
	}

	goTmpl := parseTemplate()
	for filename, v := range parsed {
		if err := generateCode(outputFile, goTmpl, packageName(filename), v); err != nil {
			return err
		}
		// TODO(prashant): Support multiple files / includes etc?
		return nil
	}

	return nil
}
Beispiel #2
0
func parseFile(inputFile string) (map[string]parseState, error) {
	parser := &parser.Parser{}
	parsed, _, err := parser.ParseFile(inputFile)
	if err != nil {
		return nil, err
	}

	allParsed := make(map[string]parseState)
	for filename, v := range parsed {
		state := newState(v, allParsed)
		services, err := wrapServices(v, state)
		if err != nil {
			return nil, fmt.Errorf("wrap services failed: %v", err)
		}
		allParsed[filename] = parseState{v, state, services}
	}
	return allParsed, setExtends(allParsed)
}