## 概述
`app.conf`?是Revel程序的配置文件,它使用?[goconfig](https://github.com/revel/config)?語法,類似微軟的 INI 文件。
下面是個例子:
~~~
app.name=chat
app.secret=pJLzyoiDe17L36mytqC912j81PfTiolHm1veQK6Grn1En3YFdB5lvEHVTwFEaWvj
http.addr=
http.port=9000
[dev]
results.pretty=true
watch=true
log.trace.output = off
log.info.output = stderr
log.warn.output = stderr
log.error.output = stderr
[prod]
results.pretty=false
watch=false
log.trace.output = off
log.info.output = off
log.warn.output = %(app.name)s.log
log.error.output = %(app.name)s.log
~~~
每個段是一種?**運行模式**。最上面的 key (不在任何段內)對所有的運行模式有效。這使得默認值在所有模式中適用,并且根據需要被重寫。`[prod]`?段僅用于?`生產`?模式。
新建的Revel程序中默認定義了?**dev**?和?**prod**?模式, 你也可以自定義你需要的段。 程序啟動時,根據 ([命令行工具](http://gorevel.cn/docs/manual/tool.html))“revel run” 提供的參數來選擇運行模式。
## 自定義屬性
開發者可以自定義key,并通過?[`revel.Config`?變量](http://gorevel.cn/docs/docs/godoc/revel.html#variables)?訪問它們。這里公開了一些簡單的?[api](http://gorevel.cn/docs/docs/godoc/config.html)。
## 內建屬性
### 應用程序設置
#### app.name
應用程序名稱,用于控制臺輸出和開發web頁。
例如:
~~~
app.name = Booking example application
~~~
默認值: 無值
* * *
#### app.secret
密鑰用于密碼操作 ([`revel.Sign`](http://gorevel.cn/docs/docs/godoc/util.html#Sign))。Revel 在內部使用它簽署session cookies。設置為空將禁用簽名。
使用?`revel new`新建項目時,它被設置為一個隨機的字符串。
例如:
~~~
app.secret = pJLzyoiDe17L36mytqC912j81PfTiolHm1veQK6Grn1En3YFdB5lvEHVTwFEaWvj
~~~
默認值: 無值
### HTTP settings
#### http.port
監聽端口
例如:
~~~
http.port = 9000
~~~
* * *
#### http.addr
監聽ip地址
Linux中, 空字符串代表通配符 – Windows中, 空字符串被轉換為?`"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 the application 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 set when running in an environment that restricts socket access by the program.
Default: 0
* * *
#### http.ssl
如果為真, Revel Web服務器將自行配置為接受SSL連接。這需要一個 X509 證書和一個 key 文件。
默認值: false
#### http.sslcert
指定 X509 證書文件的路徑
默認值: ””
#### http.sslkey
指定 X509 證書 key的路徑
默認值: ””
### 響應結果
#### results.chunked
確定模板渲染時是否使用?[分塊編碼](http://gorevel.cn/docs/manual/en.wikipedia.org/wiki/Chunked_transfer_encoding)。分塊編碼可以減少發送到客戶端的第一個字節的時間(在整個模板已經完全呈現數據之前)。
默認值: false
* * *
#### results.pretty
配置?[`RenderXml`](http://gorevel.cn/docs/docs/godoc/controller.html#RenderXml)?和?[`RenderJson`](http://gorevel.cn/docs/docs/godoc/controller.html#RenderJson)?生成縮進格式的 XML/JSON. 例如:
~~~
results.pretty = true
~~~
默認值: false
### 國際化 (i18n)
#### i18n.default_language
為消息翻譯指定默認??的語言,如果客戶端請求的語言環境未確認。如果不指定,則返回一個虛擬的信息。
例如:
~~~
i18n.default_language = en
~~~
默認值: ””
* * *
#### i18n.cookie
指定存儲用戶語言環境的cookie名稱
默認值: “%(cookie.prefix)_LANG” (參考 cookie.prefix)
### 監視
Revel 監視項目改動,并支持幾種類型文件的熱重載。啟用監視:
~~~
watch = true
~~~
如果為假, 禁用監視, 并忽略其他相關的監視配置?`watch.*`?(適用于生產環境)
默認值: true
* * *
#### watch.templates
如果為真, Revel 監視模板變化,必要時重新加載他們。
默認值: true
* * *
#### watch.routes
如果為真, Revel 監視?`routes`?文件的變化,必要時重新加載。
默認值: true
* * *
#### watch.code
如果為真, Revel 監視Go代碼改動,必要時重新編譯代碼(作為反向代理運行)。
`app/`?目錄(包括子目錄)下的代碼都被監視。
默認值: true
### Cookies
Revel 組件默認使用下面的 cookies:
* REVEL_SESSION
* REVEL_LANG
* REVEL_FLASH
* REVEL_ERRORS
#### cookie.prefix
Revel 使用這個屬性作為 Revel-produced cookies前綴。這樣可以在同一臺主機上運行多個REVEL應用程序。
例如,
~~~
cookie.prefix = MY
~~~
則對應的 cookie 名稱如下:
* MY_SESSION
* MY_LANG
* MY_FLASH
* MY_ERRORS
默認值: “REVEL”
### Session
#### session.expires
Revel 使用這個屬性設置session cookie的有效期。 Revel 使用?[ParseDuration](http://golang.org/pkg/time/#ParseDuration)?解析字符串,默認值是 30 天。也可以設置為會話結束時過期。 請注意,客戶端的行為依賴于瀏覽器的設置,所以結果并不總是保證。
### 模板
#### template.delimiters
指定模板左右分隔符
必須這樣指定分隔符 “左分隔符 右分隔符”
默認值: “{{ }}”
### 格式化
#### format.date
指定默認的日期格式,Revel在兩個地方使用它:
* 綁定日期參數到?`time.Time`?(參考?[binding](http://gorevel.cn/docs/manual/binding.html))
* 在模板中使用?`date`?模板函數輸出日期 (參考?[模板函數](http://gorevel.cn/docs/manual/templates.html))
默認值: “2006-01-02”
* * *
#### format.datetime
指定默認的日期時間格式,Revel在兩個地方使用它:
* 綁定日期參數到?`time.Time`?(參考?[binding](http://gorevel.cn/docs/manual/binding.html))
* 在模板中使用?`datetime`?模板函數輸出日期 (參考?[模板函數](http://gorevel.cn/docs/manual/templates.html))
默認值: “2006-01-02 15:04”
### 數據庫
#### db.import
指定DB模塊的 database/sql 驅動程序導入路徑。
默認值: ””
* * *
#### db.driver
指定 database/sql 驅動程序名稱 (在[`sql.Open`](http://golang.org/pkg/database/sql/#Open)中使用).
默認值: ””
* * *
#### db.spec
指定 database/sql 數據源名稱 (在?[`sql.Open`](http://golang.org/pkg/database/sql/#Open)中使用).
默認值: ””
### 構建
#### build.tags
[Build tags](http://golang.org/cmd/go/#Compile_packages_and_dependencies)?構建程序的時候使用。
默認值: ””
### 日志
TODO
### 緩存
[cache](http://gorevel.cn/docs/manual/cache.html)?模塊是一個簡單的堆或分布式緩存接口
#### cache.expires
設置緩存過期時間。在程序中調用者使用常量`cache.DEFAULT`獲取。
它是接受一個[`time.ParseDuration`](http://golang.org/pkg/time/#ParseDuration)?字符串。
(目前還不能指定默認值為?`FOREVER`)
默認值: “1h” (1 小時)
* * *
#### cache.memcached
如果為真, 緩存模塊使用?[memcached](http://memcached.org/)?來代替內存緩存。
默認值: false
* * *
#### cache.hosts
一個逗號分隔的 memcached 主機列表。緩存條目使用確定的主機名緩存key自動分片到可用的主機中。主機可能會多次列出,以增加共享的緩存空間。
默認值: ””
### 計劃任務
[計劃任務](http://gorevel.cn/docs/manual/jobs.html)?模塊允許你運行計劃任務或者臨時任務
#### 時間表
時間表可以通過key來配置。
~~~
cron.schedulename = @hourly
~~~
時間表的計劃時間可以在執行器中提交任務時使用。例如:
~~~
jobs.Schedule("cron.schedulename", job)
~~~
* * *
#### jobs.pool
允許同時允許的任務數量。例如:
~~~
jobs.pool = 4
~~~
如果為 0, 則沒有數量限制
默認值: 10
* * *
#### jobs.selfconcurrent
如果為真, 允許一個任務運行,即使是該任務的實例仍在進行中。
默認值: false
### 模塊
[模塊](http://gorevel.cn/docs/manual/modules.html)?通過指定導入路徑將模塊添加到應用程序中。例如:
~~~
module.testrunner = github.com/revel/revel/modules/testrunner
~~~
## 開發計劃
* 允許使用命令行參數配置值或以其他方式在命令行中指定值。