几种语言原生开发环境构建之--Go语言
2016-08-08 15:27
471 查看
go安装
安装gvm版本管理工具
$ bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer) $ gvm install go1.7 $ go version
安装构建工具
安装gb工具
$ go get github.com/constabulary/gb/... $ mkdir src && mkdir src/someuser && mkdir src/someuser/gofirst # someuser是用户名称, gofirst是项目名称
编写代码
源码//vi src/someuser/gofirst/main.go 源码 package main import ( "fmt" "github.com/tabalt/gracehttp" "net/http" ) 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) } }
测试代码
//vi src/someuser/gofirst/main_test.go 测试代码 package main import ( "errors" "testing" ) func Division(a, b float64) (float64, error) { if b == 0 { return 0, errors.New("除数不能为0") } return a / b, nil } func Test_Division_1(t *testing.T) { if i, e := Division(6, 2); i != 3 || e != nil { //try a unit test on function t.Error("除法函数测试没通过") // 如果不是如预期的那么就报错 } else { t.Log("第一个测试通过了") //记录一些你期望记录的信息 } }
安装glide包管理工具
$ curl https://glide.sh/get | sh
项目构建
目录结构|-bin |-pkg |---linux-386 |-----github.com |-------tabalt |-----wooz |-------http |---------vendor |-----------github.com |-------------tabalt |---------------gracehttp |-src |---wooz |-----http |-----somes |-------test |-vendor |---github.com |-----tabalt |-------gracehttp |---------gracehttpdemo |---src
构建
$ glide init #初始化依赖到glide.yaml文件,并get依赖到vendor目录 $ glide --debug up #更新依赖 $ mkdir vendor/src $ mv vendor/g* vendor/src/ $ gb build #构建 $ gb test -v # 测试或则 go test src/test/*
配置文件glide.yaml
package: . import: - package: github.com/tabalt/gracehttp testImport: - package: github.com/smartystreets/goconvey version: ^1.6.2 subpackages: - convey ignore: - wooz/somes #此处忽略没有git管理的本地包名,让glide不用去github获取代码
项目源代码
相关文章推荐
- 几种语言原生开发环境构建之--Python语言
- 几种语言原生开发环境构建之--Elm语言
- 几种语言原生开发环境构建之--Lua语言
- 几种语言原生开发环境构建之--Typescript语言
- 几种语言原生开发环境构建之--Haskell语言
- 在ubuntu下构建go语言开发环境的方法
- Go语言的开发环境配置的经验总结
- Go语言开发的第一步,安装开发环境编写第一个Go程序
- 搭建Go语言开发环境-优化篇
- Go语言知识积累——特点简介与windows开发环境搭建
- Go语言知识积累——特点简介与windows开发环境搭建
- win7下配置GO语言环境 + eclipse配置GO开发
- Go语言环境搭建开发环境和配置
- Ubuntu 配置 Go 语言开发环境(Sublime Text+GoSublime)
- go语言开发环境配置:sublime text3+gosublime+gocode
- win7下配置GO语言环境 + eclipse 配置GO开发
- Eclipse平台下配置Go语言开发环境(Win7)
- Google Go语言开发环境搭建
- CentOS下go 语言开发环境源码安装
- Go语言开发环境搭建