https://github.com/petermattis/goid
func GoID() int {
var buf [64]byte
n := runtime.Stack(buf[:], false)
// 得到id字符串
idField := strings.Fields(strings.TrimPrefix(string(buf[:n]), "goroutine "))[0]
id, err := strconv.Atoi(idField)
if err != nil {
panic(fmt.Sprintf("cannot get goroutine id: %v", err))
}
return id
}
标签:retrieve,err,goroutine,id,go,buf,ID From: https://www.cnblogs.com/rsapaper/p/17218181.html