Golang tutoriel GVM et go IRIS

Install Golang

In this article we will use GVM to manage multiple Golang version.

bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
. .bashrc
gvm install go1.4.3
gvm use go1.4.3
gvm install go1.6.2
gvm use go1.6.2 --default

If you have some trouble to compile go1.4.3, you can use binary version

gvm install go1.6.2 --binary

Prepare your environment

mkdir -p dev/go/my-project/{src,pkg,bin}
cd dev/go/my-project
gvm pkgset create --local
gvm pkgset use --local

create a basic Iris project

Fix Iris 3rc GOPATH bug

export GOPATH=$PWD

create it

go get -u -v github.com/iris-contrib/middleware/logger
go get -u -v github.com/kataras/iris/iris
iris create 

Go Unit Test

any files ended by « _test.go » will be consider as a test.
to execute it:

go test

in verbose mode

go test -test.v

to have teardown / setup in your unit test you can add a TestMain function to your test like

func TestMain(m *testing.M) {
        // setup test
        // run tests	
        code := m.Run()
        // clear env


50 Shades of Go

Laisser un commentaire