In this post, you’ll learn about the open-source Go Functions Framework that enables you to develop Golang Google Cloud Functions on your computer and deploy them to the cloud.
So why is the Go Functions Framework important? Well, it enables…
- 💻 Local testing of your Google Cloud Functions in Go
- 🔢 Transparent versioning of your application code on Google Cloud
- 🌐 Write once, run anywhere: Cloud Functions, Cloud Run, other Clouds
Personally, I really like how I can easily use
localhost to test my functions.
Set up Your Environment
Before we begin, let’s first ensure we’re running on the same environment. Print your go version with this command:
The output should be Go 1.11 or higher. If not, update Go by uninstalling and re-installing Go: https://golang.org/dl/
Then, let’s create a new directory for our function called
mkdir -p hello/cmd
Create a Go module:
go mod init example.com/hello
function.go file with the following contents (any package name):
Create a folder
cmd with a file
cmd/main.go with the following contents for our
This file uses the Go Functions Framework to start our function.
Test your function locally using the following command:
go run cmd/main.go
Your Google Cloud Function is now running locally. You can curl your function to invoke your function:
You’ll see the output:
Hello, Functions Framework!
Deploying to Google Cloud Functions
To deploy to Google Cloud Functions, run the following command:
gcloud functions deploy HelloWorld --runtime go111 --trigger-http
After ~2 minutes, you’ll see the URL look something like this:
You can invoke the function by going to your URL.
From the command-line, this script will get the URL and
curl your function:
curl $(gcloud functions describe HelloWorld --format 'value(httpsTrigger.url)')
You just went from testing your Go function on your computer to deploying to Google Cloud which can theoretically scale to 100,000,000 reqs per 100 seconds (🔗).
If you want to follow updates, or learn more, check out the GitHub repo: https://github.com/GoogleCloudPlatform/functions-framework-go
Thanks for Reading
You might also be interested in this blogpost and video: