婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁(yè) > 知識(shí)庫(kù) > golang 如何自動(dòng)下載所有依賴(lài)包

golang 如何自動(dòng)下載所有依賴(lài)包

熱門(mén)標(biāo)簽:excel地圖標(biāo)注分布數(shù)據(jù) 百度地圖標(biāo)注后傳給手機(jī) 阿克蘇地圖標(biāo)注 壽光微信地圖標(biāo)注 電話(huà)機(jī)器人軟件免費(fèi) 評(píng)價(jià)高的400電話(huà)辦理 外呼系統(tǒng)用什么卡 涿州代理外呼系統(tǒng) 外呼系統(tǒng)顯本地手機(jī)號(hào)

如何自動(dòng)下載所有依賴(lài)包?

大部分情況下大家下載 Go 項(xiàng)目都是使用go get命令,它除了會(huì)下載指定的項(xiàng)目代碼,還會(huì)去下載這個(gè)項(xiàng)目所依賴(lài)的所有項(xiàng)目。

但是有的時(shí)候我們的項(xiàng)目由于各種原因并不是通過(guò)go get下載的,是通過(guò)git clone下載的,這樣代碼下下來(lái)就沒(méi)有依賴(lài)包了,沒(méi)辦法編譯通過(guò)的。

這樣的話(huà)怎么辦呢?

go get -d -v ./...

-d標(biāo)志只下載代碼包,不執(zhí)行安裝命令;

-v打印詳細(xì)日志和調(diào)試日志。這里加上這個(gè)標(biāo)志會(huì)把每個(gè)下載的包都打印出來(lái);

./...這個(gè)表示路徑,代表當(dāng)前目錄下所有的文件。

補(bǔ)充:goland自動(dòng)下載所有依賴(lài)

項(xiàng)目中使用了go.mod時(shí)可以使用以下命令自動(dòng)下載全部依賴(lài)

方法一

go get -d -v ./...

方法二

go mod tidy

補(bǔ)充:go mod 無(wú)法自動(dòng)下載依賴(lài)包的問(wèn)題

go 11以后啟用了go mod功能,用于管理依賴(lài)包。

當(dāng)執(zhí)行g(shù)o mod init生成go.mod文件之后,golang在運(yùn)行、編譯項(xiàng)目的時(shí)候,都會(huì)檢查依賴(lài)并下載依賴(lài)包。

在啟動(dòng)了go mod之后,通過(guò)go mod下載的依賴(lài)包,不在放在GOPATH/src中,而是放到GOPATH/pkg/mod中。

比如我當(dāng)前的GOPATH=/root/go,我在/root/goProjects/下新建了一個(gè)項(xiàng)目gProject1,并在項(xiàng)目下編寫(xiě)了一些代碼,引用了一些第三方包:

echo $GO111MODULE

auto

mkdir /root/goProjects/gProject1

cd /root/goProjects/gProject1

vi main.go

cat main.go

package main
import (
 "log"

 "github.com/toolkits/smtp"
)

func main() {
 //s := smtp.New("smtp.exmail.qq.com:25", "notify@a.com", "password")
 s := smtp.NewSMTP("smtp.exmail.qq.com:25", "notify@a.com", "password",false,false,false)
 log.Println(s.SendMail("notify@a.com", "ulric@b.com;rain@c.com", "這是subject", "這是body,font color=red>red/font>"))
}

go mod init gProject1

go: creating new go.mod: module gProject1

-cat go.mod

module gProject1
go 1.12
yzc:gProj

go run main.go

如果此時(shí)報(bào)錯(cuò):

build command-line-arguments: cannot load github.com/toolkits/smtp: cannot find module providing package github.com/toolkits/smtp

原因是因?yàn)間it版本較低,go get 無(wú)法通過(guò)git下載github.com/toolkits/smtp到指定路徑。

你可以手動(dòng)執(zhí)行一下go get github.com/toolkits/smtp,發(fā)現(xiàn)會(huì)報(bào)一個(gè)類(lèi)似這樣的錯(cuò)誤:

# go get github.com/toolkits/smtp
go get github.com/toolkits/smtp: git ls-remote -q https://github.com/toolkits/smtp in /root/go/pkg/mod/cache/vcs/7028097e3b6cce3023c34b7ceae3657ef3f2bbb25dec9b4362813d1fadd80297: exit status 129:
usage: git ls-remote [--heads] [--tags] [-u exec> | --upload-pack exec>] repository> refs>...

就是git版本太低了,無(wú)法支撐go get運(yùn)行g(shù)it時(shí)的參數(shù)調(diào)用。

升級(jí)git

macos:

brew upgrade git

centos6/7

Remove old git

sudo yum remove git*

centos6:

sudo yum -y install  https://centos6.iuscommunity.org/ius-release.rpm

centos7:

sudo yum -y install  https://centos7.iuscommunity.org/ius-release.rpm

sudo yum -y install git2u-all

再次執(zhí)行g(shù)o run main.go:

go: finding github.com/toolkits/smtp latest
go: downloading github.com/toolkits/smtp v0.0.0-20190110072832-af41f29c3d89
go: extracting github.com/toolkits/smtp v0.0.0-20190110072832-af41f29c3d89
2019/07/27 16:15:52 535 Error: ��ʹ����Ȩ���¼�������뿴: http://service.mail.qq.com/cgi-bin/help?subtype=1id=28no=1001256

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教。

您可能感興趣的文章:
  • golang使用 gomodule 在公共測(cè)試環(huán)境管理go的依賴(lài)的實(shí)例詳解
  • 解決vscode中g(shù)olang插件依賴(lài)安裝失敗問(wèn)題
  • golang不到30行代碼實(shí)現(xiàn)依賴(lài)注入的方法

標(biāo)簽:蘭州 吐魯番 重慶 汕頭 雞西 梅河口 銅川 欽州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《golang 如何自動(dòng)下載所有依賴(lài)包》,本文關(guān)鍵詞  golang,如何,自動(dòng),下載,所有,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《golang 如何自動(dòng)下載所有依賴(lài)包》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于golang 如何自動(dòng)下載所有依賴(lài)包的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 阿坝| 罗田县| 五指山市| 石家庄市| 宜兰市| 绥中县| 那坡县| 成都市| 富阳市| 宿州市| 吉木萨尔县| 郯城县| 吴川市| 张家界市| 黑河市| 唐海县| 抚州市| 光山县| 扬中市| 泰州市| 临泽县| 康保县| 尚义县| 平和县| 金山区| 泰州市| 北京市| 灌南县| 栾城县| 怀安县| 伽师县| 沅江市| 富锦市| 阿图什市| 扶风县| 乐平市| 扶绥县| 通州区| 临夏市| 桃源县| 鹤峰县|