mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
This PR includes the following changes: - **Upgrade `.golangci.yml`**: Updated the configuration file to align with the latest golangci-lint version, ensuring compatibility and leveraging new features. - **Refactor GitHub Action workflow**: Modified `golangci-lint.yml` in the GitHub Actions workflow to reflect the updated configuration and improve CI performance. - **Codebase optimization**: Refactored code to address issues and warnings raised by the updated golangci-lint rules, including: - Improved function length and complexity. - Enhanced error handling and variable naming conventions. - Fixed minor issues such as unused imports and formatting inconsistencies. These changes aim to maintain code quality, ensure compatibility with the latest tools, and improve overall maintainability.
28 lines
853 B
Go
28 lines
853 B
Go
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
|
//
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
// If a copy of the MIT was not distributed with this file,
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
package gdebug
|
|
|
|
import (
|
|
"regexp"
|
|
"runtime"
|
|
"strconv"
|
|
)
|
|
|
|
// gridRegex is the regular expression object for parsing goroutine id from stack information.
|
|
var gridRegex = regexp.MustCompile(`^\w+\s+(\d+)\s+`)
|
|
|
|
// GoroutineID retrieves and returns the current goroutine id from stack information.
|
|
// Be very aware that, it is with low performance as it uses runtime.Stack function.
|
|
// It is commonly used for debugging purpose.
|
|
func GoroutineID() int {
|
|
buf := make([]byte, 26)
|
|
runtime.Stack(buf, false)
|
|
match := gridRegex.FindSubmatch(buf)
|
|
id, _ := strconv.Atoi(string(match[1]))
|
|
return id
|
|
}
|