gomobile init fails to find stdlib.h - go

I'm trying to make a cross-platform native library using go and found this tutorial for gomobile. However, when I try to initialize it (even if I give the Android NDK path although I don't in the example below) it seems to fail because it can't find stdlib.h.
I tried to do some investigation around cgo but nothing jumped out at me, was hoping someone more familiar with the ecosystem could point me in the right direction.
$ gomobile init
gomobile: go install -gcflags=-shared -ldflags=-shared -pkgdir=/Users/myusername/go/pkg/gomobile/pkg_android_arm std failed: exit status 2
# runtime/cgo
_cgo_export.c:2:10: fatal error: 'stdlib.h' file not found
My environment... (I'm on OS X El Capitan with fresh install of go1.9 darwin/amd64)
$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/myusername/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/rx/l7pzlrld2mqczrfb36t536hh0000gp/T/go-build735124167=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
EDIT: (Adding verbose output of failed init)
$ gomobile init -v
# Installing golang.org/x/mobile/gl.
# Installing golang.org/x/mobile/app.
# Installing golang.org/x/mobile/exp/app/debug.
# Installing std for android/arm.
runtime/internal/sys
runtime/internal/atomic
runtime
sync/atomic
unicode
internal/race
errors
unicode/utf8
math
math/bits
container/list
container/ring
crypto/subtle
crypto/internal/cipherhw
internal/nettrace
runtime/cgo
vendor/golang_org/x/crypto/poly1305
sync
encoding
unicode/utf16
image/color
internal/cpu
internal/syscall/windows
internal/syscall/windows/registry
image/color/palette
internal/syscall/windows/sysdll
io
syscall
internal/singleflight
runtime/race
# runtime/cgo
_cgo_export.c:2:10: fatal error: 'stdlib.h' file not found
vendor/golang_org/x/text/secure
vendor/golang_org/x/text/unicode
bytes
strings
hash
crypto/cipher
runtime/trace
hash/crc32
hash/adler32
crypto/hmac
hash/crc64
hash/fnv
vendor/golang_org/x/text/transform
text/tabwriter
bufio
path
html
strconv
math/rand
math/cmplx
time
internal/syscall/unix
reflect
crypto/aes
crypto
crypto/rc4
encoding/base64
encoding/base32
encoding/ascii85
crypto/sha512
crypto/md5
crypto/sha1
crypto/sha256
image
internal/poll
image/internal/imageutil
image/draw
image/jpeg
os
os/signal
fmt
sort
encoding/binary
path/filepath
compress/bzip2
encoding/pem
container/heap
regexp/syntax
runtime/debug
crypto/des
vendor/golang_org/x/crypto/chacha20poly1305/internal/chacha20
vendor/golang_org/x/crypto/curve25519
vendor/golang_org/x/crypto/chacha20poly1305
io/ioutil
compress/flate
context
archive/tar
math/big
compress/lzw
encoding/hex
debug/dwarf
debug/gosym
debug/plan9obj
database/sql/driver
encoding/csv
encoding/gob
encoding/json
database/sql
encoding/xml
archive/zip
compress/gzip
compress/zlib
debug/macho
debug/elf
debug/pe
log
vendor/golang_org/x/net/http2/hpack
vendor/golang_org/x/text/unicode/bidi
vendor/golang_org/x/text/unicode/norm
net/url
mime
mime/quotedprintable
net/http/internal
flag
crypto/dsa
crypto/elliptic
encoding/asn1
crypto/rand
go/token
go/scanner
crypto/rsa
vendor/golang_org/x/text/secure/bidirule
regexp
text/template/parse
go/ast
go/constant
os/exec
text/scanner
crypto/ecdsa
crypto/x509/pkix
image/gif
image/png
vendor/golang_org/x/net/idna
index/suffixarray
testing
internal/trace
runtime/pprof
text/template
net/internal/socktest
os/user
runtime/pprof/internal/profile
testing/iotest
testing/quick
go/parser
go/printer
testing/internal/testdeps
internal/testenv
go/doc
html/template
go/types
go/format
go/build
go/internal/gccgoimporter
go/internal/gcimporter
go/internal/srcimporter
go/importer
gomobile: go install -gcflags=-shared -ldflags=-shared -pkgdir=/Users/myusername/go/pkg/gomobile/pkg_android_arm -v std failed: exit status 2

The issue was still reproduced on go1.10 darwin/amd64 even with issue21802 patched.
If go install -gcflags=-shared -ldflags=-shared -pkgdir=/Users/myusername/go/pkg/gomobile/pkg_android_arm std can be run on its own it succeeds, assuming the problem is an Runtime ENV problem, there is a workaround.
The trick to solve this problem:
1.Run go install -gcflags=-shared -ldflags=-shared -pkgdir=/Users/myusername/go/pkg/gomobile/pkg_android_arm std manually. Make sure it is installed successfully.
2.Then silent installStd inside init.go.
go/src/golang.org/x/mobile/cmd/gomobile/init.go (around Line 165-175)
// Install standard libraries for cross compilers.
start := time.Now()
//if ndkRoot != "" {
// Ideally this would be -buildmode=c-shared.
// https://golang.org/issue/13234.
// androidArgs := []string{"-gcflags=-shared", "-ldflags=-shared"}
// for _, arch := range archs {
// env := androidEnv[arch]
// if err := installStd(env, androidArgs...); err != nil {
// return err
// }
// }
//}
3.Install the workaround gomobile again: go install golang.org/x/mobile/cmd/gomobile
4.Run gomobile init again.

Related

Go Tools installed successfully but not appear in $GOPATH/bin

I installed go tools in vscode and the terminal showed that the tools are installed successfully:
Tools environment: GOPATH=/home/spindrift/go
Installing 1 tool at /home/spindrift/go/bin in module mode.
gopls
Installing golang.org/x/tools/gopls (gopls) SUCCEEDED
All tools successfully installed. You are ready to Go :).
But after installing the vscode keep showing gopls is inquired but missing
So I take a look at $GOPATH/bin, and there's only dlv-dap in it!
I check my configured tools:
Checking configured tools....
GOBIN: undefined
toolsGopath:
gopath: /home/spindrift/go
GOROOT: /usr/local/go
PATH: /usr/local/go/bin:/home/spindrift/.vscode-server/bin/ea3859d4ba2f3e577a159bc91e3074c5d85c0523/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Program Files/WindowsApps/Microsoft.WindowsTerminal_1.12.10732.0_x64__8wekyb3d8bbwe:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/DevelopTools/Maven/apache-maven-3.2.5/bin:/mnt/c/DevelopTools/mingw64/mingw64/bin:/mnt/c/DevelopTools/Matlab2018a/runtime/win64:/mnt/c/DevelopTools/Matlab2018a/bin:/mnt/c/DevelopTools/Lingo/:/mnt/c/DevelopTools/MongoDB/Server/bin:/mnt/c/DevelopTools/Git/cmd:/mnt/c/DevelopTools/mysql/bin:/mnt/c/DevelopTools/anaconda3:/mnt/c/DevelopTools/anaconda3/Scripts:/mnt/c/DevelopTools/anaconda3/Library/bin:/mnt/c/WINDOWS/system32:/mnt/c/DevelopTools/Go/bin:/mnt/c/DevelopTools/scala/bin:/mnt/c/Program Files/dotnet/:/mnt/c/Users/Libra/AppData/Local/Microsoft/WindowsApps:/mnt/c/DevelopTools/VSCode/Microsoft VS Code/bin:/mnt/c/Software/Bandizip/:/mnt/c/Users/Libra/AppData/Roaming/npm:/mnt/c/DevelopTools/nodejs:/mnt/c/Users/Libra/go/bin:/mnt/c/Users/Libra/.dotnet/tools:/snap/bin
PATH (vscode launched with): /home/spindrift/.vscode-server/bin/ea3859d4ba2f3e577a159bc91e3074c5d85c0523/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Program Files/WindowsApps/Microsoft.WindowsTerminal_1.12.10732.0_x64__8wekyb3d8bbwe:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/DevelopTools/Maven/apache-maven-3.2.5/bin:/mnt/c/DevelopTools/mingw64/mingw64/bin:/mnt/c/DevelopTools/Matlab2018a/runtime/win64:/mnt/c/DevelopTools/Matlab2018a/bin:/mnt/c/DevelopTools/Lingo/:/mnt/c/DevelopTools/MongoDB/Server/bin:/mnt/c/DevelopTools/Git/cmd:/mnt/c/DevelopTools/mysql/bin:/mnt/c/DevelopTools/anaconda3:/mnt/c/DevelopTools/anaconda3/Scripts:/mnt/c/DevelopTools/anaconda3/Library/bin:/mnt/c/WINDOWS/system32:/mnt/c/DevelopTools/Go/bin:/mnt/c/DevelopTools/scala/bin:/mnt/c/Program Files/dotnet/:/mnt/c/Users/Libra/AppData/Local/Microsoft/WindowsApps:/mnt/c/DevelopTools/VSCode/Microsoft VS Code/bin:/mnt/c/Software/Bandizip/:/mnt/c/Users/Libra/AppData/Roaming/npm:/mnt/c/DevelopTools/nodejs:/mnt/c/Users/Libra/go/bin:/mnt/c/Users/Libra/.dotnet/tools:/snap/bin:/usr/local/go/bin
go: /usr/local/go/bin/go: go version go1.18.1 linux/amd64
gopkgs: not installed
go-outline: not installed
gotests: not installed
gomodifytags: not installed
impl: not installed
goplay: not installed
dlv: not installed
dlv-dap: /home/spindrift/go/bin/dlv-dap: go1.18.1
path github.com/go-delve/delve/cmd/dlv
mod github.com/go-delve/delve v1.8.3-0.20220413222856-313815782614 h1:J92Zq5+vc+zzd0Gn69RxVUUC3orKgciGmurMPUSci4I=
dep github.com/cilium/ebpf v0.7.0 h1:1k/q3ATgxSXRdrmPfH8d7YK0GfqVsEKZAX9dQZvs56k=
dep github.com/cosiner/argv v0.1.0 h1:BVDiEL32lwHukgJKP87btEPenzrrHUjajs/8yzaqcXg=
dep github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM=
dep github.com/derekparker/trie v0.0.0-20200317170641-1fdf38b7b0e9 h1:G765iDCq7bP5opdrPkXk+4V3yfkgV9iGFuheWZ/X/zY=
dep github.com/go-delve/liner v1.2.2-1 h1:0hGpZh6vjI6LFTlXuHFCX9PebaluzDzps2owdMrrSuk=
dep github.com/google/go-dap v0.6.0 h1:Y1RHGUtv3R8y6sXq2dtGRMYrFB2hSqyFVws7jucrzX4=
dep github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
dep github.com/mattn/go-isatty v0.0.3 h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI=
dep github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
dep github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
dep github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
dep github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
dep github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
dep github.com/spf13/cobra v1.1.3 h1:xghbfqPkxzxP3C/f3n5DdpAbdKLj4ZE4BWQI362l53M=
dep github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
dep go.starlark.net v0.0.0-20200821142938-949cc6f4b097 h1:YiRMXXgG+Pg26t1fjq+iAjaauKWMC9cmGFrtOEuwDDg=
dep golang.org/x/arch v0.0.0-20190927153633-4e8777c89be4 h1:QlVATYS7JBoZMVaf+cNjb90WD/beKVHnIxFKT4QaHVI=
dep golang.org/x/sys v0.0.0-20211117180635-dee7805ff2e1 h1:kwrAHlwJ0DUBZwQ238v+Uod/3eZ8B2K5rYsUHBQvzmI=
dep gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
build -compiler=gc
build CGO_ENABLED=1
build CGO_CFLAGS=
build CGO_CPPFLAGS=
build CGO_CXXFLAGS=
build CGO_LDFLAGS=
build GOARCH=amd64
build GOOS=linux
build GOAMD64=v1
staticcheck: not installed
gopls: not installed
It seems that I failed to install go tools. I tried several times but the problem still unsolved.
Here's my go env
GO111MODULE="auto"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/spindrift/.cache/go-build"
GOENV="/home/spindrift/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/spindrift/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/spindrift/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18.1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1163911802=/tmp/go-build -gno-record-gcc-switches"
This is a bug in the go extension which occurs when using go 1.18. It has been fixed in recent versions of vscode-go, for details see [1] and [2].
Updating vscode and the go extension (vscode-go) should resolve your problem (as it did for me).
[1] https://github.com/golang/vscode-go/issues/2143
[2] https://github.com/golang/vscode-go/commit/656865daa974f43e8e88310e5076f3f0c4936c73
GOBIN is not present in your $PATH.
the easiest way is to add one more line to your .bashrc / .zshrc in $HOME
PATH = $PATH:$HOME
learn more on $PATH here
Some configurations are fetched from "GOENV" file.
Make sure params in that file are valid, Especially look for "GOROOT" in it.
It should exactly match your GO executable path. (In most cases it could be /usr/local/go)
If not valid, update values and try again.
The gopls is present in GOPATH and GOROOT, but still VS Code complains about not being able to find gopls.
Configured tools output shows gopls and other tools properly installed.
go version 1.17.12

