[Go] パッケージ管理のdepを使う

公式のドキュメント: dep
git hub: https://github.com/golang/dep

### Binary installation
$ curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 5230 100 5230 0 0 7623 0 –:–:– –:–:– –:–:– 7612
ARCH = amd64
OS = linux
Will install into /home/vagrant/go/bin
Fetching https://github.com/golang/dep/releases/latest..
Release Tag = v0.5.4
Fetching https://github.com/golang/dep/releases/tag/v0.5.4..
Fetching https://github.com/golang/dep/releases/download/v0.5.4/dep-linux-amd64..
Setting executable permissions.
Moving executable to /home/vagrant/go/bin/dep

どうやら、私のケースでは /home/vagrant/go/bin/depにあるよう

$ /home/vagrant/go/bin/dep version
dep:
version : devel
build date :
git hash :
go version : go1.15.14
go compiler : gc
platform : linux/amd64
features : ImportDuringSolve=false
$ mkdir -p /home/vagrant/go/src/github.com/me/example
$ cd /home/vagrant/go/src/github.com/me/example
$ /home/vagrant/go/bin/dep init
$ ls
Gopkg.lock Gopkg.toml vendor

main.go

package main

import (
	"fmt"
	
	"github.com/carlescere/scheduler"
	"runtime"
)

func main(){
	scheduler.Every(3).Seconds().Run(printSuccess)
	runtime.Goexit()
}

func printSuccess(){
	fmt.Printf("Success!! \n")
}

$ go run main.go
main.go:6:2: cannot find package “github.com/carlescere/scheduler” in any of:
/home/vagrant/go/src/github.com/me/example/vendor/github.com/carlescere/scheduler (vendor tree)
/usr/lib/golang/src/github.com/carlescere/scheduler (from $GOROOT)
/home/vagrant/go/src/github.com/carlescere/scheduler (from $GOPATH)

このままでは 以下のようにcannot findとなるのでensureする
$ /home/vagrant/go/bin/dep ensure

$ go run main.go
Success!!
Success!!
Success!!
Success!!
Success!!
Success!!

なるほど、phpでいうcomposerみたいなものか
素晴らしい