The application config file is at conf/app.conf relative to your app root. Ituses the syntax accepted by revel/configwhich is similar to INI files. We’llcover the general structure here. See comprehensive keys fora list of all built-in config keys and their values.

Example

Two sections, dev (develop) and prod (production):

  1. app.name = myapp
  2. app.secret = pJLzyoiDe17L36mytqC912j81PfTiolHm1veQK6Grn1En3YFdB5lvEHVTwFEaWvj
  3. http.addr =
  4. http.port = 9000
  5. my_stuff.foo = 1234
  6. my_stuff.bar = Sheebang!
  7. # Development settings
  8. [dev]
  9. results.pretty = true
  10. watch = true
  11. http.addr = 192.168.1.2
  12. log.trace.output = off
  13. log.info.output = stderr
  14. log.warn.output = stderr
  15. log.error.output = stderr
  16. # Production settings
  17. [prod]
  18. results.pretty = false
  19. watch = false
  20. http.port = 9999
  21. log.trace.output = off
  22. log.info.output = off
  23. log.warn.output = %(app.name)s.log
  24. log.error.output = %(app.name)s.log

Config values can be accesed via the revel.Config variable, more below

  1. driver:=revel.Config.StringDefault("db.driver","mysql")ena:=revel.Config.BoolDefault("myapp.remote.enabled",false)

Run Modes

Each section is a Run Mode and selected with the revel run command, eg.

  1. revel run bitbucket.org/mycorp/my-app dev
  • The keys at the top level (eg app, http) are not within any [section] and apply to all run modes (ie default).
  • This allows values to be overridden (or introduced) as required in each run mode [section].
  • Also not in the example above, keys under the [prod] section applies only to prod mode.
  • The run mode is chosen at runtime by the argument provided to the revel run. eg:
    • revel run my-app - will start in dev mode as the default
    • revel run my-app prod - will start with prod mode.
      Revel creates new apps with dev and prod run modes defined, but the developer maycreate any sections they wish.

Environment variables

Besides static configuration, Revel also supports dynamic configuration by injectingenvironment variables or the value of other parameters.

In most cases, you’ll want to load sensitive values from environment variablesrather than storing them in your configuration file. The syntax for including anenvironment variable is similar to the shell syntax: ${ENV_VAR_NAME}.

Example

  1. app.name = chat
  2. http.port = 9000
  3. db.driver = ${CHAT_DB_DRIVER}
  4. db.spec = ${CHAT_DB_SPEC}

Revel will then load the CHAT_DB_DRIVER and CHAT_DB_SPEC environment variablesand inject them into the config at runtime.

Composing other parameters

To incorporate the value of one parameter into another, you can “unfold” it by usingthe %(var_name)s syntax (note the ‘s’ at the end).

Example

  1. app.name = chat
  2. http.port = 9000
  3. log.warn.output = %(app.name)s.log
  4. log.error.output = %(app.name)s.log

Will be parsed by revel/config as:

  1. app.name=chat
  2. http.port=9000
  3. log.warn.output = chat.log
  4. log.error.output = chat.log

Custom properties

The developer may define custom keys and access them via therevel.Config variable, which exposes asimple api.

Example

In your app.conf:

  1. myapp.remote = 120.2.3.5
  2. myapp.remote.enabled = true

In your Go code:

  1. varremoteServerstringifrevel.Config.BoolDefault("myapp.remote.enabled",false){remoteServer=revel.Config.StringDefault("myapp.remote","0.0.0.0")DoSomethingTo(remoteServer)}

External app.conf

Since v0.13, Revel has supported loading a external app.conf from a givendirectory. It’s a convenient way to override or add config values to theapplication. Please make sure app.conf is in the given path.

Example

  1. age:funcinit(){revel.ConfPaths=[]string{"/etc/myapp/conf"}}

Built-in properties

Application settings

app.name

The human-readable application name. This is used for some console output anddevelopment web pages.

Example

  1. app.name = Booking example application

Default: Auto Generated For example: github.com/myaccount/myrevelapp, app.name = myrevelapp

app.secret

