Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Go - cannot find package "appengine"

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?

like image 902
if __name__ is None Avatar asked Jan 09 '14 05:01

if __name__ is None


4 Answers

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"
like image 65
pgu Avatar answered Nov 06 '22 10:11

pgu


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.

like image 20
Christopher Avatar answered Nov 06 '22 10:11

Christopher


Prefix the packages with google.golang.org eg.

"google.golang.org/appengine"

Works with version 1.9.35.

like image 2
James Bloomer Avatar answered Nov 06 '22 09:11

James Bloomer


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?

like image 1
dsymonds Avatar answered Nov 06 '22 09:11

dsymonds