I am trying to upload the line coverage data periodically while the binary code is running. I've tried to use RegisterCover to inject mine Cover instance but failed to get any data other than zero value from it. Meanwhile the hack function GetCover could always return the data no matter when and where I call it.
So the working way (and it's convenient) I found so far is to add this GetCover function to return the package level variable cover in src/testing/cover.go:
NOTE: This struct is internal to the testing infrastructure and may change. It is not covered (yet) by the Go 1 compatibility guidelines.
Many parts of the testing library predate "internal" packages, and were exported for internal usage only. I think there's a single example in the Go codebase of how to use RegisterCover, but again, it could break in the future and we have no promises to support it externally.
Finally, I don't think we will be adding a new API to something that ought to have been internal in the first place, so I am going to close this issue.
I don't know the best way to help you do what you want, but a better place to ask this kind of question is golang-nuts. See https://golang.org/wiki/Questions. It'll reach a wider audience of people who may have tried something similar.