How to import a local Go package into GAE

How to import local packages in Golang + GAE?

I want something like this:

app/
-app.yaml
-/my_app
--my_app.go
--/package1
---package1.go

List my_app.go:

package my_app

import (
  "http"
  "./package1"
)

func init() {
  http.HandleFunc("/", package1.index)
}

The list of package1.go:

package package1

import (
  "http"
  "fmt"
)

func index (w http.ResponseWriter, r * http.Request) {
  fmt.Fprint(w, "I'm index page =) ")
}

In this case, I have an error, for example:

/path/to/project/my_app/my_app.go:5: can't find import: ./package1
2011/11/03 10:50:51 go-app-builder: Failed building app: failed running 6g: exit status 1

Thanks for the help.

+5
source share
2 answers

You either need to link or copy packages to your application directory. The path to the root of the application directory must match the import path. To use package1, you must configure your application directory as follows:

app.yaml
yourapp/yourapp.go
package1/package1.go

Strike> from https://groups.google.com/d/msg/golang-nuts/coEvrWIJGTs/75GzcefKVcIJ

+1
source

dupoxy-, - "my_app/package1":

import (
    "http"
    "my_app/package1"
)
+6

All Articles