• golang 安装依赖


     go get -d -v ./...

    以下载grpc为例

    grpc官方提供的下载命令是:

    go get google.golang.org/grpc
    

    因为无法访问,所以我们需要在$GOPATH/src目录下面创建一个google.golang.org的目录。
    在github上找到对应的grpc的包,https://github.com/grpc/grpc-go
    其实google.golang.org对应的就是https://github.com/grpc/grpc-go
    然后我们进入到$GOPATH/src/google.golang.org这个目录。执行git命令

    git clone --depth=1 https://github.com/grpc/grpc-go.git grpc
    

    命令解析:
    其中--depth=1 这个参数的意思是只克隆最新的commit分支。不加也行。
    最后的grpc表示的是将克隆的文件存放到那个文件夹里面。
    执行完上面的命令,我们就成功的将grpc的包下载到本地了。

    go get google.golang.org/grpc
    

    golang当中go get其实执行了两个操作,一个是git clone 另外一个go install。所以我们还要进入到$GOPATH/src/google.golang.org/grpc当中执行以下go install 。这个命令会在$GOPATH/pkg/google.golang.org/grpc下面生成一个grpc.a的外部包文件。用于和其他程序访问和编译。并且在go install的过程当中我们可以检查哪些相关依赖的包没有安装,可以使用相同的办法进行安装。

    tips 1

     复制代码
    如何自动下载所有依赖包?
    大部分情况下大家下载 Go 项目都是使用go get命令,它除了会下载指定的项目代码,还会去下载这个项目所依赖的所有项目。
    
    但是有的时候我们的项目由于各种原因并不是通过go get下载的,是通过git clone下载的,这样代码下下来就没有依赖包了,没办法编译通过的。这样的话怎么办呢?
    
     go get -d -v ./...
     
    
    -d标志只下载代码包,不执行安装命令;
    -v打印详细日志和调试日志。这里加上这个标志会把每个下载的包都打印出来;
    ./...这个表示路径,代表当前目录下所有的文件。
    复制代码
     

    tips2 

    go: github.com/go-sql-driver/mysql@v1.5.0: Get "https://proxy.golang.org/github.com/go-sql-driver/mysql/@v/v1.5.0.mod": dial tcp 172.217.24.17:443: i/o timeout
    root@cloud:~/tron-go# export GOPROXY=https://mirrors.aliyun.com/goproxy/
    root@cloud:~/tro-go# make -j 48 
    go: downloading golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae
    go: downloading go.starlark.net v0.0.0-20200619143648-50ca820fafb9
    go: downloading google.golang.org/genproto v0.0.0-20200626011028-ee7919e894b5
    go: downloading golang.org/x/text v0.3.3
    开启GO111MODULE
    用环境变量 GO111MODULE 开启或关闭模块支持,它有三个可选值:off、on、auto,默认值是 auto。
    GO111MODULE=off 无模块支持,go 会从 GOPATH 和 vendor 文件夹寻找包。
    GO111MODULE=on 模块支持,go 会忽略 GOPATH 和 vendor 文件夹,只根据 go.mod 下载依赖。
    GO111MODULE=auto 在 GOPATH/src/mod 中,也会把 go install 的结果放在 $GOPATH/bin 中。
    go env -w GO111MODULE=on
     
     
    /opt/gopath/pkg/mod/gvisor.dev/gvisor@v0.0.0-20201228220549-5c21c7c3bd15/pkg/coverage/coverage.go:35:2: cannot find module providing package github.com/bazelbuild/rules_go/go/tools/coverdata: module github.com/bazelbuild/rules_go/go/tools/coverdata: reading https://mirrors.aliyun.com/goproxy/github.com/bazelbuild/rules_go/go/tools/coverdata/@v/list: 404 Not Found
    root@cloud:/gvisor# unset GOPROXY
    root@cloud:/gvisor# go get gvisor.dev/gvisor/runsc@go
    go get gvisor.dev/gvisor/runsc@go: gvisor.dev/gvisor/runsc@go: invalid version: Get "https://proxy.golang.org/gvisor.dev/gvisor/runsc/@v/go.info": dial tcp 216.58.200.241:443: i/o timeout
    root@cloud:/gvisor# go get https://github.com/bazelbuild/rules_go.git
    go get https:/github.com/bazelbuild/rules_go.git: malformed module path "https:/github.com/bazelbuild/rules_go.git": invalid char ':'
    root@cloud:/gvisor# go get github.com/bazelbuild/rules_go

    git clone 

    root@cloud:/gvisor# export GOPROXY=https://mirrors.aliyun.com/goproxy/
    root@cloud:/gvisor# go get gvisor.dev/gvisor/runsc@go
    go: found gvisor.dev/gvisor/runsc in gvisor.dev/gvisor v0.0.0-20201228220549-5c21c7c3bd15
    go: finding module for package github.com/bazelbuild/rules_go/go/tools/coverdata
    go: downloading github.com/bazelbuild/rules_go v0.25.1
    go: found github.com/bazelbuild/rules_go/go/tools/coverdata in github.com/bazelbuild/rules_go v0.25.1
    # gvisor.dev/gvisor/pkg/sentry/platform/ring0/pagetables
    /opt/gopath/pkg/mod/gvisor.dev/gvisor@v0.0.0-20201228220549-5c21c7c3bd15/pkg/sentry/platform/ring0/pagetables/walker_empty.go:121:14: pudEntry.SetSuper undefined (type *PTE has no field or method SetSuper)
    /opt/gopath/pkg/mod/gvisor.dev/gvisor@v0.0.0-20201228220549-5c21c7c3bd15/pkg/sentry/platform/ring0/pagetables/walker_empty.go:132:22: pudEntry.IsSuper undefined (type *PTE has no field or method IsSuper)
    /opt/gopath/pkg/mod/gvisor.dev/gvisor@v0.0.0-20201228220549-5c21c7c3bd15/pkg/sentry/platform/ring0/pagetables/walker_empty.go:138:24: pmdEntries[index].SetSuper undefined (type PTE has no field or method SetSuper)
    /opt/gopath/pkg/mod/gvisor.dev/gvisor@v0.0.0-20201228220549-5c21c7c3bd15/pkg/sentry/platform/ring0/pagetables/walker_empty.go:175:15: pmdEntry.SetSuper undefined (type *PTE has no field or method SetSuper)
    /opt/gopath/pkg/mod/gvisor.dev/gvisor@v0.0.0-20201228220549-5c21c7c3bd15/pkg/sentry/platform/ring0/pagetables/walker_empty.go:186:23: pmdEntry.IsSuper undefined (type *PTE has no field or method IsSuper)
    /opt/gopath/pkg/mod/gvisor.dev/gvisor@v0.0.0-20201228220549-5c21c7c3bd15/pkg/sentry/platform/ring0/pagetables/walker_lookup.go:121:14: pudEntry.SetSuper undefined (type *PTE has no field or method SetSuper)
    /opt/gopath/pkg/mod/gvisor.dev/gvisor@v0.0.0-20201228220549-5c21c7c3bd15/pkg/sentry/platform/ring0/pagetables/walker_lookup.go:132:22: pudEntry.IsSuper undefined (type *PTE has no field or method IsSuper)
    /opt/gopath/pkg/mod/gvisor.dev/gvisor@v0.0.0-20201228220549-5c21c7c3bd15/pkg/sentry/platform/ring0/pagetables/walker_lookup.go:138:24: pmdEntries[index].SetSuper undefined (type PTE has no field or method SetSuper)
    /opt/gopath/pkg/mod/gvisor.dev/gvisor@v0.0.0-20201228220549-5c21c7c3bd15/pkg/sentry/platform/ring0/pagetables/walker_lookup.go:175:15: pmdEntry.SetSuper undefined (type *PTE has no field or method SetSuper)
    /opt/gopath/pkg/mod/gvisor.dev/gvisor@v0.0.0-20201228220549-5c21c7c3bd15/pkg/sentry/platform/ring0/pagetables/walker_lookup.go:186:23: pmdEntry.IsSuper undefined (type *PTE has no field or method IsSuper)
    /opt/gopath/pkg/mod/gvisor.dev/gvisor@v0.0.0-20201228220549-5c21c7c3bd15/pkg/sentry/platform/ring0/pagetables/walker_lookup.go:186:23: too many errors
    note: module requires Go 1.15
    root@cloud:/gvisor# 
    note: module requires Go 1.15
  • 相关阅读:
    Java RandomAccessFile用法(转)
    CSS样式设计小技巧(水平居中,垂直居中)
    CSS总结(下篇)
    CSS总结(中篇)
    CSS总结(上篇)
    Html常用到的标签
    java 重定向和转发的区别(转)
    eclipse启动tomcat无法访问的解决方法(转)
    Busybox下mdev配置说明
    Linux 下网卡参数配置
  • 原文地址:https://www.cnblogs.com/dream397/p/13750907.html
Copyright © 2020-2023  润新知