1
0
mirror of https://github.com/chai2010/advanced-go-programming-book.git synced 2025-05-24 04:22:22 +00:00

Merge pull request #410 from kumakichi/fix_code_snippet

fix code snippet
This commit is contained in:
chai2010 2019-01-15 23:37:33 +08:00 committed by GitHub
commit 46bbb0e350
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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))