Package reportpanic Automatically report your programs panic.
// +build ignore
package main
import (
"github.com/mh-cbon/report-panic"
)
// wrap your main code with reportpanic.HandleMain,
// provide it a reporter such as Gh
func main() {
reportpanic.HandleMain(reportpanic.Gh("mh-cbon/demotest"), func() {
panic("oh no!")
})
}
// +build ignore
package main
import (
"github.com/mh-cbon/report-panic"
)
// wrap your main code with reportpanic.HandleMain,
// provide it a reporter such as Gh
func main() {
// Don t forget to change the GA ID.
reportpanic.HandleMain(reportpanic.Ga("UA-93911415-1", "my-program", "0.0.1"), func() {
panic("oh no!")
})
}
mkdir -p $GOPATH/src/github.com/mh-cbon/report-panic
cd $GOPATH/src/github.com/mh-cbon/report-panic
git clone https://github.com/mh-cbon/report-panic.git .
glide install
go install
You can only set
- GA ID
- Your program name
- Your program version
The GA reporter will emit pageview
on program start
, panic
as
http://localhost/<program>/<version>/<action>
To set a different token to report panics,
add this flag to your build compilation
--ldflags "-X reportpanic.GhReporterToken=xxxxx"
go build --ldflags "-X reportpanic.GhReporterToken=xxxxx"
- Access to the templater instance of the reporter
package main
import (
"github.com/mh-cbon/report-panic"
)
func main () {
reporter := reportpanic.Gh("your_user/your_repo")
reporter.Templater.Template = "template { {content} } here"
reportpanic.HandleMain(reporter, func () {
panic("oh no!")
})
}
- Or, use ldflags at build time
At build time, use ldflags
to configure the template
go build --ldflags "-X reportpanic.GhTemplate=your_tpl"
Register your_tpl
to panicreport
package main
import (
"github.com/mh-cbon/report-panic"
)
// register your template in the init, or main func
func init(){
panicreport.PanicReportTemplates["your_tpl"] = "template { {content} } here"
}
func main() {
reportpanic.HandleMain(reportpanic.Gh("your_user/your_repo"), func () {
panic("oh no!")
})
}
gump patch -d # check
gump patch # bump
Mitchell Hashimoto for the base code provided in panicwrap