external package from go get

1k views Asked by At

I want use code.google.com/p/google-api-go-client/drive/v2 and other.

My app is structured like:

+-- MyApp
+---- app.yaml
+---- main.go
+---- src/
+------ ...external package...

My GOPATH is equal to "MyApp/src"

In my main.go I have `// +build !appengine"

I can't launch goapp serve, I get

2014/12/09 22:20:32 Can't find package "code.google.com/p/google-api-go-client/googleapi" in $GOPATH: cannot find package "code.google.com/p/google-api-go-client/googleapi" in any of:

and many other who said the same.

How I can use package download from a go get?

Thank you.

1

There are 1 answers

0
Rohan On BEST ANSWER

Typically a gopath looks like this: (I have added random projects to it to demonstrate what it could look like)

  • gopath
    • src
      • code.google.com
        • p
          • google-api-go-client
            • etc
      • github.com
        • fluffle
          • goirc
      • rohan.com <- This is where your own projects go(or in code.google.com or github.com)
        • my_random_project
          • main.go
          • helper.go
        • my_app_engine_project
          • app
            • app.yaml
            • my_app_engine_project.go
          • routes
            • random_rest_route.go
          • process
            • random_route_logic.go
    • pkg
    • bin

Your $GOPATH$ enviroment variable should point to that root folder which contains src, pkg and bin.

So when you go get a package from github for example it'l be put in the github.com src folder, and that's when you'll be able to use that library in your own projects.

Usage Example

So for example, if I need the fluffle/goirc library from github, I'l type:

go get github.com/fluffle/goirc

The library will then be placed in:

gopath/src/github.com

And I can use the library by importing it with:

import (
     "github.com/fluffle/goirc/client"
)

And then use it

client.NewConfig("My User Name")