"[Quickstart] For Go in the App Engine Flexible Environment"

Published: Mon 11 July 2016

In content.

This quickstart shows you how to create a small App Engine application that displays a short message.

Before you begin

Before running this sample, take the following steps:

This quickstart assumes that you are familiar with the Go programming language and that you have installed Go.

Download the Hello World app

We've created a simple Hello World app for Go so you can quickly get a feel for deploying an app to Google Cloud Platform. Follow these steps to download Hello World to your local machine.

Download the sample app and navigate into the app directory:

  • 1) Get the Hello World sample app and its dependencies:

[code lang=text] go get -u -d github.com/GoogleCloudPlatform/golang-samples/docs/managed_vms/helloworld [/code]

  • 2) Change to the directory that contains the sample code:

[code lang=text] cd $GOPATH/src/github.com/GoogleCloudPlatform/golang-samples/docs/managed_vms/helloworld [/code]

Run Hello World on your local machine

To run the Hello World app on your local computer:

  • 1) Start a local web server: go run helloworld.go

  • 2) In your web browser, enter the following address: http://localhost:8080

You can see the Hello World message from the sample app displayed in the page. In your terminal window, press Ctrl+C to exit the web server.

Deploy and run Hello World on App Engine

To deploy your app to the App Engine flexible environment, you need to have a Google Cloud Platform Console project.

Create a project in the Google Cloud Platform Console.

  • 1) In the Cloud Platform Console, go to the Projects page and select or create a new project. GO TO THE PROJECTS PAGE

  • 2) Enable billing for your project. ENABLE BILLING

  • 3) Note the Project ID, since it is used for configuration and deployment.

Deploy the app to App Engine

  • 1) Deploy the Hello World Go app. Use the aedeploy tool, which will correctly assemble an app's dependencies in the same way that the go tool does.

    • a) Install the aedeploy tool: go get google.golang.org/appengine/cmd/aedeploy

    • b) Deploy your app by prefixing a gcloud app deploy command with aedeploy. aedeploy gcloud preview app deploy

This time, the page that displays the Hello World message is delivered by a web server running on an App Engine instance.

Congratulations! You've deployed your first Go app to App Engine flexible environment!

To view your application in the web browser run: gcloud app browse

You can read logs from the command line by running: gcloud app logs read

social