无法访问Go库

问题描述 投票:3回答:3

我有一个工作项目,我添加了一些库。一切都很好,直到这一步。然后我将我的代码推送到服务器。我再次尝试将新的克隆存储在存储库中,并且我遇到了以下错误。

去文件找不到错误

当我尝试去做 - (再次回购)我得到

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库存储库指向其他一些存储库提交。 enter image description here

git go
3个回答
0
投票

你可以做几件事。

  1. 如果不是最新版本,请检查您的GO版本然后将您的GO更新为版本1.7
  2. 更新GO后删除repo并再次克隆。
  3. 您可以尝试使用以下步骤为Golang目录创建新导出:
export GOPATH=/home/golang/    => try to modify your golang dir here
~$ mkdir -p $GOPATH
~$ go get github.com/jinzhu/gorm

这些问题在这些链接中提到:

我认为最新版本已经解决了这个问题。希望它


0
投票

我尝试了这种方法,它起作用,因为这是唯一的工作我留下:

新鲜克隆项目并在其中导航;创建了install.sh,它将设置GOPATH,删除库然后重新下载它。

#!/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

文件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

#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

所有这些都适用于以下目录结构:

Project Root -----bin -----pkg -----src -----src/github.com/ -----src/github.com/gorilla/mux -----src/github.com/gorilla/handlers -----src/yours/project/code


0
投票

我今天遇到了同样的问题,我通过在本地依赖项中初始化一个.git repo来修复它。所以在github.com/jinzhu/gorm里面运行:

git init 

git add . 
git commit -m "first commit"
© www.soinside.com 2019 - 2024. All rights reserved.