You must add a language: gofile to your .travis.yml, so Travis CI knows that the project is a Go project and correctly sets GOPATH and GOROOT. By default , Travis CI launches go get -d -v ./... && go build -v ./...in step install, so I think you can change your .travis.yml to this:
language: go
before_script:
- go run example.go
go run example.go script, :
language: go
script:
- go run example.go
Go docs Travis CI .