1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-25 22:51:29 +00:00

add HttpServerTimeOut setting

This commit is contained in:
astaxie 2013-07-03 15:29:54 +08:00
parent 189df1280c
commit bf9de3bcf6
2 changed files with 13 additions and 1 deletions

View File

@ -10,6 +10,7 @@ import (
"os" "os"
"path" "path"
"runtime" "runtime"
"time"
) )
const VERSION = "0.7.0" const VERSION = "0.7.0"
@ -41,6 +42,7 @@ var (
EnableGzip bool // enable gzip EnableGzip bool // enable gzip
DirectoryIndex bool //ebable DirectoryIndex default is false DirectoryIndex bool //ebable DirectoryIndex default is false
EnbaleHotUpdate bool //enable HotUpdate default is false EnbaleHotUpdate bool //enable HotUpdate default is false
HttpServerTimeOut int64
) )
func init() { func init() {
@ -67,6 +69,7 @@ func init() {
EnableGzip = false EnableGzip = false
StaticDir["/static"] = "static" StaticDir["/static"] = "static"
AppConfigPath = path.Join(AppPath, "conf", "app.conf") AppConfigPath = path.Join(AppPath, "conf", "app.conf")
HttpServerTimeOut = 0
ParseConfig() ParseConfig()
} }
@ -106,7 +109,13 @@ func (app *App) Run() {
theStoppable.wg.Wait() theStoppable.wg.Wait()
CloseSelf() CloseSelf()
} else { } else {
err = http.ListenAndServe(addr, app.Handlers) s := &http.Server{
Addr: addr,
Handler: app.Handlers,
ReadTimeout: time.Duration(HttpServerTimeOut) * time.Second,
WriteTimeout: time.Duration(HttpServerTimeOut) * time.Second,
}
err = s.ListenAndServe()
} }
} }

View File

@ -180,6 +180,9 @@ func ParseConfig() (err error) {
if hotupdate, err := AppConfig.Bool("hotupdate"); err == nil { if hotupdate, err := AppConfig.Bool("hotupdate"); err == nil {
EnbaleHotUpdate = hotupdate EnbaleHotUpdate = hotupdate
} }
if timeout, err := AppConfig.Int64("httpservertimeout"); err == nil {
HttpServerTimeOut = timeout
}
} }
return nil return nil
} }