beego / bee

Bee is a tool for helping develop with beego app framework.
Apache License 2.0
1.45k stars 922 forks source link

bee run error (get the go version 获取版本号出错) #767

Closed Joe3160 closed 3 years ago

Joe3160 commented 3 years ago

bee run error 获取版本号出错:

>bee run
go version go1.16.2 windows/amd64
go version go1.16.2 windows/amd64
panic: runtime error: index out of range [2] with length 1

goroutine 1 [running]:
github.com/beego/bee/v2/cmd/commands/version.GetGoVersion(0xc000091b40, 0xc0000d9170)
       **** /pkg/mod/github.com/beego/bee/v2@v2.0.2/cmd/commands/version/version.go:177 +0x1a6

reason:get not get go version 原因: 获取不了版本号

文件地址: file path github.com\beego\bee\v2@v2.0.2\cmd\commands\version\version.go line:168

func GetGoVersion() string {
    var (
        cmdOut []byte
        err    error
    )

    if cmdOut, err = exec.Command("go", "version").Output(); err != nil {
        beeLogger.Log.Fatalf("There was an error running 'go version' command: %s", err)
    }
    return strings.Split(string(cmdOut), " ")[2]
}

I can not ask how the porblom take place,but I suggest replace by the code belows: 建议用下面代码替换

func GetGoVersion() string {
      return runtime.Version()
}
flycash commented 3 years ago

非常感谢!以后也欢迎直接给我们PR~~