The secret key used for cryptographic operations, see revel.Sign.

  • Revel also uses it internally to sign session cookies.
  • Setting it to empty string disables signing and is not recommended.
  • It is set to a random string when initializing a new project with revel new

    Example

  1. app.secret = pJLzyoiDe17L36mytqC912j81PfTiolHm1veQK6Grn1En3YFdB5lvEHVTwFEaWvj

Default: Auto Generated random seed value

app.behind.proxy

If true Revel will resolve client IP address from HTTP headers X-Forwarded-For and X-Real-Ip in the order. By default Revel will get client IP address from http.Request’s RemoteAddr. Set to true if Revel application is running behind the proxy server like nginx, haproxy, etc.

Example

  1. app.behind.proxy = true

Default: false

HTTP settings

http.port

The port to listen on.

Example:

  1. http.port = 9000

http.addr

The IP address on which to listen.

  • On Linux, an address of 0.0.0.0 will listen on all interfaces assigned to the host
  • on Windows, an empty string is silently converted to "localhost"
  • An empty string is converted to localhost for security reasons.
    Default: “localhost”

harness.port

Specifies the port for the application to listen on, when run by the harness.For example, when the harness is running, it will listen on http.port, run theapplication on harness.port, and reverse-proxy requests. Without the harness,the application listens on http.port directly.

By default, a random free port will be chosen. This is only necessary to setwhen running in an environment that restricts socket access by the program.

Default: 0

http.ssl

If true, Revel’s web server will configure itself to accept SSL connections. Thisrequires an X509 certificate and a key file.

Default: false

http.sslcert

Specifies the path to an X509 certificate file.

Default: “”

http.sslkey

Specifies the path to an X509 certificate key.

Default: “”

http.timeout.read

Read timeout specifies a time limit for http.Server.ReadTimeout in secondsmade by a single client. A Timeout of zero means no timeout.

Example

  1. http.timeout.read = 300

Default: 90

http.timeout.write

Write timeout specifies a time limit for http.Server.WriteTimeout in secondsmade by a single client. A Timeout of zero means no timeout.

Example

  1. http.timeout.write = 120

Default: 60

Results

results.chunked

Determines whether the template rendering should usechunked encoding. Chunkedencoding can decrease the time to first byte on the client side by sending databefore the entire template has been fully rendered.

Default: false

results.pretty

Configures RenderXML and RenderJSON to produce indented XML/JSON.

Example

  1. results.pretty = true

Default: false

Internationalization

i18n.default_language

Specifies the default language for messages when the requested locale is notrecognized. If left unspecified, a dummy message is returned to those requests.

Example

  1. i18n.default_language = en

Default: “”

Specifies the name of the cookie used to store the user’s locale.

Default: %(cookie.prefix)_LANG (see cookie.prefix)

Watch

Revel watches your project and supports hot-reload for a number of types ofsource. To enable watching:

  1. watch = true

If false, nothing will be watched, regardless of the other watch.*configuration keys. (This is appropriate for production deployments)

Default: true

watch.mode

  • If watch.mode = "eager", the server starts to recompile the application every time the application’s files change.
  • If watch.mode = "normal", the server recompiles with a request eg a browser refresh.
    Default: "normal"

watch.templates

If true, Revel will watch the views/ template directory (and sub-directories) for changes and reload them as necessary.

Default: true

watch.routes

If true, Revel will watch the app/routes file for changes and reload as necessary.

Default: false

watch.code

If true, Revel will watch the Go code for changes and rebuild your applicationas necessary. This runs the harness as a reverse-proxy to the application.

All code within the application’s app/ directory, or any sub-directory is watched.

Default: true

Cookies

Revel components use the following cookies by default:

  • REVEL_SESSION
  • REVEL_LANG
  • REVEL_FLASH
  • REVEL_ERRORS

Revel uses this property as the prefix for the Revel-produced cookies. This isso that multiple REVEL applications can coexist on the same host.

Example

  1. cookie.prefix = MY

would result in the following cookie names:

  • MY_SESSION
  • MY_LANG
  • MY_FLASH
  • MY_ERRORS
    Default: REVEL

