A Go App Engine application can be configured by a file named
app.yaml
that specifies how URL paths correspond to request handlers and static files.
It also contains information about the application code, such as the application ID and the latest version identifier.
Note: If you created your project using the Google Developers Console , your project has a title and an ID. In the instructions that follow, the project title and ID can be used wherever an application title and ID are mentioned. They are the same thing.
-
About
app.yaml
- Required elements
- Script handlers
- Static file handlers
- Includes
- Secure URLs
- Requiring login or administrator status
- Skipping files
- Reserved URLs
- Inbound services
- Warmup requests
- Administration console custom pages
- Custom error responses
- Custom PageSpeed configuration
- Auto ID policy
About
app.yaml
A Go app specifies runtime configuration, including versions and URLs, in a file named
app.yaml
. The following is an example of an
app.yaml
file for a Go application:
application: myapp version: 1 runtime: go api_version: go1 handlers: - url: /stylesheets static_dir: stylesheets - url: /(.*\.(gif|png|jpg))$ static_files: static/\1 upload: static/.*\.(gif|png|jpg)$ - url: /.* script: _go_app
The syntax of
app.yaml
is the YAML format. For more information about this syntax, see
the YAML website
.
The YAML format supports comments. A line that begins with a pound (
#
) character is ignored:
# This is a comment.
URL and file path patterns use
POSIX extended regular expression syntax
, excluding collating elements and collation classes. Back-references to grouped matches (e.g.
\1
) are supported, as are these Perl extensions:
\w \W \s \S \d \D
Required elements
An
app.yaml
file must include one of each of the following elements:
application
The application identifier. This is the identifier you selected when you created the application in the Google Developers Console .
application: myapp
version
A version specifier for the application code. App Engine retains a copy of your application for each version used. An administrator can change which major version of the application is default using the
Google Developers Console
, and can test non-default versions before making them default. (The default version is loaded when no version is specified or an invalid version is specified.) The version specifier can contain lowercase letters, digits, and hyphens. It cannot begin with the prefix
ah-
and the names
default
and
latest
are reserved and cannot be used. Each version of an application retains its own copy of
app.yaml
. When an application is uploaded, the version mentioned in the
app.yaml
file being uploaded is the version that gets created or replaced by the upload.
version: 2-0-test
runtime
The name of the App Engine runtime environment used by this application. To specify Go, use go. Other runtimes are available; please refer to the runtime's documentation for more info. Other JVM languages can customize
app.yaml
based on the specified runtime.
runtime: go
handlers
A list of URL patterns and descriptions of how they should be handled. App Engine can handle URLs by executing application code, or by serving static files uploaded with the code, such as images, CSS or JavaScript. Patterns are evaluated in the order they appear in the
app.yaml
, from top to bottom. The first mapping whose pattern matches the URL is the one used to handle the request.
There are two kinds of handlers: script handlers, and static file handlers. A script handler runs a Go script in your application to determine the response for the given URL. A static file handler returns the contents of a file, such as an image, as the response. See Script Handlers and Handlers for Static Files below for more information on this value.
handlers: - url: /images static_dir: static/images - url: /.* script: _go_app
Notice that you can specify a handler in either of two ways:
-
Directly under the
handlers:
element, as shown above. -
Indirectly in
.yaml
files that are included under theincludes:
element.
The following example shows included
.yaml
files, with handlers defined there instead of inside the
app.yaml
file that includes those other
.yaml
files:
includes: - cloud_endpoints.yaml - web_interface.yaml - admin_interface.yaml
The included
.yaml
files would have the handlers directly defined under
handlers:
element.
api_version
The version of the API in the given runtime environment used by this application. When Google releases a new version of a runtime environment's API, your application will continue to use the one for which it was written. To upgrade your application to the new API, you change this value and upload the upgraded code.
At this time, App Engine has one version of the
go
runtime environment:
go1
api_version: go1