JBD from Google engineering team shared this guide and experiences how to migrate services to Google Cloud Functions (GFC)for golang.
The article provides reader with example of simple “hello world” to introduce the overall build and deploy experience with GFC. GCF expects an http.HandlerFunc to be the entry point.
In Go, we organize packages by responsibility. This also fits well with serverless design patterns – a function is representing one responsibility.
The article explains how:
- How to create and package dependencies
- How to organize the code
- How to chain handler (to utilize existing middlewares)
- How to (automatically) create traces for incoming HTTP requests
If you have external dependencies, you have to vendor them under the library package. This is possible by any vendoring tool. The dependency is vendored locally and function can be redeploy afterwards again.
Author recommends to create a new module for each function, provide function-specific other APIs from the same module. Common functionality lives in a separate module and vendored on the function package because GCF CLI uploads and deploys only one module at a time.
To learn more read that brief tutorial in whole!
[Read More]