Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
shiqizng committed Mar 13, 2023
1 parent d6d56ee commit 6f4c231
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions conduit/plugins/processors/filterprocessor/gen/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,10 @@ func recursiveTagFields(theStruct interface{}, ignoreTags map[string]bool, outpu
return errors
}

func writeFieldsToFile(filepath string, fields map[string]internal.StructField) {
func writeFieldsToFile(filepath string, fields map[string]internal.StructField) error {
fout, err := os.Create(filepath)
if err != nil {
fmt.Fprintf(os.Stderr, "cannot open %s for writing: %v\n", filepath, err)
os.Exit(1)
return err
}
defer fout.Close()
// sort the tags
Expand All @@ -230,11 +229,21 @@ func writeFieldsToFile(filepath string, fields map[string]internal.StructField)
tags = append(tags, k)
}
sort.Strings(tags)
fout.WriteString(fmt.Sprintf("|%s|%s|\n", "filter tag", "transaction field"))
fout.WriteString("| -------- | ------- |\n")
_, err = fout.WriteString(fmt.Sprintf("|%s|%s|\n", "filter tag", "transaction field"))
if err != nil {
return err
}
_, err = fout.WriteString("| -------- | ------- |\n")
if err != nil {
return err
}
for _, tag := range tags {
fout.WriteString(fmt.Sprintf("|%s|%s|\n", tag, fields[tag].FieldPath))
_, err = fout.WriteString(fmt.Sprintf("|%s|%s|\n", tag, fields[tag].FieldPath))
if err != nil {
return err
}
}
return err
}

const templateStr = `// Code generated via go generate. DO NOT EDIT.
Expand Down Expand Up @@ -335,7 +344,9 @@ func main() {

// write filter tags to a file
if tagsFilepath != "" {
writeFieldsToFile(tagsFilepath, fields)
err = writeFieldsToFile(tagsFilepath, fields)
if err != nil {
fmt.Fprintf(os.Stderr, "error while creating file %s, err: %v\n", tagsFilepath, err)
}
}

}

0 comments on commit 6f4c231

Please sign in to comment.