1
0
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:
san 2019-01-15 23:16:05 +08:00
parent 158167d639
commit e41adb305d

View File

@ -63,10 +63,10 @@ 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))