Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Google AppEngine #13

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ the error will be sent to Raygun using your API-key.

The client returned by ``New`` has several chainable option-setting methods

Method | Description
--------------------------|------------------------------------------------------------
`Silent(bool)` | If set to true, this prevents the handler from sending the error to Raygun, printing it instead.
`Request(*http.Request)` | Adds the responsible http.Request to the error.
`Version(string)` | If your program has a version, you can add it here.
`Tags([]string)` | Adds the given tags to the error. These can be used for filtering later.
`CustomData(interface{})` | Add arbitrary custom data to you error. Will only reach Raygun if it works with `json.Marshal()`.
`User(string)` | Add the name of the affected user to the error.
Method | Description
---------------------------------------|----------------------------------------------
`Silent(bool)` | If set to true, this prevents the handler from sending the error to Raygun, printing it instead.
`Request(*http.Request)` | Adds the responsible http.Request to the error.
`Version(string)` | If your program has a version, you can add it here.
`Tags([]string)` | Adds the given tags to the error. These can be used for filtering later.
`CustomData(interface{})` | Add arbitrary custom data to you error. Will only reach Raygun if it works with `json.Marshal()`.
`User(string)` | Add the name of the affected user to the error.
`AppEngineHTTPClient(*http.Client)` | On Google AppEngine pass the urlfetch.Client

## Bugs and feature requests

Expand Down
27 changes: 20 additions & 7 deletions raygun4go.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ import (
// Client is the struct holding your Raygun configuration and context
// information that is needed if an error occurs.
type Client struct {
appName string // the name of the app
apiKey string // the api key for your raygun app
context contextInformation // optional context information
silent bool // if true, the error is printed instead of sent to Raygun
logToStdOut bool
appName string // the name of the app
apiKey string // the api key for your raygun app
context contextInformation // optional context information
silent bool // if true, the error is printed instead of sent to Raygun
logToStdOut bool
appEngineHTTPClient *http.Client // when running on GAE use the urlfetch http client
}

// contextInformation holds optional information on the context the error
Expand Down Expand Up @@ -86,7 +87,7 @@ func New(appName, apiKey string) (c *Client, err error) {
if appName == "" || apiKey == "" {
return nil, errors.New("appName and apiKey are required")
}
c = &Client{appName, apiKey, context, false, false}
c = &Client{appName, apiKey, context, false, false, nil}
return c, nil
}

Expand Down Expand Up @@ -139,6 +140,12 @@ func (c *Client) User(u string) *Client {
return c
}

// AppEngineHTTPClient enables overiding the http.client with Google App Engine http.client using urlfetch
func (c *Client) AppEngineHTTPClient(client *http.Client) *Client {
c.appEngineHTTPClient = client
return c
}

// HandleError sets up the error handling code. It needs to be called with
//
// defer c.HandleError()
Expand Down Expand Up @@ -203,7 +210,13 @@ func (c *Client) submit(post postData) error {
return errors.New(errMsg)
}
r.Header.Add("X-ApiKey", c.apiKey)
httpClient := http.Client{}

var httpClient *http.Client
if c.appEngineHTTPClient == nil {
httpClient = &http.Client{}
} else {
httpClient = c.appEngineHTTPClient
}
resp, err := httpClient.Do(r)

defer resp.Body.Close()
Expand Down