github.com/sujit-baniya/log@v1.0.73/goid_safe.go (about) 1 //go:build !amd64 && !arm64 && !arm && !386 && !mipsle 2 // +build !amd64,!arm64,!arm,!386,!mipsle 3 4 package log 5 6 import ( 7 "runtime" 8 ) 9 10 func goid() (n int) { 11 const offset = len("goroutine ") 12 var data [32]byte 13 b := data[:runtime.Stack(data[:], false)] 14 if len(b) <= offset { 15 return 16 } 17 for i := offset; i < len(b); i++ { 18 j := int(b[i] - '0') 19 if j < 0 || j > 9 { 20 break 21 } 22 n = n*10 + j 23 } 24 return n 25 } 26 27 // Goid returns the current goroutine id. 28 // It exactly matches goroutine id of the stack trace. 29 func Goid() int64 { 30 return int64(goid()) 31 }