Quickstart for Go App Engine Standard Environment

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

Before you begin

Before running this sample, you must install the App Engine SDK for Go:

Download the SDK

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.

  1. Clone the Hello World sample app repository to your local machine in a directory called helloworld:

    git clone -b part1-helloworld https://github.com/GoogleCloudPlatform/appengine-guestbook-go.git helloworld
    
  2. Then go to the directory that contains the sample code:

    cd helloworld
    

Alternatively, you can download the sample as a zip file and extract it into a directory called helloworld.

Test the application

Test the application using the development web server, which is included with the App Engine SDK.

  1. Run the following command, providing the path to the helloworld directory, to compile your app and start the development web server:

    /path/to/go_appengine/goapp serve helloworld/
    

    You can omit the /path/to/go_appengine/ if you added the directory from the Go App Engine SDK to your PATH environment variable. You can also omit the directory name (helloworld) if this is your current directory.

    The web server is now running, listening for requests on port 8080.

  2. Visit http://localhost:8080/ in your web browser to see the app in action.

For more information about running the development web server, see the Go Development Server reference, or run goapp help serve.

Make a change

The development app server watches for changes in your project files. As you update your source, it recompiles them and relaunches your local app. There's no need to restart goapp.

  1. Try it now: leave the web server running, then edit hello.go to change Hello, world! to something else.
  2. Reload http://localhost:8080/ to see the change.

Deploy your app

To deploy your app to App Engine, you will need to register a project to create your project ID, which will determine the URL for the app.

  1. In the Cloud Platform Console, go to the Projects page and select or create a new project.

    Go to the Projects page

  2. Note the project ID that you created above.
  3. Upload your application to Google App Engine by invoking the following command. This opens a browser window for you to sign in using your Google account. You'll be providing the project ID as the argument for -A. Use the -V argument to specify a version name.
    appcfg.py -A <YOUR_PROJECT_ID> -V v1 update myapp/
  4. Your app is now deployed and ready to serve traffic at http://<YOUR_PROJECT_ID>.appspot.com/.

Congratulations! You have completed this quickstart.

Clean up

To avoid incurring charges to your Google Cloud Platform account for the resources used in this quickstart:

  1. Go to the Cloud Platform Console.
  2. Click the trash can icon next to the project you want to shut down: this schedules the project for deletion.

What's next

Hello World code review

Hello World is the simplest possible App Engine app: it contains only one module, has only one version, and all of the code is located within the app's root directory. This section describes each of the app files in detail.

This Go package responds to any request by sending a response containing the message Hello, world!.

package hello

import (
    "fmt"
    "net/http"
)

func init() {
    http.HandleFunc("/", handler)
}

func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprint(w, "Hello, world!")
}

app.yaml

The app.yaml configuration file tells the App Engine service which runtime to use and which URLs should be handled by our Go program.

runtime: go
api_version: go1

handlers:
- url: /.*
  script: _go_app

From top to bottom, this configuration file says the following about this application:

  • This code runs in the go runtime environment, with API version go1.
  • Every request to a URL whose path matches the regular expression /.* (all URLs) should be handled by the Go program. The _go_app value is a magic string recognized by the development web server; it is ignored by the production App Engine servers.

The syntax of this file is YAML. For a complete list of configuration options, see the Go Application Configuration page.

Learn the whole platform

Now that you know what it's like to develop and deploy App Engine apps, you can stretch out and see the rest of Google Cloud Platform. For a guided walkthrough that teaches you how to create an application that uses the entire platform, not just App Engine, check out our "Creating a Guestbook" quickstart in which you expand this simple application to become a fully-fledged Guestbook application that lets authenticated Google accounts post messages to a public page.

Learn more about App Engine standard environment

Here are some topics to help you to continue learning about App Engine.

Send feedback about...

App Engine standard environment for Go