我在其中开发了go工作区,然后构建了一个二进制文件并将其复制到kuberenetes pod上并运行它。是否可能知道二进制文件中使用/安装了哪些go软件包?
答案 0 :(得分:4)
是的! runtime/debug软件包中的ReadBuildInfo
函数可以为您提供此信息。
根据文档,此功能
返回嵌入在正在运行的二进制文件中的构建信息。该信息仅在模块支持的二进制文件中可用。
例如,如果您的项目具有以下文件:
go.mod
module buildinfo
go 1.12
require github.com/gorilla/mux v1.7.3
main.go
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
答案 1 :(得分:2)
您可以使用go version [-m] [file ...]
Go version 报告用于构建每个命名的 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=
答案 2 :(得分:0)
鉴于github-ecosystem,检查二进制文件中包含的资源最简单;
只需检查二进制文件中的模块;
$ 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
(...)