Golang的自制方法

I want to write a Homebrew formula for installing a Go package and its dependencies. Here's what I've got so far:

class LsGo < Formula
  desc "A more colorful, user-friendly implementation of `ls` written in Go"
  homepage "https://github.com/acarl005/ls-go"
  url "https://github.com/acarl005/ls-go/archive/v0.0.0.tar.gz"
  sha256 "db9ba7300fbbaf92926b2c95fd63e3e936739e359f123b5a45e6ca04b490af51"

  depends_on "go" => :build

  def install
    ENV["GOPATH"] = buildpath
    (buildpath/"src/github.com/acarl005").mkpath
    ln_s buildpath, buildpath/"src/github.com/acarl005/ls-go"
    system "cd", buildpath/"src/github.com/acarl005/ls-go"
    system "go", "get", "./"
    system "cd", "-"
    system "go", "build", "-o", bin/"ls-go"
  end

  test do
    system bin/"ls-go", "--help"
  end
end

But I get an error about running go get ./ outside the $GOPATH.

==> cd /private/tmp/ls-go-20180612-22435-oidqms/ls-go-0.0.0/src/github.com/acarl005/ls-go
==> go get ./
Last 15 lines from /Users/andy/Library/Logs/Homebrew/ls-go/02.go:
2018-06-12 16:31:14 -0700

go
get
./

go get: no install location for directory /private/tmp/ls-go-20180612-22435-oidqms/ls-go-0.0.0 outside GOPATH

This doesn't make sense to me. I set ENV["GOPATH"] to /private/tmp/ls-go-20180612-22435-oidqms/ls-go-0.0.0/, and I cd'ed into a subdir of that path. Why is it saying I'm outside the $GOPATH?

How should I get the dependencies for my package?

EDIT: I'd prefer to avoid vendoring packages.

I'm pretty sure that your Homebrew formula is just a Ruby class with some DSL magic to make it friendlier. That means that system runs commands in a separate process so this:

system "cd", "some_directory"

will change the current directory in a separate process and then that process exits without affecting the parent.

You should use Dir.chdir instead:

Dir.chdir buildpath/"src/github.com/acarl005/ls-go" do
  system "go", "get", "./"
end
system "go", "build", "-o", bin/"ls-go"

Using the block form (i.e. Dir.chdir dir do ... end) will change directives, run the system command, and then change back to the original directory before continuing so you don't have to worry about the cd - part.