内容简介:相信各位更多實戰影片可以參考我的
相信各位 Go 語言 開發者陸陸續續都將專案從各種 Vendor 工具 轉換到 Go Module ,本篇會帶大家一步一步從舊專案轉換到 Go Module,或是該如何導入新專案,最後會結合 CI/CD 著名的兩套工具 Travis 或 Drone 搭配 Go Module 測試。
影片介紹
- 舊專案內 vendor 轉換成 go module 設定 (1:15)
- 新專案如何啟用 go module (6:20)
- 在 Travis CI 或 Drone 如何使用 go module (8:31)
- 在開源專案內並存 vendor 及 go module (介紹 Gin 如何使用 vendor 及 go module) (15:00)
更多實戰影片可以參考我的 Udemy 教學系列
舊專案
假設原本的專案有導入 vendor 工具類似 govendor 或 dep,可以在目錄底下找到 vendor/vendor.json 或 Gopkg.toml ,這時候請在專案目錄底下執行
$ go mod init github.com/appleboy/drone-line $ go mod download
您會發現 go module 會從 vendor/vendor.json 或 Gopkg.toml 讀取相關套件資訊,接著寫進去 go.mod 檔案,完成後可以下 go mod dowload 下載所有套件到 $HOME/go/pkg/mod
新專案
新專案只需要兩個步驟就可以把相關套件設定好
$ go mod init github.com/appleboy/drone-line $ go mode tidy
其中 tidy 可以確保 go.mod 或 go.sum 裡面的內容都跟專案內所以資料同步,假設在程式碼內移除了 package,這樣 tidy 會確保同步性移除相關 package。
整合 Travis 或 Drone
go module 在 1.11 版本預設是不啟動的,那在 Travis 要把 GO111MODULE 環境變數打開
matrix:
fast_finish: true
include:
- go: 1.11.x
env: GO111MODULE=on
完成後可以到 Travis 的環境看到底下 go get 紀錄
而在 Drone 則是設定如下:
steps:
- name: testing
image: golang:1.11
pull: true
environment:
GO111MODULE: on
commands:
- make vet
- make lint
- make misspell-check
- make fmt-check
- make build_linux_amd64
- make test
結論
在開源專案內為了相容許多 Go 版本,所以 Gin 同時支援了 govendor 及 go module,其實還蠻難維護的,這邊可以透過 travis 環境變數的判斷來達成目的:
language: go
sudo: false
go:
- 1.6.x
- 1.7.x
- 1.8.x
- 1.9.x
- 1.10.x
- 1.11.x
- master
matrix:
fast_finish: true
include:
- go: 1.11.x
env: GO111MODULE=on
git:
depth: 10
before_install:
- if [[ "${GO111MODULE}" = "on" ]]; then mkdir "${HOME}/go"; export GOPATH="${HOME}/go"; fi
install:
- if [[ "${GO111MODULE}" = "on" ]]; then go mod download; else make install; fi
- if [[ "${GO111MODULE}" = "on" ]]; then export PATH="${GOPATH}/bin:${GOROOT}/bin:${PATH}"; fi
- if [[ "${GO111MODULE}" = "on" ]]; then make tools; fi
詳細設定請 參考 .travis 設定
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- ENVI扩展工具:RandomForest分类工具
- 15大安全工具和下载黑客工具
- 版本管理工具及 Ruby 工具链环境
- [译]Go性能分析工具工具和手段
- 工具 | 一个在线生成 nginx 配置文件的开源工具
- 【工具分享】PxCook像素大厨——很好用的标记工具
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Sexy Web Design
Elliot Stocks / SitePoint / 2009-03-28 / $39.95
Description A guide to building usable, aesthetically pleasing interfaces for web sites and web applications by applying timeless principles of user-centered design. This book focuses on practical ......一起来看看 《Sexy Web Design》 这本书的介绍吧!