Example #1
0
func GenerateThrift(name string, in io.Reader) (out string, err error) {
	var (
		p  *parser.Parser
		th *parser.Thrift
		g  *GoGenerator
		b  *bytes.Buffer
	)
	if th, err = p.Parse(in); err != nil {
		return
	}
	g = &GoGenerator{th.MergeIncludes()}
	b = new(bytes.Buffer)
	if err = g.Generate(name, b); err != nil {
		return
	}
	out = b.String()
	return
}
Example #2
0
func ReadFiles(files []string) (map[string]parser.Thrift, error) {
	output := make(map[string]parser.Thrift)

	thriftParser := parser.Parser{}

	for _, file := range files {
		files_map, _, err := thriftParser.ParseFile(file)
		if err != nil {
			return output, fmt.Errorf("Error parsing Thrift IDL file %s: %s", file, err)
		}

		for fname, parsedFile := range files_map {
			output[fname] = *parsedFile
		}
	}

	return output, nil
}