Jump to Content
Application Development

Get Go-ing with Cloud Functions: Go 1.11 is now a supported language

January 16, 2019
Eno Compton

Senior Software Engineer, Google Cloud

Stewart Reichling

Product Manager, Traffic Director

Since releasing Node.js and Python as supported languages for Google Cloud Functions this summer, our team has been hard at work. Today, we're excited to announce support for Go on Cloud Functions.

Now in beta, the runtime uses the latest version, Go 1.11, which includes new language features like modules for integrating third-party dependencies into your code. Starting today, you can write Go functions that scale dynamically in response to load and integrate seamlessly with Google Cloud events.

Two ways to Go

Let’s take a look at the two types of functions that you can use with Cloud Functions: HTTP functions and background functions.

HTTP functions are what their name suggests: functions that are invoked by HTTP requests. They follow the http.HandlerFunc type from the standard library. For example, an HTTP function that returns a caller’s IP address might look like this:

Loading...

HTTP functions can be reached without an additional API gateway layer—Cloud Functions gives you an HTTPS URL. After the function is deployed, you can invoke the function by entering the URL into your browser.


In contrast, background functions are triggered in response to an event. Your function might, for example, run every time the contents of a Cloud Storage bucket change. Let’s look at an example function that triggers when a file is added to a Cloud Storage bucket:
Loading...

When you deploy your function, you also indicate a specific Cloud Storage bucket. Every time a new file appears in that bucket, your function runs and logs the file's name.


These are just two small examples of what’s possible with Cloud Functions and Go. The runtime supports a rich ecosystem of Go packages via Go modules. For example, to use the Cloud Translation client library in your function, create a `go.mod` file by running the following commands:
Loading...

When you deploy your function, Cloud Functions fetches and installs the dependencies listed in your `go.mod` file.


Using Cloud Functions, you can build serverless application backends, real-time data processing pipelines, chatbots, and video or image analysis tools, just to name a few. Now, you can also use the familiar building blocks of Go to build out your Cloud Functions.


We're continuously making improvements to Cloud Functions. For instance, environment variables are now generally available and we added new IAM security controls. We hope you're excited to try the Go runtime. To get started, check out the Go quickstart.
Video Thumbnail
Posted in