diff options
author | Wim <wim@42.be> | 2017-03-25 20:45:10 +0100 |
---|---|---|
committer | Wim <wim@42.be> | 2017-03-25 20:45:10 +0100 |
commit | 07fd825349e8b7e86f8afb3843cb8e2c2afc7c74 (patch) | |
tree | ea4b33872a5b925fa0ecd2b421f8f073ba22b2cc /vendor/gopkg.in/airbrake/gobrake.v2/notice.go | |
parent | be15cc8a36ed3c207251f9b92815781f2fa8618d (diff) | |
download | matterbridge-msglm-07fd825349e8b7e86f8afb3843cb8e2c2afc7c74.tar.gz matterbridge-msglm-07fd825349e8b7e86f8afb3843cb8e2c2afc7c74.tar.bz2 matterbridge-msglm-07fd825349e8b7e86f8afb3843cb8e2c2afc7c74.zip |
Update vendor
Diffstat (limited to 'vendor/gopkg.in/airbrake/gobrake.v2/notice.go')
-rw-r--r-- | vendor/gopkg.in/airbrake/gobrake.v2/notice.go | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/vendor/gopkg.in/airbrake/gobrake.v2/notice.go b/vendor/gopkg.in/airbrake/gobrake.v2/notice.go new file mode 100644 index 00000000..06bc771a --- /dev/null +++ b/vendor/gopkg.in/airbrake/gobrake.v2/notice.go @@ -0,0 +1,105 @@ +package gobrake + +import ( + "fmt" + "net/http" + "os" + "path/filepath" + "runtime" +) + +var defaultContext map[string]interface{} + +func getDefaultContext() map[string]interface{} { + if defaultContext != nil { + return defaultContext + } + + defaultContext = map[string]interface{}{ + "notifier": map[string]interface{}{ + "name": "gobrake", + "version": "2.0.4", + "url": "https://github.com/airbrake/gobrake", + }, + + "language": runtime.Version(), + "os": runtime.GOOS, + "architecture": runtime.GOARCH, + } + if s, err := os.Hostname(); err == nil { + defaultContext["hostname"] = s + } + if s := os.Getenv("GOPATH"); s != "" { + list := filepath.SplitList(s) + // TODO: multiple root dirs? + defaultContext["rootDirectory"] = list[0] + } + return defaultContext +} + +type Error struct { + Type string `json:"type"` + Message string `json:"message"` + Backtrace []StackFrame `json:"backtrace"` +} + +type Notice struct { + Errors []Error `json:"errors"` + Context map[string]interface{} `json:"context"` + Env map[string]interface{} `json:"environment"` + Session map[string]interface{} `json:"session"` + Params map[string]interface{} `json:"params"` +} + +func (n *Notice) String() string { + if len(n.Errors) == 0 { + return "Notice<no errors>" + } + e := n.Errors[0] + return fmt.Sprintf("Notice<%s: %s>", e.Type, e.Message) +} + +func NewNotice(e interface{}, req *http.Request, depth int) *Notice { + notice := &Notice{ + Errors: []Error{{ + Type: fmt.Sprintf("%T", e), + Message: fmt.Sprint(e), + Backtrace: stack(depth), + }}, + Context: map[string]interface{}{}, + Env: map[string]interface{}{}, + Session: map[string]interface{}{}, + Params: map[string]interface{}{}, + } + + for k, v := range getDefaultContext() { + notice.Context[k] = v + } + + if req != nil { + notice.Context["url"] = req.URL.String() + if ua := req.Header.Get("User-Agent"); ua != "" { + notice.Context["userAgent"] = ua + } + + for k, v := range req.Header { + if len(v) == 1 { + notice.Env[k] = v[0] + } else { + notice.Env[k] = v + } + } + + if err := req.ParseForm(); err == nil { + for k, v := range req.Form { + if len(v) == 1 { + notice.Params[k] = v[0] + } else { + notice.Params[k] = v + } + } + } + } + + return notice +} |