funcKit

package
v1.3.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFuncInfoToString

func AddFuncInfoToString(str string, extraSkips ...int) string

AddFuncInfoToString 在传参format前面加上: "$包名.$方法名: "

@param extraSkips 额外跳过的步骤,第1个值(有的话)必须: >= 0

func GetCallerDetail

func GetCallerDetail() (string, string, int, bool)

GetCallerDetail 获取 调用此函数的函数 的详细信息(函数名、文件路径、行数).

PS: 由于此方法多了一层调用,所以需要+1,最终skip为2.

@return e.g. main.c /Users/richelieu/GolandProjects/go-scales/test/test1.go 32 true

func GetCallerDetailWithSkip

func GetCallerDetailWithSkip(skip int) (funcName string, filePath string, line int, ok bool)

GetCallerDetailWithSkip

参考:

Golang实现获取当前函数名称和文件行号等操作 https://www.51sjk.com/b123b248673/
Go学习——runtime.Caller()函数 https://blog.csdn.net/weixin_52000204/article/details/124504877

PS: 有可能获取失败,但目前不清楚什么情况下会失败(交叉编译时加上 -ldflags="-w -s" 并不会导致获取失败).

@param skip 理论上此值应该>=1,1: 向上1层(即谁调用此方法的);2: 向上2层... @return e.g. ("main.main", "/Users/richelieu/GolandProjects/go-scales/test/test1.go", 10)

func GetCallerName

func GetCallerName() string

GetCallerName 获取 调用此函数的函数 的名称(上1层).

func GetCallerNameWithSkip

func GetCallerNameWithSkip(skip int) string

GetCallerNameWithSkip

@param skip 1: 向上1层

func GetFuncInfo

func GetFuncInfo(extraSkips ...int) string

GetFuncInfo

@param extraSkips 额外跳过的步骤,第1个值(有的话)必须: >= 0 @return extraSkip == 0的情况下,返回: 调用此函数的函数的信息("$包名.$方法名: ")

e.g. "main.main: " "main.Print: " "main.test: "

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL