Skip to content

Instantly share code, notes, and snippets.

@ngauthier
Created April 6, 2015 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ngauthier/9bc17108c57045c0295e to your computer and use it in GitHub Desktop.
Save ngauthier/9bc17108c57045c0295e to your computer and use it in GitHub Desktop.
Minimum Viable Go Dependency Manager
package main
import (
"fmt"
"os"
"os/exec"
"strings"
)
func main() {
if len(os.Args) < 3 {
fmt.Println("Usage: checkit <import path> <ref>")
os.Exit(1)
}
imp := os.Args[1]
ref := os.Args[2]
fmt.Println("checkit: checking out", imp, "@", ref)
paths := strings.Split(os.Getenv("GOPATH"), ":")
var path string
for _, p := range paths {
full := strings.Join([]string{p, "/src/", imp}, "")
if _, err := os.Stat(full); err == nil {
path = full
break
}
}
if path == "" {
fmt.Println("checkit: could not find", imp)
os.Exit(1)
}
cmd := exec.Command("git", "checkout", ref)
cmd.Dir = path
if err := cmd.Run(); err != nil {
fmt.Println("checkit:", err)
os.Exit(1)
}
}
build:
# get all the deps
go get -d -v -t ./...
# check out the library to the right ref
checkit github.com/myaccount/mylib abc123
# build stuff!
go build ./...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment