Go is the world’s leading programming language for cloud-based development, used by millions of developers to build and scale their cloud applications and business-critical cloud infrastructure. Whether it’s building CLIs, web applications, or cloud and network services, developers find Go easy to learn, easy to maintain, and packed with useful features such as built in concurrency and a robust standard library.
And now, getting started with Go on Google Cloud is a little bit easier. Following Go’s recent announcement of gonew, an experimental tool for instantiating new projects in Go from predefined templates, Google Cloud is releasing four templates for gonew that developers can use to bootstrap their Go applications across several Google Cloud products. This includes common use cases such as creating a simple HTTP handler Cloud Function, subscribing to a Cloud Pub/Sub topic, or creating an HTTP Server on Cloud Run.
From our partners:
Google Cloud Go templates
- httpfn: A basic HTTP handler (Cloud Function)
- pubsubfn: A function that is subscribed to a PubSub topic handling a Cloud Event (Cloud Function)
- microservice: An HTTP server that can can be deployed to a serverless runtime (Cloud Run)
- taskhandler: An basic app that handles tasks from requests (App Engine)
Let’s get started
- Make sure you have Go installed on your machine, if not you need to download/install from here .
- Start by installing gonew using go install:
$ go install golang.org/x/tools/cmd/gonew@latest
To generate a basic HTTP Handler Cloud Function, instantiate the existing httpfn template by running gonew in your new project’s parent directory. As of now, gonew’s syntax expects two arguments: first, the path to the template you wish to invoke, and second, the module name of the project you are creating. For example:
$ gonew github.com/GoogleCloudPlatform/go-templates/functions/httpfn yourdomain.com/httpfn
- Deploy this new go module to Cloud Functions by following the steps listed here, you can also try this in the Cloud Shell editor.
We have big plans for Go on Google Cloud, with several new enhancements on our roadmap. In the meantime, please try out these new templates, deploy them to Google Cloud using the instructions provided and let us know how we can make them better. Please use this to report any issues.
By: Prithpal Bhogill (Group Product Manager) and Cody Oss (Senior Software Engineer)
Originally published at: Google Cloud Blog