A Raygun.io golang client for handling errors.
##Usage
import (
"github.com/gsblue/raygunclient"
"errors"
)
var n raygunclient.Notifier
func init() {
n := raygunclient.NewClient("your api key", "application version no", nil)
}
func SomeFunctionWhichNeedsToHandleError() {
if someErr := doSomeWork(); someErr != nil {
entry := NewErrorEntry(someErr)
entry.SetUser("user identifier").
SetTags([]string{"tag 1", "tag 2"}).
SetCustomData(&struct{ OrderNo int }{340})
if err := n.Notify(entry); err != nil {
panic(err)
}
}
}
func doSomeWork() error {
return errors.New("some error")
}
If you are capturing an error in context of a http request, you can send the request data too
import (
"github.com/gsblue/raygunclient"
"errors"
)
var n raygunclient.Notifier
func init() {
n := raygunclient.NewClient("your api key", "application version no", nil)
}
func handle(w http.ResponseWriter, r *http.Request) {
if someErr := doSomeWork(); someErr != nil {
entry := NewErrorEntry(someErr)
entry.SetRequest(r)
if err := n.Notify(entry); err != nil {
panic(err)
}
}
}
func doSomeWork() error {
return errors.New("some error")
}
Note, by default stack trace is captured and sent to raygun.
If you need to send custom stack trace, use NotifyWithStackTrace
method.
Pull requests are welcome.