Documentation ¶
Overview ¶
Package raygun4go adds Raygun-based error handling to your golang code.
It basically adds an error-handler that recovers from all panics that might occur and sends information about that error to Raygun. The amount of data being sent is configurable.
Basic example:
raygun, err := raygun4go.New("appName", "apiKey") if err != nil { log.Println("Unable to create Raygun client:", err.Error()) } defer raygun.HandleError()
This will send the error message together with a stack trace to Raygun.
However, raygun4go really starts to shine if used in a webserver context. By calling
raygun.Request(*http.Request)
you can set a request to be analyzed in case of an error. If an error occurs, this will send the request details to Raygun, including
- hostname
- url
- http method
- ip adress
- url parameters
- POSTed form fields
- headers
- cookies
giving you a lot more leverage on your errors than the plain error message could provide you with.
Chainable configuration methods are available (see below) to set the affected version, user, tags or custom data.
Index ¶
- type Client
- func (c *Client) CreateError(message string) error
- func (c *Client) CreatePost(err error, stackTruncateAt int) Post
- func (c *Client) CustomData(data interface{}) *Client
- func (c *Client) HandleError() error
- func (c *Client) LogToStdOut(l bool) *Client
- func (c *Client) Request(r *http.Request) *Client
- func (c *Client) Silent(s bool) *Client
- func (c *Client) SubmitPost(post Post) error
- func (c *Client) Tags(tags []string) *Client
- func (c *Client) User(u string) *Client
- func (c *Client) Version(v string) *Client
- type Post
- type UserCustomData
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the struct holding your Raygun configuration and context information that is needed if an error occurs.
func New ¶
New creates and returns a Client, needing an appName and an apiKey. It also creates a unique identifier for you program.
func (*Client) CreateError ¶
CreateError is a simple wrapper to manually post messages (errors) to raygun
func (*Client) CreatePost ¶
CreatePost is a wrapper to manually post errors to raygun. It also allows to specify the index for stack trace truncation.
func (*Client) CustomData ¶
CustomData is a chainable option-setting method to add arbitrary custom data to the context. Note that the given type (or at least parts of it) must implement the Marshaler-interface for this to work.
func (*Client) HandleError ¶
HandleError sets up the error handling code. It needs to be called with
defer c.HandleError()
to handle all panics inside the calling function and all calls made from it. Be sure to call this in your main function or (if it is webserver) in your request handler as soon as possible.
func (*Client) LogToStdOut ¶
LogToStdOut sets the logToStdOut-property on the Client. If true, errors will be printed to std out as they are submitted to raygun. This will also log any errors that occur when submiting to raygun to std out
func (*Client) Request ¶
Request is a chainable option-setting method to add a request to the context.
func (*Client) Silent ¶
Silent sets the silent-property on the Client. If true, errors will not be sent to Raygun but printed instead.
func (*Client) SubmitPost ¶
SubmitPost is a wrapper to manually post errors to raygun asynchronously (having previously captured a stack trace on a separate goroutine, using c.CreatePost())
func (*Client) Tags ¶
Tags is a chainable option-setting method to add tags to the context. You can use tags to filter errors in Raygun.
type Post ¶
type Post struct {
// contains filtered or unexported fields
}
Post holds postData (including a stack). This allows for asynchronous reporting to raygun (without losing the stack trace)
type UserCustomData ¶
type UserCustomData interface{}
UserCustomData is the interface that needs to be implemented by the custom data to be sent with the error. Being 'interface{}' suggests that it could be anything, but the data itself or contained data should respond to json.Marshal() for the data to be transmitted.