9

I have followed this guide in installing the AppEngine SDK. https://developers.google.com/appengine/docs/go/gettingstarted/introduction

I have originally installed Go 1.2 with Brew (on OSX). I've set my paths:

export GOPATH=$HOME/Documents/go
export PATH=$GOPATH/bin:$PATH
export PATH=$HOME/Documents/go/go_appengine:$PATH

I copy/pasted hello world app, and ran it with goapp serve. All good.

Now, as soon as I try to use appengine:

import (
    "appengine"
)

I get compile time error:

api.go:5:5: cannot find package "appengine" in any of:
    /usr/local/Cellar/go/1.2/libexec/src/pkg/appengine (from $GOROOT)
    /Users/jan/Documents/go/src/appengine (from $GOPATH)

The starting guide documentation doesn't say anything about this. It seems like the SDK has its own $GOPATH like dir with /src, /pkg and /bin. I assume I would have to manually switch the $GOPATH between SDK and native Go all the time, which doesn't make any sense and doesn't even work for me (as I mostly work on non-appengine stuff).

I am clearly doing something wrong here. What am I missing?

EDIT: It seems like the actual appengine server is compiling and running fine, however my entire setup is broken (testing, Vim...). Is there any workaround?

if __name__ is None
  • 11,083
  • 17
  • 55
  • 71
  • Try following the [steps](https://stackoverflow.com/questions/11286534/test-cases-for-go-and-appengine) provided by Kyle Finley in his answer. – alpe1 Jan 09 '14 at 09:59

5 Answers5

7

As provided by alpe1, the following lines solve the vim compiler go:

ln -s $APPENGINE_SDK/goroot/src/pkg/appengine $GOROOT/src/pkg/ 
ln -s $APPENGINE_SDK/goroot/src/pkg/appengine_internal $GOROOT/src/pkg/
mkdir -p $GOROOT/src/pkg/code.google.com/p/
ln -s $APPENGINE_SDK/goroot/src/pkg/code.google.com/p/goprotobuf
$GOROOT/src/pkg/code.google.com/p/

and I needed to update gocode lib-path (cf Options) to have the autocompletion for appengine:

gocode set lib-path "$APPENGINE_SDK/goroot/pkg/linux_amd64_appengine"
Community
  • 1
  • 1
pgu
  • 86
  • 4
  • The only problem is, the 3rd party libraries that I use are compiled for 1.2 and GAE uses 1.1.2 so `goapp serve` gives me errors now. How could I fix that? – if __name__ is None Jan 10 '14 at 06:27
  • 4
    Don't do this. You should not intermingle a regular Go installation with the Go App Engine SDK. – dsymonds Jan 13 '14 at 00:35
2

For testing appengine, consider "appengine/aetest", which replaces the testing framework mentioned in other answers about this issue.

As for vim, let's avoid symlinking between distinct GOROOT directories. That's a recipe for bugs of the worst kind and sort: Slightly mismatched library dependencies. Have you considered simply exporting a different GOROOT before you launch vim? You could drop it into an alias trivially:

# You could of course drop this in your .bashrc, .bash_profile, or .zshrc
$ alias appvim="export GOROOT=$APPENGINE_SDK/goroot && vim"

All syntastic does is look in $GOROOT/src for the relevant includes. By changing $GOROOT to be the appengine SDK's, you're going to check the correct libraries.

Christopher
  • 42,720
  • 11
  • 81
  • 99
2

Prefix the packages with google.golang.org eg.

"google.golang.org/appengine"

Works with version 1.9.35.

James Bloomer
  • 5,212
  • 2
  • 22
  • 23
1

You don't say what version of the Go App Engine SDK you are using. Make sure it's the most recent from https://developers.google.com/appengine/downloads#Google_App_Engine_SDK_for_Go.

You should be able to run goapp serve (or goapp build, goapp test, etc.) without any changes to the extracted SDK. You should only need to add the path to go_appengine to your PATH.

You should be able to have a single GOPATH for both regular Go and App Engine.

Your error message implies that the GOROOT is /usr/local/Cellar/go/1.2/libexec. Is that when you invoke goapp? That shouldn't happen. Does anything change if you use the full path $HOME/Documents/go/go_appengine/goapp?

dsymonds
  • 857
  • 5
  • 8
  • You are correct. This has all changed with version 1.7.4 as described [here](https://blog.golang.org/the-app-engine-sdk-and-workspaces-gopath) – eQ19 Mar 28 '15 at 06:35
0

Building on Christopher's answer, gocode looks in $GOROOT/pkg for a path matching your architecture (e.g. $GOROOT/pkg/darwin_amd64). However, the code directory in AppEngine's setup is suffixed with _appengine (e.g. $GOROOT/pkg/darwin_amd64_appengine). You can fix this discrepancy by creating a simlink:

export APPENGINE_SDK=/your/appengine/sdk/directory/go_appengine
ln -s $APPENGINE_SDK/goroot/pkg/your_architecture_appengine $APPENGINE_SDK/goroot/pkg/your_architecture_amd64

Be sure to replace the AppEngine directory and architectures above with your own.

After doing this, create an alias to change GOROOT and start vim

alias appvim="export GOROOT=$APPENGINE_SDK/goroot && vim"

as Christopher mentioned in his comment.

zeptonaut
  • 895
  • 3
  • 10
  • 20