linker command failing for particular golang test involving "net/http" and "time" packages

I'm new to web development and golang. I'm trying to learn go from here. Without any issues I was able to learn till concurrency part, however, I'm facing issues while trying to learn select statements. Here is what I did. hello.go contains the function, while hello_test.go has the testing code. This is the hello.go code.
package lol
func Racer(a, b string) (winner string) {
return
}
Below is the testing code
package lol
import "testing"
func TestRacer(t *testing.T) {
slowURL := "http://www.facebook.com"
fastURL := "http://www.quii.co.uk"
want := fastURL
got := Racer(slowURL, fastURL)
if got != want {
t.Errorf("got %q, want %q", got, want)
}
}
The test is failing just as expected with message hello_test.go:13: got "", want "http://www.quii.co.uk". Now I'm trying to write some more code to hello.go to make it pass.
package lol
import(
"time"
"net/http"
)
func Racer(a, b string) (winner string) {
startA := time.Now()
http.Get(a)
aDuration := time.Since(startA)
startB := time.Now()
http.Get(b)
bDuration := time.Since(startB)
if aDuration < bDuration {
return a
}
return b
}
When I'm testing now, it is giving me # runtime/cgo ld: unsupported tapi file type '!tapi-tbd' in YAML file '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libSystem.tbd' for architecture x86_64 clang-10: error: linker command failed with exit code 1 (use -v to see invocation) FAIL module [build failed]. After searching on internet forums on this error, I did sudo rm -rf /Library/Developer/CommandLineTools and reinstalled them back, but didn't help. I think it may be due to the modules I'm trying to import but I'm not sure. I don't know if it is relevant or not but I updated to macOS Big Sur two days before facing the issue. Please help in resolving the issue. TIA
Edit: go env is returning
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/{user_name}/Library/Caches/go-build"
GOENV="/Users/{user_name}/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/{user_name}/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/{user_name}/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.16.5/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.16.5/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.16.5"
GCCGO="gccgo"
AR="/Users/{user_name}/opt/anaconda3/bin/x86_64-apple-darwin13.4.0-ar"
CC="x86_64-apple-darwin13.4.0-clang"
CXX="x86_64-apple-darwin13.4.0-clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/zc/4r25vdyj4cv3ynjx64633ly40000gn/T/go-build3491450963=/tmp/go-build -gno-record-gcc-switches -fno-common"
Edit 2:
The test started working when I ran CGO_ENABLED=0 go test -v ./.... It returned the expected output.
=== RUN TestRacer
hello_test.go:13: got "http://www.facebook.com", want "http://www.quii.co.uk"
--- FAIL: TestRacer (2.52s)
FAIL
FAIL module 3.076s
FAIL
I'm still trying to understand why I need to add CGO_ENABLED=0 to for this particular test.
In my case it was R Studio installed through Anaconda package manager. After it was removed, the linker started working as expected.

