Skip to content

tehsphinx/cstack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cstack

CStack implements a light-weight wrapper around the call stack returned by runtime.Callers. The wrapper add convenience functions to get information on the stack.

Usage

package main

import (
	"fmt"

	"github.com/tehsphinx/cstack"
)

func main() {
	// get stack skipping 0 layers
	stack := cstack.CallStack(0)
	
	// Use Format to transform each frame to a string 
	stackTrace := stack.Format(func(frame cstack.Frame) string {
		fName := frame.FuncName()
		file, line := frame.FileLine()
		return fmt.Sprintf("  %s\n    %s:%d\n", fName, file, line)
	})
	
	fmt.Print(stackTrace)
}

About

Go call stack

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages