summaryrefslogtreecommitdiffstats
path: root/vendor/gopkg.in/airbrake/gobrake.v2/util.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2017-03-25 20:45:10 +0100
committerWim <wim@42.be>2017-03-25 20:45:10 +0100
commit07fd825349e8b7e86f8afb3843cb8e2c2afc7c74 (patch)
treeea4b33872a5b925fa0ecd2b421f8f073ba22b2cc /vendor/gopkg.in/airbrake/gobrake.v2/util.go
parentbe15cc8a36ed3c207251f9b92815781f2fa8618d (diff)
downloadmatterbridge-msglm-07fd825349e8b7e86f8afb3843cb8e2c2afc7c74.tar.gz
matterbridge-msglm-07fd825349e8b7e86f8afb3843cb8e2c2afc7c74.tar.bz2
matterbridge-msglm-07fd825349e8b7e86f8afb3843cb8e2c2afc7c74.zip
Update vendor
Diffstat (limited to 'vendor/gopkg.in/airbrake/gobrake.v2/util.go')
-rw-r--r--vendor/gopkg.in/airbrake/gobrake.v2/util.go59
1 files changed, 59 insertions, 0 deletions
diff --git a/vendor/gopkg.in/airbrake/gobrake.v2/util.go b/vendor/gopkg.in/airbrake/gobrake.v2/util.go
new file mode 100644
index 00000000..c05c0331
--- /dev/null
+++ b/vendor/gopkg.in/airbrake/gobrake.v2/util.go
@@ -0,0 +1,59 @@
+package gobrake
+
+import (
+ "runtime"
+ "strings"
+)
+
+func stackFilter(packageName, funcName string, file string, line int) bool {
+ return packageName == "runtime" && funcName == "panic"
+}
+
+type StackFrame struct {
+ File string `json:"file"`
+ Line int `json:"line"`
+ Func string `json:"function"`
+}
+
+func stack(depth int) []StackFrame {
+ stack := []StackFrame{}
+ for i := depth; ; i++ {
+ pc, file, line, ok := runtime.Caller(i)
+ if !ok {
+ break
+ }
+ packageName, funcName := packageFuncName(pc)
+ if stackFilter(packageName, funcName, file, line) {
+ stack = stack[:0]
+ continue
+ }
+ stack = append(stack, StackFrame{
+ File: file,
+ Line: line,
+ Func: funcName,
+ })
+ }
+
+ return stack
+}
+
+func packageFuncName(pc uintptr) (string, string) {
+ f := runtime.FuncForPC(pc)
+ if f == nil {
+ return "", ""
+ }
+
+ packageName := ""
+ funcName := f.Name()
+
+ if ind := strings.LastIndex(funcName, "/"); ind > 0 {
+ packageName += funcName[:ind+1]
+ funcName = funcName[ind+1:]
+ }
+ if ind := strings.Index(funcName, "."); ind > 0 {
+ packageName += funcName[:ind]
+ funcName = funcName[ind+1:]
+ }
+
+ return packageName, funcName
+}