Skip to content

Commit

Permalink
Use streaming decoder and encoder.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekSi committed Sep 3, 2013
1 parent 09f97f5 commit 9d9c20b
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions gocov-xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,8 @@ type Line struct {
}

func main() {
data, err := ioutil.ReadAll(os.Stdin)
if err != nil {
panic(err)
}
var r struct{ Packages []gocov.Package }
err = json.Unmarshal(data, &r)
err := json.NewDecoder(os.Stdin).Decode(&r)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -135,11 +131,15 @@ func main() {

coverage := Coverage{Packages: packages, Timestamp: time.Now().UnixNano() / int64(time.Millisecond)}

data, err = xml.MarshalIndent(coverage, "", "\t")
fmt.Printf(xml.Header)
fmt.Printf("<!DOCTYPE coverage SYSTEM \"http://cobertura.sourceforge.net/xml/coverage-03.dtd\">\n")

encoder := xml.NewEncoder(os.Stdout)
encoder.Indent("", "\t")
err = encoder.Encode(coverage)
if err != nil {
panic(err)
}
fmt.Printf(xml.Header)
fmt.Printf("<!DOCTYPE coverage SYSTEM \"http://cobertura.sourceforge.net/xml/coverage-03.dtd\">")
fmt.Printf("%s\n", data)

fmt.Println()
}

0 comments on commit 9d9c20b

Please sign in to comment.