Get golang coverage programmatically

code-coverage, go

Solution

You can try `axw/gocov`, which:

- will run test with a `-coverprofile` argument

- parse the results (`gocov/convert.go`)

You can see a tool like GoCov GUI uses `gocov.Statement` in `convert_statements(s []*gocov.Statement, offset int)` in order to build a small GUI:

Problem

The go -cover or -coverprofile is great when running go tests and can show nicely in html or plain text. But is there an api to access it programmatically or process the file?

Original source