1

I'm just getting starting with Golang and Serverless. I've basically gone through these steps on MacOS:

  1. brew install golang
  2. brew install dep
  3. npm install -g serverless
  4. mkdir ~/Projects/testproject
  5. Added export GOPATH="$GOPATH:~/Projects/testproject" to ~/.profile
  6. serverless create -t aws-go-dep -p myservice within the testprojects folder
  7. Run make and get this weird error:
unable to create lock pkg/dep/sm.lock: Lockfiles must be given as absolute path names
make: *** [build] Error 1

Not sure what I'm doing wrong. Also I followed the blog article for getting setup with the example: https://serverless.com/blog/framework-example-golang-lambda-support/

According to go env my path is: GOPATH=":/Users/ddibiase-macbook/go:/Users/ddibiase-macbook/Projects/centive/api"

There isn't much helpful documentation online to get through this :-/

3 Answers 3

2

To resolve the issue, I ended up giving up on creating a custom workspace and just making my GOPATH point to one consistent folder. GOROOT was pointed to /usr/local/opt/go/libexec (seems to be where Brew installs Go).

Small rant: Go's setup experience is terrible. I get the fact that it's meant to have opinions, but something as simple as workspace placement and setting up paths...this should be taken care of by the installation process and make clearer to the developer installing the build tools. Booo!

Sign up to request clarification or add additional context in comments.

Comments

0

This documentation can help you to set up Go specific development environment.

In short, you need to set two variables - GOPATH & GOROOT.

Here is what your .profile should look like ...

# this is mac os specific

export GOPATH=$HOME/Projects

# set goroot
export GOROOT=/usr/local/opt/go/libexec

# set path
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:$GOROOT/bin

2 Comments

Will that however push go dependencies into my projects folder? I have a number of non-Go projects in that Projects folder. What I’m attempting to do is have a Go base where dependencies are installed then setup workspaces for each project as needed. Does that make much sense?
GOPATH is relative and should help resolve dependencies for exported paths. Have one workspace and point the gopath to it. Git clone as many projects as you want under the workspace. Any standard dependency manager can pick up from there (like dep).
0

You can make a symlink within $GOPATH/src/github.com/* and point it to your existing project directory.

Create the symlink:

~ >> ln -s $HOME/code/example-project $GOPATH/src/github.com/example-project

Verify it worked

~/go/src/github.com >> ls -l
total 0
drwxr-xr-x  3 trex  staff  96 Feb  9 10:20 google
lrwxr-xr-x  1 trex  staff  30 Feb  9 15:58 example-project -> /Users/trex/code/example-project

Now you can go about your business in the example-project with things like

~ code/example-project >> make 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.