diff --git a/README.md b/README.md index d97105a..583decf 100644 --- a/README.md +++ b/README.md @@ -225,7 +225,7 @@ unwanted or sensitive params or ignoring the whole notice completely. ```go // Filter out sensitive information such as credit cards. airbrake.AddFilter(func(n *gobrake.Notice) *gobrake.Notice { - if _, ok := n.Context["creditCard"] { + if _, ok := n.Context["creditCard"]; ok { n.Context["creditCard"] = "Filtered" } return n diff --git a/notice.go b/notice.go index bde108a..31b44ba 100644 --- a/notice.go +++ b/notice.go @@ -2,9 +2,9 @@ package gobrake import ( "fmt" + "go/build" "net/http" "os" - "path/filepath" "runtime" "strings" "sync" @@ -45,23 +45,10 @@ func getDefaultContext() map[string]interface{} { } func gopath() string { - path := os.Getenv("GOPATH") - if path != "" { + if path, ok := os.LookupEnv("GOPATH"); ok { return path } - - path, ok := os.LookupEnv("HOME") - if ok { - return filepath.Join(path, "go") - } - - return "" -} - -type Error struct { - Type string `json:"type"` - Message string `json:"message"` - Backtrace []StackFrame `json:"backtrace"` + return build.Default.GOPATH } type StackFrame struct { @@ -71,6 +58,12 @@ type StackFrame struct { Code map[int]string `json:"code,omitempty"` } +type Error struct { + Type string `json:"type"` + Message string `json:"message"` + Backtrace []StackFrame `json:"backtrace"` +} + type Notice struct { Id string `json:"-"` // id returned by SendNotice Error error `json:"-"` // error returned by SendNotice diff --git a/notifier_test.go b/notifier_test.go index a7f66d6..db67f95 100644 --- a/notifier_test.go +++ b/notifier_test.go @@ -6,6 +6,7 @@ import ( "crypto/rand" "encoding/json" "errors" + "go/build" "io/ioutil" "log" "net/http" @@ -343,6 +344,9 @@ var _ = Describe("Notifier", func() { hostname, _ := os.Hostname() gopath := os.Getenv("GOPATH") + if gopath == "" { + gopath = build.Default.GOPATH + } wd, _ := os.Getwd() Expect(sentNotice.Context["language"]).To(Equal(runtime.Version()))