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, ctx gcontext.Context)
- func (c *Client) CustomData(data interface{}) *Client
- func (c *Client) HandleError(ctx gcontext.Context)
- func (c *Client) Request(r *http.Request) *Client
- func (c *Client) Silent(s bool) *Client
- func (c *Client) Tags(tags []string) *Client
- func (c *Client) User(u string) *Client
- func (c *Client) Version(v string) *Client
- 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) 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) 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) Tags ¶
Tags is a chainable option-setting method to add tags to the context. You can use tags to filter errors in Raygun.
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.