1
FUNC的init()的第二次執行我有非常簡單的代碼,我。去文件:在GAE
func init() {
http.HandleFunc("/", handlerMain)
log.Println("init executed")
}
func handlerMain(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "TEST")
}
和app.yaml中:
application: newsboard
version: 1
runtime: go
api_version: go1
handlers:
- url: /.*
script: _go_app
當第一的一切而被執行罰款,這是從控制檯
INFO 2015-10-19 19:28:56,626 devappserver2.py:763] Skipping SDK update check.
INFO 2015-10-19 19:28:56,652 api_server.py:205] Starting API server at: http://localhost:56946
INFO 2015-10-19 19:28:56,655 dispatcher.py:197] Starting module "default" running at: http://localhost:8080
INFO 2015-10-19 19:28:56,658 admin_server.py:116] Starting admin server at: http://localhost:8000
2015/10/19 19:28:59 init executed
輸出但是當我進入http://localhost:8080我得到以下幾點:
INFO 2015-10-19 19:32:16,394 module.py:786] default: "GET/HTTP/1.1" 200 4
2015/10/19 19:32:16 init executed
因此,init()以某種方式被執行兩次。然後,每當我重新加載頁面時,「執行init」不再出現在控制檯中。 我的問題:爲什麼init()發生兩次,這是好嗎?
但是當我第一次訪問我的本地主頁時究竟發生了什麼?我認爲它不會做任何可以被認爲是代碼修改的東西 – Kaign
@Kaign請參閱編輯答案。 – icza