https://github.com/golang-infrastructure/go-how-run
检测Golang程序是如何运行的,是从打包的二进制运行的,还是从源代码运行的,如果是源代码又是Test还是main啥的
https://github.com/golang-infrastructure/go-how-run
how-run run-env-detect utils
Last synced: 3 months ago
JSON representation
检测Golang程序是如何运行的,是从打包的二进制运行的,还是从源代码运行的,如果是源代码又是Test还是main啥的
- Host: GitHub
- URL: https://github.com/golang-infrastructure/go-how-run
- Owner: golang-infrastructure
- License: mit
- Created: 2022-12-26T11:35:09.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-01-07T06:08:58.000Z (over 2 years ago)
- Last Synced: 2025-01-18T16:11:07.798Z (5 months ago)
- Topics: how-run, run-env-detect, utils
- Language: Go
- Homepage:
- Size: 6.84 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# How Run
# 一、这是啥
用来判断当前程序是怎么跑起来的,比如是源代码运行的,还是编译后运行的,是运行的单元测试,还是main方法运行的,是否跑在IDE比如GoLand中# 二、安装
```bash
go get -u github.com/golang-infrastructure/go-how-run
```# 三、Example
```go
package mainimport (
"fmt"
how_run "github.com/golang-infrastructure/go-how-run"
)func main() {
// 识别当前是运行的发布的二进制包还是从源代码运行
runType, err := how_run.GetRunType()
if err != nil {
fmt.Println("GetRunType error: " + err.Error())
return
}
fmt.Println(runType) // Output: SourceCode// 如果是从源代码运行,入口是啥,是main方法还是单元测试啥的
sourceCodeRunType, err := how_run.GetSourceCodeRunType()
if err != nil {
fmt.Println("GetSourceCodeRunType error: " + err.Error())
return
}
fmt.Println(sourceCodeRunType) // Output: main.go// 识别当前是否运行在IDE中
ide, err := how_run.GetRunIDE()
if err != nil {
fmt.Println("GetRunIDE error: " + err.Error())
return
}
fmt.Println(ide) // Output: GoLand}
```