menu

ZEIT

Our mission is to make cloud computing as easy and accessible as mobile computing. You can find our Next.js community here.

Channels
Team

Golang Example: multi-route, multi-lambda with dependencies

January 6, 2019 at 6:44pm

Golang Example: multi-route, multi-lambda with dependencies

January 6, 2019 at 6:44pm (Edited 8 months ago)

https://github.com/torbensky/go-zeit-now

Example of

  • using dep to vendor dependencies
  • building multiple Go lambdas
  • routing to multiple lambdas

Note: One minor annoyance is my IDE (VSC) gives me errors for not having a func main() declared in those main packages:

runtime.main_main·f: function main is undeclared in the main package

But if you include a main method to resolve that error it breaks the now builder. I haven't looked into @now/go builder, but I suspect it's basically gluing in a shim with a main() method from the looks of the errors.

  • UPDATE: I updated the example repo so the IDE error is no longer an issue. Just put a func main(){} in a non-lambda .go file that is also in package main.

January 6, 2019 at 10:33pm

For Zeit, my wishlist is:

- Update https://zeit.co/docs/v2/deployments/official-builders/go-now-go/ with more details about how the builder works. It seems to require a lambda to be in a main package.

- It would be nice if go lambdas didn't need to be in the main package (this would supercede the previous point)

- now support to run dev mode and fire up all the lambdas ;)

Edited
  • reply
  • like

February 11, 2019 at 12:45pm

Hi, @torbensky, I tried your solution, but the deployment failed, saying there is no lambda function in main.go.

  • reply
  • like

Hi @thezjy if you can share more info about what your project looks like I might be able to help you.

Also, have a look at: https://spectrum.chat/?t=258de71b-da9c-47df-a335-658e748411de

It's an alternative Now 2.0 builder for Golang that I made. Have you tried it? I found the Zeit provided builder had a lot of issues for me.

  • reply
  • like