GO在哪里寻找google-cloud-sdk? GOPATH应该是什么? [英] Where does GO look for google-cloud-sdk ? What should GOPATH be?

查看:138
本文介绍了GO在哪里寻找google-cloud-sdk? GOPATH应该是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在osX上设置Go App引擎时遇到问题。 google-cloud-sdk路径应该位于GOROOT还是GOPATH?



我将google-cloud-sdk放入/ usr / local

它看起来有以下源代码:goroot /

  / usr / local / google-cloud -sdk / platform / google_appengine / goroot / 

去env

  GOPATH =/ usr / local / google-cloud-sdk / platform / google_appengine / goroot
GORACE =
GOROOT =/ usr / local / go
GOTOOLDIR =/ usr / local / go / pkg / tool / darwin_amd64

$ go get

  package google.golang.org/appengine:无法下载,/ usr / local / google -cloud-sdk / platform / google_appengine / goroot是一个GOROOT,而不是GOPATH。有关更多详细信息,请参阅:'go help gopath'
包google.golang.org/appengine/datastore:无法下载,/ usr / local / google-cloud-sdk / platform / google_appengine / goroot是GOROOT,而不是GOPATH。有关更多详细信息,请参阅:'go help gopath'

当我试图将PATH更改为include / src :

  GOPATH =/ usr / local / google-cloud-sdk / platform / google_appengine / goroot / src

$ go get

  package google.golang.org/appengine:mkdir / usr / local / google-cloud-sdk / platform / google_appengine / goroot / src / src:权限被拒绝
包google.golang.org/appengine/datastore :无法在以下任何一个中找到包google.golang.org/appengine/datastore:
/usr/local/go/src/google.golang.org/appengine/datastore(from $ GOROOT)
/usr/local/google-cloud-sdk/platform/google_appengine/goroot/src/src/google.golang.org/appengine/datastore(from $ GOPATH)

我附加了google-cloud-sdk到GOROOT的路径:

  export GOROOT =/ usr / local / go /:/ usr / local / google-cloud-sdk / platform / google_appengine / goroot

GO似乎不喜欢GOROOT中的多个路径:

$ go获取

  go:无法找到GOROOT目录:/ usr / local / go /:/ usr / local / google-cloud-sdk / platform / google_appengine / goroot 

在将源复制到/ usr / local

$后,我确实运行了./install.sh脚本b
$ b

添加的附加PATH没有解决我遇到的错误。



我看到了这个答案:



google-cloud-sdk文件夹的位置




I'm having trouble setting up Go App engine on osX. Should the google-cloud-sdk path be in GOROOT or GOPATH?

I put the google-cloud-sdk in /usr/local

It looks like there is source code in: goroot/

/usr/local/google-cloud-sdk/platform/google_appengine/goroot/

go env

GOPATH="/usr/local/google-cloud-sdk/platform/google_appengine/goroot"  
GORACE=""  
GOROOT="/usr/local/go"  
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64" 

$ go get

package google.golang.org/appengine: cannot download, /usr/local/google-cloud-sdk/platform/google_appengine/goroot is a GOROOT, not a GOPATH. For more details see: 'go help gopath'   
package google.golang.org/appengine/datastore: cannot download, /usr/local/google-cloud-sdk/platform/google_appengine/goroot is a GOROOT, not a GOPATH. For more details see: 'go help gopath'  

When I attempted to change the PATH to include /src:

GOPATH="/usr/local/google-cloud-sdk/platform/google_appengine/goroot/src"  

$ go get

package google.golang.org/appengine: mkdir /usr/local/google-cloud-sdk/platform/google_appengine/goroot/src/src: permission denied  
package google.golang.org/appengine/datastore: cannot find package "google.golang.org/appengine/datastore" in any of:  
    /usr/local/go/src/google.golang.org/appengine/datastore (from $GOROOT)  
    /usr/local/google-cloud-sdk/platform/google_appengine/goroot/src/src/google.golang.org/appengine/datastore (from $GOPATH)  

I appended the path to google-cloud-sdk to GOROOT:

export GOROOT="/usr/local/go/:/usr/local/google-cloud-sdk/platform/google_appengine/goroot"

GO doesn't seem to like multiple paths in GOROOT:
$ go get

go: cannot find GOROOT directory: /usr/local/go/:/usr/local/google-cloud-sdk/platform/google_appengine/goroot

I did run the ./install.sh script after I copied the source to /usr/local

The additional PATH's added did not fix the errors I was having.

I saw this answer: Test cases for go and appengine

But it's from 5 years ago and it seems clunky/hacky. It would seem in 5 years there would be a more elegant solution that copying individual directories and creating symlinks.

EDIT **********************
mv /usr/local/google-cloud-sdk/ ~/go/ then deleted GOPATH and GOROOT from .bash_profile

I then ran ./install.sh

I attempted to run 'go get':

$ go get

go install: no install location for directory /Users/Bryan/work/gocode/skincarereview outside GOPATH

Since that failed, I added the path to the working directory of code AND appended the path to google-cloud-sdk to PATH:

export GOPATH = "/Users/Bryan/work/gocode/skincarereview"
export PATH=$HOME/google-cloud-sdk:$PATH

go get get failed with the same message:

$ go get  

go install: no install location for directory /Users/Bryan/work/gocode/skincarereview outside GOPATH  
    For more details see: 'go help gopath'  

解决方案

It goes in neither $GOROOT or $GOPATH. Just unpack it to your $HOME directory and run the installer. If necessary, add it to your $PATH by adding this line to your .bash_profile.

export PATH=$HOME/google-cloud-sdk:$PATH

Make sure you grab the golang SDK as well with gcloud components install app-engine-go https://cloud.google.com/appengine/docs/standard/go/download

DO NOT change your path to include the src dir in google-cloud-sdk/platform/google_appengine/goroot/src. That will break things. You leave your $GOPATH to be your normal installation. Using the App Engine SDK for Go automatically uses the sources in that dir without any manipulation.

Also, you should NEVER MANUALLY change $GOROOT unless you plan on compiling a new Go version from source (as in a new version of the language). It will automatically set the proper $GOROOT for you. https://dave.cheney.net/2013/06/14/you-dont-need-to-set-goroot-really

If your install is messed up beyond reason (happened to me once), just remove the cloud SDK and any references to it in your $PATH. Also completely uninstall the regular Go installation. Then start from scratch. Install Go, unpack google-cloud-sdk, run installer (add to $PATH if needed), gcloud components install app-engine-go. Voila.

When developing for App Engine, your go sources go into your REGULAR $GOPATH. They DO NOT go in google-cloud-sdk/... anywhere. To run the dev_appserver locally, run dev_appserver.py [path-to-source] where the given path contains your code and the app.yaml. I usually cd in to my project path (e.g. cd $HOME/go/src/myproject) and run with dev_appserver.py ./. https://cloud.google.com/appengine/docs/standard/go/tools/using-local-server

Deployment is covered here. https://cloud.google.com/appengine/docs/standard/go/tools/uploadinganapp

EDIT: Folder structure.

$GOPATH = $HOME/go

Location for google-cloud-sdk folder

这篇关于GO在哪里寻找google-cloud-sdk? GOPATH应该是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