Cannot install revel framework form Go

I tried to install Revel Framework. I followed all the steps as given in the documentation but whenever I tried to run the Revel command it throws panic error.
Following are the steps which I am performing
Enviormental path:
export GOROOT=/usr/local/go
export GOPATH=/Users/<username>/Desktop/gocode
export PATH="/Users/<username>/gocode/bin:$PATH"
To install Revel
go get github.com/revel/revel
go get github.com/revel/cmd/revel
export PATH="$PATH:$GOPATH/bin"
when I run revel version it shows:
panic: runtime error: slice bounds out of range
goroutine 1 [running]:
github.com/revel/cmd/model.(*CommandConfig).UpdateImportPath(0xc4200961c0, 0x20)
/Users/amitsharma/Desktop/gocode/src/github.com/revel/cmd/model/command_config.go:122 +0x907
main.main()
/Users/amitsharma/Desktop/gocode/src/github.com/revel/cmd/revel/revel.go:133 +0x243
When I run
revel run -a my-app
It shows
ERROR 19:34:59 harness.go:231: Could not start application error="revel/harness: app died reason: exit status 2"
INFO 19:34:59 watcher.go:272: Watcher: Recording error last build, setting rebuild on error="App failed to start up: revel/harness: app died reason: exit status 2"
INFO 19:34:59 watcher.go:277: Rebuilt, result error="App failed to start up: revel/harness: app died reason: exit status 2"
My go version
go version go1.10.3 darwin/amd64
My go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/amitsharma/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/<username>/Desktop/gocode"
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/0d/pkfrs5cj0v57xgsnwvb2kb580000gn/T/go-build028697826=/tmp/go-build -gno-record-gcc-switches -fno-common"
Try re-install the revel
Here is how I have tried and it works for me.
Set the go path ($GOPATH):
export GOPATH=/var/projects/go
Install revel & cmd:
go get github.com/revel/revel
go get github.com/revel/cmd/revel
Link revel cmd to bin directory. So the command could be executable.
export PATH="$PATH:$GOPATH/bin
Check revel is working or not. Just type revel in command line
Output would be like this
Usage:
revel [OPTIONS] <command>
Application Options:
-v, --debug If set the logger is set to verbose
--historic-run-mode If set the runmode is passed a string not json
-X, --build-flags= These flags will be used when building the application. May be specified multiple times, only applicable for Build, Run,
Package, Test commands
Available commands:
build
clean
new
package
run
test
version
Check revel version:
revel version
Output
Revel executing: displays the Revel Framework and Go version
Revel Framework : 0.21.0 (0.21.0 remote master branch)
Revel Cmd : 0.21.1 (0.21.1 remote master branch)
Revel Modules : 0.21.0 (0.21.0 remote master branch)
Now, You can create first project using command
revel new myapp
Output
Revel executing: create a skeleton Revel application
Your application has been created in:
/var/projects/go/src/myapp
You can run it with:
revel run -a myapp

Cannot find package within project directory

I've been trying to solve this problem for the past two hours. I cannot, for the life of me, understand how the folks who developed Go did such a fine job with the language but such a terrible job with package management.
Here is my go env output:
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/<me>/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/<me>/Documents/Proj/go"
GORACE=""
GOROOT="/usr/local/opt/go/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/z4/b3lxy_51405_b8pb_680l4xh0000gn/T/go-build063693521=/tmp/go-build -gno-record-gcc-switches -fno-common"
Notice that my GOPATH and GOROOT are set.
Here is the structure of my go workspace (/Users/<me>/Documents/Proj/go):
go/
|-bin/
|-pkg/
|-src/
|--github.com/
|--user/
|--myproject/
|--client/
|--client.go
|--main.go
Here is my client.go file:
// client.go
package client
type MyClient struct {}
this is my main.go file:
// main.go
package main
import "client"
func main() {}
When I run go build in the project root, I get this error:
main.go:4:2: cannot find package "client" in any of:
/usr/local/opt/go/libexec/src/transport (from $GOROOT)
/Users/<me>/Documents/Proj/go/src/transport (from $GOPATH)
The first time this happened, I tried to correct the path above:
// main.go
package main
import "github.com/user/myproject/client"
func main() {}
Then I got this error:
main.go:4:2: cannot find package "client" in any of:
/usr/local/opt/go/libexec/src/transport (from $GOROOT)
/Users/<me>/Documents/Proj/go/src/github.com/user/myproject/transport (from $GOPATH)
Which is bizarre, since the package exists at that exact path.
What am I doing wrong??
You should not import client but which path is coming from GOPATH/src, in this particular case github.com/user/myproject/client because that is your path.
I see that the way you describe your problem is not exactly the way it is on your computer. You replaced some things. That is understandable, you do not want to tell the world how your computer looks like. So you replaced your name with "<me>".
You also replaced the projectname, with MyProject in your question, that is also, just like the user name, a potential spot for an error which we cannot see, because you replaced it. Never use long names in development-paths on Windows, because Windows is doing dirty tricks with them, sometimes.
I am sure there is something the matter which is a problem. Try using your short-directory name in the go-path. Check this: https://superuser.com/questions/1182040/strange-short-path-name-on-windows

Go 'Can't Find Import'

I'm attempting to incorporate Heroku's log-shuttle library (https://github.com/heroku/log-shuttle) into a Go project I'm working on. The tool is primarily designed to be run as an independent binary, but I'm hoping to integrate it in a different way in my tool.
So I get the library:
$ go get github.com/heroku/log-shuttle
$ ls $GOPATH/src/github.com/heroku/log-shuttle/
batcher.go Godeps ...
...
which returns successfully. Then I try to import the library:
package myPackage
import (
"github.com/heroku/log-shuttle"
"fmt"
"log"
)
...
Great. But now I go to go build and...
$ go build
# github.com/<my project>
logWriter/log_shuttle_writer.go:5: can't find import: "github.com/heroku/log-shuttle"
I have my GOPATH set correctly (I believe):
$ go env
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/jeff/go/"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
TERM="dumb"
CC="gcc"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
CXX="g++"
CGO_ENABLED="1"
And the package is installed and built, but it doesn't want to import. As you can see, there are non non-ASCII chars in the package path (though the hyphen is non-alpha-numeric), and I can't find any more info about what could be causing this problem.
Not sure how it would matter, but I am using godep to try to manage my dependencies.
Thanks in advance.
github.com/heroku/log-shuttle is a main package, not an importable library, meaning it's meant to be compiled and run as a binary.

Resources