在Go中修改导入的库

My Problem

Elastic Beats is an open source project for log shippers written in Go. It features several log outputs, including console, Elasticsearch and Redis. I would like to add an output of my own - to AWS Kinesis.

I have cloned the repo to ~/github/beats, and tried building it:

$ cd filebeat; go build main.go

However, it failed due to a missing library which is a part of the project:

main.go:6:2: cannot find package "github.com/elastic/beats/filebeat/cmd" in any of:
    /usr/local/go/src/github.com/elastic/beats/filebeat/cmd (from $GOROOT)
    /Users/adam/go/src/github.com/elastic/beats/filebeat/cmd (from $GOPATH)

A directory of the project is dependent on a package from the same repo, but instead of looking one directory up the hierarchy it looks in the GOPATH.

So, go get github.com/elastic/beats/filebeat/cmd fetched the code, and now go build main.go works. Changing the code in my GOPATH is reflected in these builds.

This leaves me with an structural inconvenience. Some of my code is at a working directory, and some of it is at my GOPATH and included by the code in my working directory.

I would like to have all my code in a single directory for various reasons, not the least being keeping everything under version control.

What Have I Tried

Mostly searching for the problem. I am quite new to Go, so I might have missed the correct terminology.

My Question

What is the right way to edit the code of an imported library in Go?

A project working copy should be checked out into $GOPATH/src/package/import/path - for example, this project should be checked out into /Users/adam/go/src/github.com/elastic/beats. With the project in the correct location, the go tooling will be able to operate on it normally; otherwise, it will not be able to resolve imports correctly. See go help gopath for more info.

One of the recommended ways to work with other's packages is:

  1. Get the sources of the original package:

    go get github.com/elastic/beats
    

    As a result you will clone project's git repository to the folder

    $GOPATH/src/github.com/elastic/beats
    
  2. Make some fixes, compile code, fix, compile... When you make go install package will be compiled and installed to your system. When you need merge updates from original repository you can git pull them.

Everything is OK. What's next? How to share your work with others?

  1. Fork project on github, suppose it will be github.com/username/beats

  2. Add this fork as another remote mycopy (or any other name you like) to your local repository

    git remote add mycopy git://github.com/username/beats.git
    
  3. When all is done you can push updated sources to your repo on github

    git push mycopy
    

    and then open a pull-request to original sources. This way you can share your work with others. And keep your changes in sync with mainstream.