goLang开发环境配置:go mod使用
go mod是1.11以后版本新增的,如果是1.9.2及以下的版本是没有gomod的。
首先是初始化模块
1 2 3 4 | go mod init<项目模块名称> #初始化模块,会在项目根目录下生成 go.mod文件。 go mod tidy #根据go.mod文件来处理依赖关系。 |
如果是从github上拉下来的项目,执行这个命令之后就会开始下载一些需要的mod,比如下面的demo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | go : finding github.com/tidwall/gjson v1.2.1 go : finding github.com/gomodule/redigo/redis latest go : finding github.com/ go -sql-driver/mysql v1.4.1go: finding github.com/astaxie/beego/cache/redis latest go : finding github.com/astaxie/beego/orm latest go : finding github.com/astaxie/beego/cache latest go : finding github.com/astaxie/beego v1.11.1 go : finding github.com/astaxie/beego/logs latest go : finding github.com/astaxie/beego/context/param latest go : downloading github.com/tidwall/gjson v1.2.1 go : extracting github.com/tidwall/gjson v1.2.1 go : finding github.com/yinheli/mahonia latest go : finding github.com/gomodule/redigo v2.0.0+incompatible go : downloading github.com/gomodule/redigo v2.0.0+incompatible go : extracting github.com/gomodule/redigo v2.0.0+incompatible go : finding github.com/gomodule/redigo/redisx latest go : finding github.com/tidwall/match v1.0.1 go : downloading github.com/tidwall/match v1.0.1 go : extracting github.com/tidwall/match v1.0.1 go : downloading github.com/ go -sql-driver/mysql v1.4.1 go : extracting github.com/ go -sql-driver/mysql v1.4.1 go : finding github.com/pkg/errors v0.8.1 go : downloading github.com/pkg/errors v0.8.1 go : extracting github.com/pkg/errors v0.8.1 go : downloading github.com/astaxie/beego v1.11.1 go : downloading github.com/yinheli/mahonia v0.0.0-20131226213531-0eef680515cc go : extracting github.com/yinheli/mahonia v0.0.0-20131226213531-0eef680515cc go : finding github.com/astaxie/beego/context latest go : extracting github.com/astaxie/beego v1.11.1 go : finding github.com/pkg/errors v0.8.0 go : finding github.com/syndtr/goleveldb v0.0.0-20181127023241-353a9fca669c go : finding github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58 go : finding github.com/beego/x2j v0.0.0-20131220205130-a0352aadc542 go : finding github.com/siddontang/rdb v0.0.0-20150307021120-fc89ed2e418d go : finding github.com/bradfitz/gomemcache v0.0.0-20180710155616-bc664df96737 go : finding github.com/mattn/ go -sqlite3 v1.10.0 go : finding github.com/pelletier/ go -toml v1.2.0 go : finding github.com/elazarl/ go -bindata-assetfs v1.0.0 go : finding gopkg.in/yaml.v2 v2.2.1 go : finding github.com/Knetic/govaluate v3.0.0+incompatible go : finding github.com/ go -redis/redis v6.14.2+incompatible go : finding github.com/cupcake/rdb v0.0.0-20161107195141-43ba34106c76 go : finding github.com/gogo/protobuf v1.1.1 go : finding github.com/beego/goyaml2 v0.0.0-20130207012346-5545475820dd go : finding github.com/casbin/casbin v1.7.0 go : finding github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db go : finding github.com/couchbase/goutils v0.0.0-20180530154633-e865a1461c8a go : finding github.com/edsrzf/mmap- go v0.0.0-20170320065105-0bce6a688712 go : finding github.com/lib/pq v1.0.0 go : finding github.com/ssdb/gossdb v0.0.0-20180723034631-88f6b59b84ec go : finding github.com/couchbase/gomemcached v0.0.0-20181122193126-5125a94a666c go : finding github.com/couchbase/ go -couchbase v0.0.0-20181122212707-3e9b6e1258bb go : finding github.com/siddontang/ go v0.0.0-20180604090527-bdc77568d726 go : finding gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 go : finding github.com/wendal/errors v0.0.0-20130201093226-f66c77a7882b go : golang.org/x/net@v0.0.0-20181114220301-adae6a3d119a: unrecognized import path "golang.org/x/net" (https fetch: Get https: //golang.org/x/net?go-get=1: dial tcp 216.239.37.1:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.) go : finding github.com/belogik/goes v0.0.0-20151229125003-e54d722c3aff go : finding github.com/siddontang/ledisdb v0.0.0-20181029004158-becf5f38d373 go : golang.org/x/crypto@v0.0.0-20181127143415-eb0de9b17e85: unrecognized import path "golang.org/x/crypto" (https fetch: Get https: //golang.org/x/crypto?go-get=1: dial tcp 216.239.37.1:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.) go : error loading module requirements |
报错了,好吧 golang.org 这个网站打不开,可以通过替换github地址来下载mod
1 | go mod edit -replace=golang.org/x/crypto@v0.0.0=github.com/golang/crypto@latest |
然后再执行一次 tidy
1 | go mod tidy -v |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了