Skip to content

Commit

Permalink
Updated the fetching method of GOPATH. Code restructuring
Browse files Browse the repository at this point in the history
Updated the fetching method for GOPATH
Updated the test case to correctly test the GOPATH
  • Loading branch information
chimanjain committed Nov 17, 2021
1 parent 06a2a6d commit 9db5712
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
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 9db5712

Please sign in to comment.