A secure cookie has the secure attribute enabled and is only used via HTTPS,ensuring that the cookie is always encrypted when transmitting from client toserver. This makes the cookie less likely to be exposed to cookie theft viaeavesdropping.

  1. cookie.secure = false

Default: false in dev mode, otherwise true

Session

session.expires

Revel uses this property to set the expiration of the session cookie.Revel uses ParseDuration to parse the string.The default value is 30 days. It can also be set to "session" to allow session onlyexpiry. Please note that the client behaviour is dependent on browser configuration sothe result is not always guaranteed.

Templates

template.go.delimiters

Specifies an override for the left and right delimiters used in the templates.The delimiters must be specified as “LEFT_DELIMS RIGHT_DELIMS”

Default: {{ }}

Formatting

format.date

Specifies the default date format for the application. Revel uses this in two places:

  • Binding dates to a time.Time (see parameters)
  • Printing dates using the date template function (see template funcs)
    Default: 2006-01-02

format.datetime

Specifies the default datetime format for the application. Revel uses this in two places:

  • Binding dates to a time.Time (see parameters)
  • Printing dates using the datetime template function (see template funcs)
    Default: 2006-01-02 15:04

Database

db.import

Specifies the import path of the desired database/sql driver for the db module.

Default: “”

db.driver

Specifies the name of the database/sql driver (used insql.Open).

Default: “”

db.spec

Specifies the data source name of your database/sql database (used insql.Open).

Default: “”

Build

build.tags

Build tags to usewhen building an application.

Default: “”

Logging

See logging for details.

Cache

The cache module is a simple interface to a heap or distributed cache.

cache.expires

Sets the default duration before cache entries are expired from the cache. Itis used when the caller passes the constant cache.DEFAULT.

It is specified as a duration string acceptable totime.ParseDuration

(Presently it is not possible to specify a default of FOREVER)

Default: 1h (1 hour)

cache.memcached

If true, the cache module uses memcached instead of thein-memory cache.

Default: false

cache.redis

If true, the cache module uses redis instead of thein-memory cache.

Default: false

cache.hosts

A comma-separated list of memcached hosts. Cache entries are automaticallysharded among available hosts using a deterministic mapping of cache key to hostname. Hosts may be listed multiple times to increase their share of cachespace.

Default: “”

Scheduled Jobs

The jobs module allows you to run scheduled or ad-hoc jobs.

jobs.pool

  • The number of jobs allowed to run concurrently.
  • Default is 10.
  • If zero (0), then there is no limit imposed.
  1. jobs.pool = 4

jobs.selfconcurrent

If true (default is false), allows a job to run even if previous instances of that job are still inprogress.

  1. jobs.selfconcurrent = true

jobs.acceptproxyaddress

If true (default is false), the status page will accept the X-Forwarded-For header as the remoteaddress used to allow or deny public access. This is diabled by default as the header value can be spoofedand therefore is not trustable. You should only use this if you are access your Revel app via a reverseproxy (e.g. Nginx). It is not recommended to allow this is production mode due to the security implications.

  1. jobs.acceptproxyaddress = true

Named Schedules

Named cron schedules may be configured by setting a key of the form:

  1. cron.schedulename = @hourly

The names schedule may be referenced upon submission to the job runner. Forexample:

  1. jobs.Schedule("cron.schedulename",job)

Modules

  • Modules may be added to an application by specifying their base import path.
  • An empty import path disables the module.

module.testrunner = github.com/revel/modules/testrunner

FIXME mymodule crashes so disabled for now

module.mymodulename = /path/to/mymodule

module.mymodulename =

Error Handling

  • An optional value to wrap error path and line locations with a hyper link.
  • Disabled by default; does not wrap error location with link.
  • An example using Sublime Text’s custom URI scheme:

error.link = "subl://open?url=file://{{Path}}&line={{Line}}"

Areas for development

  • Allow inserting command line arguments as config values or otherwisespecifying config values from the command line.
GoDoc Reference
GitHub Labels

原文: https://revel.github.io/manual/appconf.html