判断是否是已编译文件
import (
"os"
"path/filepath"
"strings"
)
//IsRelease 当前执行的是否是已编译文件
func IsRelease() bool {
arg1 := strings.ToLower(os.Args[0])
name := filepath.Base(arg1)
return strings.Index(name, "__") != 0 && strings.Index(arg1, "go-build") < 0
}
判断是否是单元测试
package main
import (
"flag"
"fmt"
)
func main() {
if os.Args[len(os.Args)-1] == "unit-test" {
//...
//...
//...
}
}