goroutine.go 228 Bytes Edit Raw Blame History 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 package zmisc import ( "fmt" "runtime" ) // GetGoroutineID 获取携程ID func GetGoroutineID() int { var buf [64]byte runtime.Stack(buf[:], false) var id int fmt.Sscanf(string(buf[:]), "goroutine %d", &id) return id }