Documentation
¶
Overview ¶
Because go language does not have industrial level of exception handing mechanism, using the information of calling state is the only way to expose secret in code.
Obtain CallerInfo ¶
CallerInfo is the main struct which holds essential information of detail on code.
You can obtain CallerInfo by various functions:
GetCallerInfo() - Obtains the caller(the previous calling point to current function) GetCallerInfoWithDepth() - Obtains the caller of caller by numeric depth
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CallerInfo ¶
type CallerInfo struct { Line int // contains filtered or unexported fields }
Information of the position in file and where line number is targeted
func GetCallerInfo ¶
func GetCallerInfo() *CallerInfo
Gets caller info from current function
Example ¶
f := func() *CallerInfo { return GetCallerInfo() } // This is line 18 of stack_test.go callerInfo := f() replaceRegExp, _ := regexp.Compile(`github\.com/.+$`) fmt.Printf("%s", replaceRegExp.FindStringSubmatch(callerInfo.String())[0])
Output: github.com/Cepave/open-falcon-backend/common/runtime/stack_test.go:20
func GetCallerInfoWithDepth ¶
func GetCallerInfoWithDepth(depth int) *CallerInfo
Gets caller info with depth.
N means the Nth caller of caller.
Example ¶
f2 := func() *CallerInfo { return GetCallerInfoWithDepth(1) } f1 := func() *CallerInfo { return f2() } callerInfo := f1() fmt.Printf("%s", callerInfo)
Output:
func (*CallerInfo) GetFile ¶
func (c *CallerInfo) GetFile() string
Gets the file by trimming of $GOPATH
The processing of file is delayed to improve performance
func (*CallerInfo) String ¶
func (c *CallerInfo) String() string
type CallerStack ¶
type CallerStack []*CallerInfo
func GetCallerInfoStack ¶
func GetCallerInfoStack(startDepth int, endDepth int) CallerStack
Gets stack of caller info
func (CallerStack) AsStringStack ¶
func (s CallerStack) AsStringStack() []string
func (CallerStack) ConcatStringStack ¶
func (s CallerStack) ConcatStringStack(sep string) string
Click to show internal directories.
Click to hide internal directories.