func GetGoroutineID() int { var buf = make([]byte, 128) b := runtime.Stack(buf, false) idField := strings.Fields(strings.TrimPrefix(string(buf[:b]), "goroutine "))[0] id, err := strconv.Atoi(idField) if err != nil { panic(fmt.Sprintf("cannot get goroutine id: %v", err)) } return id }
标签:idField,err,Get,Goroutine,id,Go,buf,ID From: https://www.cnblogs.com/dissipate/p/17228118.html