From 06a2a6d341cf34d9e62fdaf6e4930bf4610b3460 Mon Sep 17 00:00:00 2001 From: ChimanJain <36687396+ChimanJain@users.noreply.github.com> Date: Mon, 15 Nov 2021 18:25:56 +0530 Subject: [PATCH 1/2] Updated readme updated the usage of filter functionality --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 9db5712a0e724354f24b6d82c62aa93e03a5f367 Mon Sep 17 00:00:00 2001 From: ChimanJain <36687396+ChimanJain@users.noreply.github.com> Date: Mon, 15 Nov 2021 18:28:24 +0530 Subject: [PATCH 2/2] Updated the fetching method of GOPATH. Code restructuring Updated the fetching method for GOPATH Updated the test case to correctly test the GOPATH --- notice.go | 25 +++++++++---------------- notifier_test.go | 4 ++++ 2 files changed, 13 insertions(+), 16 deletions(-) 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()))