package errors import ( "runtime" "strings" ) var ( IsStackCaptureEnabled = true StackCaptureSize = 1024 * 4 ) type ErrorStack = []string func CaptureStackIfEnabled() ErrorStack { if !IsStackCaptureEnabled { return nil } return CaptureStack() } func CaptureStack() ErrorStack { buffer := make([]byte, StackCaptureSize) stackSize := runtime.Stack(buffer, false) return strings.Split(string(buffer[:stackSize]), "\n") }