aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/Xe/ln/stack.go
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2017-03-29 00:26:50 -0700
committerChristine Dodrill <me@christine.website>2017-03-29 00:26:50 -0700
commitb89387f6bbb010907dfa85ee0c0bab0cf8b34dfb (patch)
tree91deef87b78892c30839a99088362b70bf78eee4 /vendor/github.com/Xe/ln/stack.go
parenta59e48d9485f6c80f397df3bbcbe9b09ac54a435 (diff)
downloadxesite-b89387f6bbb010907dfa85ee0c0bab0cf8b34dfb.tar.xz
xesite-b89387f6bbb010907dfa85ee0c0bab0cf8b34dfb.zip
support RSS feed generation
Diffstat (limited to 'vendor/github.com/Xe/ln/stack.go')
-rw-r--r--vendor/github.com/Xe/ln/stack.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/vendor/github.com/Xe/ln/stack.go b/vendor/github.com/Xe/ln/stack.go
new file mode 100644
index 0000000..1cf1e7a
--- /dev/null
+++ b/vendor/github.com/Xe/ln/stack.go
@@ -0,0 +1,44 @@
+package ln
+
+import (
+ "os"
+ "runtime"
+ "strings"
+)
+
+type frame struct {
+ filename string
+ function string
+ lineno int
+}
+
+// skips 2 frames, since Caller returns the current frame, and we need
+// the caller's caller.
+func callersFrame() frame {
+ var out frame
+ pc, file, line, ok := runtime.Caller(3)
+ if !ok {
+ return out
+ }
+ srcLoc := strings.LastIndex(file, "/src/")
+ if srcLoc >= 0 {
+ file = file[srcLoc+5:]
+ }
+ out.filename = file
+ out.function = functionName(pc)
+ out.lineno = line
+
+ return out
+}
+
+func functionName(pc uintptr) string {
+ fn := runtime.FuncForPC(pc)
+ if fn == nil {
+ return "???"
+ }
+ name := fn.Name()
+ beg := strings.LastIndex(name, string(os.PathSeparator))
+ return name[beg+1:]
+ // end := strings.LastIndex(name, string(os.PathSeparator))
+ // return name[end+1 : len(name)]
+}