mirror of
https://github.com/chai2010/advanced-go-programming-book.git
synced 2025-05-24 12:32:21 +00:00
fix code snippet
This commit is contained in:
parent
158167d639
commit
e41adb305d
@ -62,11 +62,11 @@ main.main()
|
|||||||
func GetGoid() int64 {
|
func GetGoid() int64 {
|
||||||
var (
|
var (
|
||||||
buf [64]byte
|
buf [64]byte
|
||||||
n = runtime.Stack(buf[:], false)
|
n = runtime.Stack(buf[:], false)
|
||||||
stk = strings.TrimPrefix(string(buf[:n])
|
stk = strings.TrimPrefix(string(buf[:n]), "goroutine ")
|
||||||
)
|
)
|
||||||
|
|
||||||
idField := strings.Fields(stk, "goroutine "))[0]
|
idField := strings.Fields(stk)[0]
|
||||||
id, err := strconv.Atoi(idField)
|
id, err := strconv.Atoi(idField)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Errorf("can not get goroutine id: %v", err))
|
panic(fmt.Errorf("can not get goroutine id: %v", err))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user