Golang包依赖管理工具gb
原文链接:http://tabalt.net/blog/golang... 一个Golang项目工程通常由 gb项目不放在你的$GOPATH中,也不需要为你的gb项目设置或修改$GOPATH。依赖的第三包需要放到 安装gbgb的官网是:http://getgb.io/,github地址是:https://github.com/constabulary/gb/。 使用如下命令即可安装gb: go get github.com/constabulary/gb/... 安装gb后,会有 export PATH=$PATH:$GOPATH/bin 使用gb进行项目开发我们以一个简单的提供HTTP页面的“Hello World”程序来学习一下gb的使用。为了体现gb管理第三方包依赖的特性,我们引入一个支持HTTP服务优雅重启的第三方包 github.com/tabalt/gracehttp。 创建gb项目目录结构: cd ~/helloworld mkdir -p src/helloworld mkdir -p vendor/src 编写“Hello World”程序 #vim src/helloworld/main.go package main import ( "fmt" "net/http" "github.com/tabalt/gracehttp" ) func main() { http.HandleFunc("/",func(w http.ResponseWriter,r *http.Request) { fmt.Fprintf(w,"hello world") }) err := gracehttp.ListenAndServe(":8080",nil) if err != nil { fmt.Println(err) } } 添加依赖的第三包 gb vendor fetch github.com/tabalt/gracehttp 目前为止整个项目目录结构如下: ./ |-- src | `-- helloworld | `-- main.go `-- vendor |-- manifest `-- src `-- github.com `-- tabalt `-- gracehttp |-- README.md |-- connection.go |-- gracehttpdemo | `-- main.go |-- listener.go `-- server.go 编译执行程序 gb build helloworld ./bin/helloworld 打开一个新终端并执行 hello world 提交所有代码到git仓库 git init git add . git commit -am 'init hello world project with gb' git add remote -v $your_remote_git_repository git push origin master:master gb常用命令在上面的项目开发中,我们用到了两个命令 可以通过 gb 命令列表
gb vendor 功能列表
原文链接:http://tabalt.net/blog/golang... (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |