Trying to get Serverless Golang Example to work

Hey everyone,

I am following this tutorial: https://serverless.com/blog/framework-example-golang-lambda-support/
Upon executing the make command, I get this error:

dep ensure -v
make: dep: Command not found
Makefile:2: recipe for target 'build' failed
make: *** [build] Error 127

which go : /usr/lib/go-1.10//bin/go
go version: go version go1.10 linux/amd64
GOPATH="/home/anon/go"
GOROOT="/usr/lib/go-1.10"

I have installed dep using this command curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh from https://github.com/golang/dep

I googled the error message but did not find anything useful. All files are as is from the tutorial.

I am very new to Go in general and any input will be appreciated.

1 Like

I’m so sorry you ran into this issue, we should really improve that Makefile. In this case you’re missing the dep manager itself. If you pull down the binary first and then run make and it should work for you.

go get -v -u github.com/golang/dep/cmd/dep

Thanks for the reply,

I ran go get -v -u github.com/golang/dep/cmd/dep, and it executed without errors.
However running make on the tutorial repo resulted in the same error message

dep ensure -v
make: dep: Command not found
Makefile:2: recipe for target 'build' failed
make: *** [build] Error 127

The Makefile (which is untouched) is as follows:

build:
	dep ensure -v
	env GOOS=linux go build -ldflags="-s -w" -o bin/hello hello/main.go
	env GOOS=linux go build -ldflags="-s -w" -o bin/world world/main.go

.PHONY: clean
clean:
	rm -rf ./bin ./vendor Gopkg.lock

.PHONY: deploy
deploy: clean build
	sls deploy --verbose

Could you also clarify on the following?

I assume you meant running make on the tutorial repo but just wanted to double check.

It appears that dep is still not installed. Running dep status returns

dep: command not found

I ran both go get -v -u github.com/golang/dep/ and go get -v -u github.com/golang/dep/cmd/dep again but neither had any output.

All this is running inside a Ubuntu 16.04 LTS VirtualBox btw.

Hmm, this looks to be a GOPATH issue. Do you mind pasting here results from the following commands:

echo $GOPATH | tr ':' '\n'
which go
go version
which dep

For example…

[sborza@icebox]:~:$ echo $GOPATH | tr ':' '\n'
/home/sborza/.gvm/pkgsets/go1.10.4/global
/home/sborza/src/github.com/sebito91/stuffs/golang
/home/sborza/src/github.com/sebito91/challenges/exercism
/home/sborza/src/golang/go
/home/sborza
[sborza@icebox]:~:$ which go
~/.gvm/gos/go1.10.4/bin/go
[sborza@icebox]:~:$ go version
go version go1.10.4 linux/amd64
[sborza@icebox]:~:$ which dep
~/.gvm/pkgsets/go1.10.4/global/bin/dep

NOTE: I’m using gvm so my GOPATH values will be different, but make sure your Makefile is able to access the go binary and its libraries (https://golang.org/doc/install#testing)

anon@anon-virtualbox ~/go/src/helloWorld $ echo $GOPATH | tr ':' '\n'

anon@anon-virtualbox ~/go/src/helloWorld $ which go
/usr/lib/go-1.10//bin/go
anon@anon-virtualbox ~/go/src/helloWorld $ go version
go version go1.10 linux/amd64
anon@anon-virtualbox ~/go/src/helloWorld $ which dep

I tried following https://golang.org/doc/install#testing, but was not able to run the build.

The program 'hello' can be found in the following packages:
 * hello
 * hello-traditional
Try: sudo apt install <selected package>

running go env:

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/anon/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/anon/go"
GORACE=""
GOROOT="/usr/lib/go-1.10"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.10/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build916188744=/tmp/go-build -gno-record-gcc-switches"

Thanks for that post…so it looks like the GOPATH is off, note how it has nothing pasted out there! Can you please do the following in sequence and let me know how that works:

cd ~/go
export GOPATH=$(pwd)
echo $GOPATH
go get -v -u github.com/golang/dep/cmd/dep
which dep

If you notice that dep is somewhere within your GOPATH then you can try running the make again to see how that goes.

thats weird cos GOPATH shows up in go env
echo $GOPATH: /home/anon/go
which dep returns no output

my current go env:

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/anon/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/anon/go"
GORACE=""
GOROOT="/usr/lib/go-1.10"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.10/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build426522265=/tmp/go-build -gno-record-gcc-switches"

which go: /usr/lib/go-1.10//bin/go
this is different from what go env is saying, and note the double slashes. Is that to be expected?

The double-slash isn’t supposed to be there but it also should not impact anything. If you cd to your app folder now and run make, does it work?

okay, so looks like my base Go installation is not working. I edited my path settings to fix the double slash issue.

.profile:

PATH="$HOME/bin:$HOME/.local/bin:$PATH"
export PATH=$PATH:/usr/local/go/bin
export GOROOT=/usr/lib/go-1.10
export PATH=$PATH:$GOROOT/bin

go env:

OARCH="amd64"
GOBIN=""
GOCACHE="/home/anon/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/anon/go"
GORACE=""
GOROOT="/usr/lib/go-1.10"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.10/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build092148776=/tmp/go-build -gno-record-gcc-switches"

which go: /usr/lib/go-1.10/bin/go
which dep:

“Test your installation” from https://golang.org/doc/install#testing is still not working with the same error.
make in the serverless tutorial folder is still not working with the same error. =(

I may have missed this earlier but where did you download/install golang from?

I installed it a long time ago and I can’t recall really. This is the first time I’ve had to compile it, previously I just ran small tutorial snippets within my IDE.

Is there any guide to verify my Golang installation?

I would remove any and all traces of go from your VM and try once more following these instructions:

It’s the best default installation possible. If you want to mimic my setup using another golang manager, you can try the instructions here:

If all of that doesn’t work please send me an email to sebastian@serverless.com and I will try to replicate your env locally to help get you sorted!

okay will try that next, thanks for all your help Seb! this was quite beyond the scope of serverless haha

Of course, we’re happy to help! We’ll make sure to get you sorted, it’s pretty awesome when it’s all working. :slight_smile:

Just checking in to see how you were making out. Hope things are going super well now!