Skip to content

Commit

Permalink
Merge pull request #216 from airbrake/ChimanJain-master
Browse files Browse the repository at this point in the history
Updated the fetching method of GOPATH, updated the test case and fixed a typo in readme
  • Loading branch information
chimanjain authored Nov 17, 2021
2 parents 2484622 + 9db5712 commit 10bccf4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 9 additions & 16 deletions notice.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package gobrake

import (
"fmt"
"go/build"
"net/http"
"os"
"path/filepath"
"runtime"
"strings"
"sync"
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions notifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"crypto/rand"
"encoding/json"
"errors"
"go/build"
"io/ioutil"
"log"
"net/http"
Expand Down Expand Up @@ -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()))
Expand Down

0 comments on commit 10bccf4

Please sign in to comment.