代码拉取完成,页面将自动刷新
package runtimeutils
import (
"bytes"
"fmt"
"reflect"
"runtime"
"strconv"
"strings"
)
var goroutineSpace = []byte("goroutine ")
// GoroutineID returns current GO Routine ID (parsed from runtime.Stack)
func GoroutineID() uint64 {
b := make([]byte, 64)
b = b[:runtime.Stack(b, false)]
// Parse the 4707 out of "goroutine 4707 ["
b = bytes.TrimPrefix(b, goroutineSpace)
i := bytes.IndexByte(b, ' ')
if i < 0 {
panic(fmt.Sprintf("No space found in %q", b))
}
b = b[:i]
n, err := strconv.ParseUint(string(b), 10, 64)
if err != nil {
panic(fmt.Sprintf("Failed to parse goroutine ID out of %q: %v", b, err))
}
return n
}
// GetFunction returns metadata about function based on pointer to a function
//
// Example usage:
//
// func foo() {}
// GetFunction(foo)
func GetFunction(function interface{}) *runtime.Func {
return runtime.FuncForPC(reflect.ValueOf(function).Pointer())
}
// GetFunctionName returns name of the function
//
// Example usage:
//
// func foo() {}
// GetFunctionName(foo) // returns string containing "foo" substring
func GetFunctionName(function interface{}) string {
fullName := GetFunction(function).Name()
name := strings.TrimSuffix(fullName, "-fm")
dot := strings.LastIndex(name, ".")
if dot > 0 && dot+1 < len(name) {
return name[dot+1:]
}
return fullName
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。