The Go Development Server

The Google Cloud SDK and App Engine SDK for
Go
each include a local development server that you can run locally to simulate
your application running in production App Engine. The simulated environment
enforces some sandbox restrictions, such as restricted system functions and
Go module imports, but not others, like request time-outs or
quotas.

The local development server also simulates the services provided by the
libraries in the SDK for App Engine, including Datastore, Memcache, and Task
Queues, by performing their tasks locally. Note that when your application is
running in the development server, you can still make remote API calls to the
production infrastructure using Google APIs HTTP endpoints.

Running the local development server

After you create the
app.yaml
configuration file for your app, you can start the local development server with
the dev_appserver.py command to run your app locally.

Note:dev_appserver.py does not run in the App Engine flexible
environment.

To start the local development server:

Running the local development server (dev_appserver.py)

To run the local development server, you can either run dev_appserver.py by
specifying the full directory path or you can add dev_appserver.py to your
PATH environment variable:

If you installed the App Engine SDK, the tool is located at
[PATH_TO_APP_ENGINE_SDK]/dev_appserver.py.

If you installed the Google Cloud SDK, the tool is located at
[PATH_TO_CLOUD_SDK]/google-cloud-sdk/bin/dev_appserver.py.

Tip: To add the Google Cloud SDK tools to your PATH and enable
command-completion in your bash shell, you can run:

[PATH_TO_CLOUD_SDK]/google-cloud-sdk/install.sh

Run the dev_appserver.py command as follows from the directory
that contains your app's app.yaml configuration file:
dev_appserver.py

Specify the directory path to your app, for example:

dev_appserver.py [PATH_TO_YOUR_APP]

Alternatively, you can specify the configuration file of a specific
service, for example:

dev_appserver.py app.yaml

To change the port, you include the --port option:

dev_appserver.py --port=9999 [PATH_TO_YOUR_APP]

goapp serve

The goapp serve command is included with the original
App Engine SDK for Go and wraps the underlying
dev_appserver.py Python tool. To start the local
development server, you run:

goapp serve

Tip: Using the Python tool directly as dev_appserver.py
provides you with greater control over the local development server.

The local development server is now running and listening for requests. You
can visit http://localhost:8080/ in your
web browser to see the app in action.

If you specified a custom port with the --port option, remember
to open your browser to that port.

To stop the local server from the command line, you press the following:

Mac OS X or Linux: Control-C

Windows: Control-Break

Specifying application IDs

If you want to use application IDs with the local development server, don't use
the App ID from the APPLICATION_ID environment variable. The development
server differs from production App Engine service in that the local server
prepends the string dev~ to the APPLICATION_ID environment variable.

Detecting application runtime environment

To determine whether your code is running in production or in the local
development server, you can call the
IsDevAppServer()
method. When this is true, your code is running in the local development
environment; otherwise, you're running in production.

Specifying the ID allocation policy

Although the auto ID assignment policies for the production server are
completely different than those used by the development server, you can also set
the automatic ID allocation policy for the local server.

To specify the automatic ID assignment policy, use the --auto_id_policy
option:

dev_appserver.py --auto_id_policy=sequential

where --auto_id_policy can be one of the following:

scattered: (default) IDs are assigned from a non-repeating sequence of
approximately uniformly distributed integers.

sequential: IDs are assigned from the sequence of consecutive integers.

Note: Your app should make no assumptions about the sequence of automatic IDs
assigned in production. .

Clearing the local Datastore

To clear the local datastore for an application, invoke the local development
server as follows:

dev_appserver.py --clear_datastore=yes app.yaml

Changing local Datastore location

To change the location used for the datastore file, use the --datastore_path
option:

dev_appserver.py --datastore_path=/tmp/myapp_datastore app.yaml

Using the Users service

App Engine provides a
Users Service to simplify
authentication and authorization for your application. The local development
server simulates the behavior of Google
Accounts
with its own sign-in and sign-out pages. While running under the local
development server, the
LoginURL and
LogoutURL
functions return URLs for /_ah/login and /_ah/logout on the local server.

Using Mail

The local development server can send email for calls to the App Engine mail
service using either an SMTP server or a local installation of
Sendmail.

Using SMTP

To enable mail support with an SMTP server, invoke dev_appserver.py as
follows::

where you set the --smtp_host, --smtp_port, --smtp_user and
--smtp_password options with your own values.

Using Sendmail

To enable mail support with Sendmail, invoke dev_appserver.py as follows:

dev_appserver.py --enable_sendmail=yes [PATH_TO_YOUR_APP]

The local server will use the sendmail command to send email messages with
your installation's default configuration.

Note: If you don't invoke dev_appserver.py with either SMTP or Sendmail as
described, then attempts to send email from your application will do
nothing, but the attempt will appear successful in your application.

Using URL Fetch

When your application uses the URL fetch API to make an HTTP request, the
local development server makes the request directly from your computer. The
URL Fetch behavior on the local server may differ from production App Engine if
you use a proxy server for accessing websites.