Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does GO look for google-cloud-sdk ? What should GOPATH be?

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'  
like image 947
BryanWheelock Avatar asked Apr 24 '17 15:04

BryanWheelock


1 Answers

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

enter image description here

Location for google-cloud-sdk folder

enter image description here

like image 185
RayfenWindspear Avatar answered Oct 24 '22 21:10

RayfenWindspear