英文:
Can't access Go libraries
问题
我有一个工作中的Go项目,并向其中添加了一些库。
在这一步之前,一切都正常工作。然后我将我的代码推送到服务器上。然后我尝试重新克隆存储库,但是出现了以下错误。
找不到go文件错误
当我尝试运行 go get - (再次运行存储库)时,我得到以下错误信息:
go get -u github.com/jinzhu/gorm
package github.com/jinzhu/gorm: directory "/testapp/src/github.com/jinzhu/gorm" is not using a known version control system
这种方法有什么问题吗?
当我检查存储库时,我发现git库存储库指向另一个存储库的提交。
英文:
I had a working go project and I added some libraries to it.
All was working fine till this step. Then I pushed my code to server. Again I tried to take fresh clone the repository and I am getting following error.
go file not find error
When I try to do go get - (repo again) I get
go get -u github.com/jinzhu/gorm
package github.com/jinzhu/gorm: directory "/testapp/src/github.com/jinzhu/gorm" is not using a known version control system
What is wrong in this approach??
And When I am checking repository I can see git library repository point to some other repository commit.
答案1
得分: 2
我今天遇到了同样的问题,我通过在本地依赖项中初始化一个.git
仓库来解决它。所以在github.com/jinzhu/gorm
目录下运行以下命令:
git init
git add .
git commit -m "first commit"
英文:
I ran into the same issue just today and I fixed it by initializing a .git
repo inside the local dependency. So inside github.com/jinzhu/gorm
run:
git init
git add .
git commit -m "first commit"
答案2
得分: 1
我尝试了这种方法,它起作用了,因为这是我唯一剩下的解决办法:
- 克隆项目并进入项目目录;
- 创建一个名为
install.sh
的文件,该文件会设置GOPATH,删除库并重新下载。
#!/bin/sh
# 获取当前工作目录
CURRENT_DIR=`pwd`
echo "GOPATH指向${CURRENT_DIR}"
# 导出当前工作目录的GOPATH
export GOPATH=${CURRENT_DIR}
# 更改目录权限为可执行
chmod +x ${GOPATH}
# 删除github依赖,以便重新安装
# Github问题:https://github.com/golang/go/issues/18591
# 如果添加了其他包,请修改此脚本
rm -rf ${GOPATH}/src/github.com
# dependencies.txt 包含 go get -u (repo path) 的列表
# 在新行中添加任何新的依赖项,然后再次执行 install.sh
sh dependencies.txt
文件 dependencies.txt:
go get -u -v github.com/gorilla/mux
go get -u -v github.com/gorilla/handlers
go get -u -v github.com/dgrijalva/jwt-go
最后运行脚本启动应用程序 run.sh
:
#!/bin/sh
# 获取当前工作目录
CURRENT_DIR=`pwd`
echo "GOPATH指向${CURRENT_DIR}"
# 导出当前工作目录的GOPATH
export GOPATH=${CURRENT_DIR}
echo "在 http://localhost:9096 启动服务器"
# 运行服务器实例
go run ${GOPATH}/path/to/main/file/Main.go
这些都适用于以下目录结构:
项目根目录
-----bin
-----pkg
-----src
-----src/github.com/
-----src/github.com/gorilla/mux
-----src/github.com/gorilla/handlers
-----src/你的项目代码
英文:
I tried this approach and it worked as this was the only work around i was left with:
Fresh clone the project and navigate inside it;
Created install.sh
which would set GOPATH, remove libraries and then re download it.
#!/bin/sh
#GET current working directory
CURRENT_DIR=`pwd`
echo "GOPATH is pointing to ${CURRENT_DIR}"
#Export GOPATH for current working directory
export GOPATH=${CURRENT_DIR}
#Change Directory permission to executable
chmod +x ${GOPATH}
#Delete github dependency so that they can be reinstalled
#Github Issue: https://github.com/golang/go/issues/18591
#Modify this script if you are adding any other packages
rm -rf ${GOPATH}/src/github.com
#dependencies.txt contain list of go get -u (repo path)
#dependencies in new line add any new dependency and execute install.sh again
sh dependencies.txt
File dependencies.txt
go get -u -v github.com/gorilla/mux
go get -u -v github.com/gorilla/handlers
go get -u -v github.com/dgrijalva/jwt-go
Then finally run script which would boot my application
run.sh
#!/bin/sh
#GET current working directory
CURRENT_DIR=`pwd`
echo "GOPATH is pointing to ${CURRENT_DIR}"
#Export GOPATH for current working directory
export GOPATH=${CURRENT_DIR}
echo "Starting server at http://localhost:9096"
#Run server instance
go run ${GOPATH}/path/to/main/file/Main.go
All this hold true with following directory structure:
Project Root
-----bin
-----pkg
-----src
-----src/github.com/
-----src/github.com/gorilla/mux
-----src/github.com/gorilla/handlers
-----src/yours/project/code
答案3
得分: 0
有几件事情你可以做。
- 检查你的GO版本,如果不是最新版本,就更新到版本
1.7
。 - 在更新GO之后,删除仓库并重新克隆。
- 你可以尝试按照以下步骤为Golang目录创建新的导出:
export GOPATH=/home/golang/ => 在这里修改你的golang目录
~$ mkdir -p $GOPATH
~$ go get github.com/jinzhu/gorm
这种问题在以下链接中提到:
我认为最新版本已经修复了这个问题。希望能帮到你。
英文:
There are couple things you can do.
- Check your version of your GO if not the latest version then update your GO to version
1.7
- Delete the repo and clone again after updating GO.
- You could try to create new export for Golang directory with the following step :
> export GOPATH=/home/golang/ => try to modify your golang dir here
> ~$ mkdir -p $GOPATH
> ~$ go get github.com/jinzhu/gorm
this kind of problem mention in these link :
I think the latest version has fix this issue. Hope it
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论