LoginSignup
21
5

More than 5 years have passed since last update.

go1.11のModulesを使って依存パッケージを管理する

Posted at

今まで glidedep を使って依存パッケージを管理していたが、go1.11からModulesがお試し版で使えるようになったので試してみる。

まず、プロジェクトクトの配下で以下のコマンドを実行すると、go.modというファイルが作成される。

$ GO111MODULE=on go mod init

go.modの中身はこんな感じ。

go.mod
module github.com/fuku2014/sample

require (
        github.com/go-sql-driver/mysql v1.4.0
        github.com/jessevdk/go-flags v1.4.0
)

この状態で go buildを実行すると、自動的に依存ライブラリをダウンロードしてきてくれてビルドされる

$ GO111MODULE=on go build pkg/main.go

いろいろな依存パッケージ管理ライブラリが乱立している中、標準のgoコマンドで管理できるようになったのはうれしい。
go1.12から正式にリリースされる予定になっている。

21
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21
5