Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Google Makes it Easier to Create Go Applications on Google Cloud

Google Makes it Easier to Create Go Applications on Google Cloud

Google released four templates developers can use to bootstrap Go applications using gonew, an experimental tool aimed at instantiating Go projects.

The new templates include httpfn, which creates a basic HTTP handler using Cloud Function; pubsubfn, a Cloud Function that is subscribed to a PubSub topic handling a Cloud Event; [microservice(], a Cloud Run HTTP server meant to be deployed to a serverless runtime; and taskhandler, which is a basic app handling tasks using App Engine.

Using a template simplifies the process of writing a Go service and deploying it to Google Cloud. Each template includes a basic Go program implementing the required functionality and a dependency file. More complex services may include additional configuration files, such as yaml files to configure Cloud services.

For example, in the case of a simple HTTP handler, if you use the httpfs gonew template, once you have gonew installed, the whole process comes down to two steps: downloading the project template and deploying it.

gonew your.domain/httpfn

gcloud functions deploy hello-http \
--gen2 \
--runtime=go120 \
--region=us-central1 \
--source=. \
--entry-point=HelloHTTP \
--trigger-http \

Compare this with the steps required to write a simple Cloud Function using the Go runtime to accomplish the same goal. Those include creating a Google Cloud project using gcloud CLI, implementing the required functionality writing a simple Go program, then deploying it. The benefits are even more evident if you look at the steps required to create a simple task handler using Google App Engine.

As mentioned, the Go templates leverage the recently introduced gonew tool, which aims to simplify the task of bootstrapping a Go project.

For a long time now, we have heard from Go developers that getting started is often the hardest part. New developers coming from other languages expect guidance on a default project layout, experienced developers working on teams expect consistency in their projects’ dependencies.

Templates for gonew, which are packaged as Go modules, can be written by anyone. The initial release of the tool is intentionally minimal and aimed to gather feedback from the developer base.

About the Author

Rate this Article