3 回答
TA贡献1869条经验 获得超4个赞
您可以使用go version [-m] [file ...]
Go 版本报告用于构建每个指定可执行文件的 Go 版本。
输出示例:
$ go version -m dlv
dlv: go1.14.2
path github.com/go-delve/delve/cmd/dlv
mod github.com/go-delve/delve v1.4.0 h1:O+1dw1XBZXqhC6fIPQwGxLlbd2wDRau7NxNhVpw02ag=
dep github.com/cosiner/argv v0.0.0-20170225145430-13bacc38a0a5 h1:rIXlvz2IWiupMFlC45cZCXZFvKX/ExBcSLrDy2G0Lp8=
dep github.com/mattn/go-isatty v0.0.3 h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI=
dep github.com/peterh/liner v0.0.0-20170317030525-88609521dc4b h1:8uaXtUkxiy+T/zdLWuxa/PG4so0TPZDZfafFNNSaptE=
dep github.com/sirupsen/logrus v0.0.0-20180523074243-ea8897e79973 h1:3AJZYTzw3gm3TNTt30x0CCKD7GOn2sdd50Hn35fQkGY=
dep github.com/spf13/cobra v0.0.0-20170417170307-b6cb39589372 h1:eRfW1vRS4th8IX2iQeyqQ8cOUNOySvAYJ0IUvTXGoYA=
dep github.com/spf13/pflag v0.0.0-20170417173400-9e4c21054fa1 h1:7bozMfSdo41n2NOc0GsVTTVUiA+Ncaj6pXNpm4UHKys=
dep go.starlark.net v0.0.0-20190702223751-32f345186213 h1:lkYv5AKwvvduv5XWP6szk/bvvgO6aDeUujhZQXIFTes=
dep golang.org/x/arch v0.0.0-20190927153633-4e8777c89be4 h1:QlVATYS7JBoZMVaf+cNjb90WD/beKVHnIxFKT4QaHVI=
dep golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
dep golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb h1:fgwFCsaw9buMuxNd6+DQfAuSFqbNiQZpcgJQAgJsK6k=
dep gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
TA贡献1876条经验 获得超6个赞
是的!运行时/调试ReadBuildInfo
包中的函数可以为您提供此信息。
根据文档这个功能
返回嵌入在运行的二进制文件中的构建信息。该信息仅在使用模块支持构建的二进制文件中可用。
因此,例如,如果您的项目有这些文件:
go.mod
module buildinfo
go 1.12
require github.com/gorilla/mux v1.7.3
主程序
package main
import (
"fmt"
"runtime/debug"
_ "github.com/gorilla/mux"
)
func main() {
buildInfo, ok := debug.ReadBuildInfo()
if !ok {
panic("Can't read BuildInfo")
}
fmt.Println("Dependencies:")
for _, dep := range buildInfo.Deps {
fmt.Printf(" %s %s\n", dep.Path, dep.Version)
}
}
运行时会输出:
Dependencies:
github.com/gorilla/mux v1.7.3
TA贡献1877条经验 获得超1个赞
考虑到 github 生态系统,检查二进制文件中包含的资源是最简单的;
只需检查二进制文件中的模块即可;
$ strings ~/bin/txeh | grep github
/usr/bin/env go run ~/src/github.com/txn2/txeh/util/txeh.go "$@"
$ strings ~/bin/tt | grep github
github.com/araddon/dateparse.init.ializers
github.com/araddon/dateparse.init
/home/jaroslav/src/github.com/tox2ik/ttrack/src/tt/main.go
/home/jaroslav/src/github.com/araddon/dateparse/parseany.go
github.com/araddon/dateparse.ErrAmbiguousMMDD
github.com/araddon/dateparse.initdone.
github.com/araddon/dateparse.init.ializers
github.com/araddon/dateparse.init
或者如果您不知道来源:
strings ~/bin/tt | grep -e '\.go\>' -C2 | sort -ur
/usr/lib/go/src/os/exec_posix.go
/usr/lib/go/src/syscall/asm_linux_amd64.s
/usr/lib/go/src/internal/bytealg/count_native.go
/usr/lib/go/src/runtime/sigqueue.go
/usr/lib/go/src/os/wait_waitid.go
/usr/lib/go/src/internal/cpu/cpu.go
/usr/lib/go/src/runtime/mgclarge.go
/usr/lib/go/src/internal/bytealg/index_amd64.go
/usr/lib/go/src/strings/builder.go
/usr/lib/go/src/runtime/signal_unix.go
/usr/lib/go/src/runtime/utf8.go
/usr/lib/go/src/runtime/signal_linux_amd64.go
/usr/lib/go/src/os/stat_linux.go
/usr/lib/go/src/runtime/mbarrier.go
/usr/lib/go/src/runtime/netpoll.go
/usr/lib/go/src/runtime/mcache.go
/usr/lib/go/src/runtime/mcentral.go
.elfdata
/usr/lib/go/src/syscall/exec_unix.go
/usr/lib/go/src/runtime/cpuflags_amd64.go
(...)
- 3 回答
- 0 关注
- 126 浏览
添加回答
举报