add HttpServerTimeOut setting
Showing
2 changed files
with
13 additions
and
1 deletions
| ... | @@ -10,6 +10,7 @@ import ( | ... | @@ -10,6 +10,7 @@ import ( |
| 10 | "os" | 10 | "os" |
| 11 | "path" | 11 | "path" |
| 12 | "runtime" | 12 | "runtime" |
| 13 | "time" | ||
| 13 | ) | 14 | ) |
| 14 | 15 | ||
| 15 | const VERSION = "0.7.0" | 16 | const VERSION = "0.7.0" |
| ... | @@ -41,6 +42,7 @@ var ( | ... | @@ -41,6 +42,7 @@ var ( |
| 41 | EnableGzip bool // enable gzip | 42 | EnableGzip bool // enable gzip |
| 42 | DirectoryIndex bool //ebable DirectoryIndex default is false | 43 | DirectoryIndex bool //ebable DirectoryIndex default is false |
| 43 | EnbaleHotUpdate bool //enable HotUpdate default is false | 44 | EnbaleHotUpdate bool //enable HotUpdate default is false |
| 45 | HttpServerTimeOut int64 | ||
| 44 | ) | 46 | ) |
| 45 | 47 | ||
| 46 | func init() { | 48 | func init() { |
| ... | @@ -67,6 +69,7 @@ func init() { | ... | @@ -67,6 +69,7 @@ func init() { |
| 67 | EnableGzip = false | 69 | EnableGzip = false |
| 68 | StaticDir["/static"] = "static" | 70 | StaticDir["/static"] = "static" |
| 69 | AppConfigPath = path.Join(AppPath, "conf", "app.conf") | 71 | AppConfigPath = path.Join(AppPath, "conf", "app.conf") |
| 72 | HttpServerTimeOut = 0 | ||
| 70 | ParseConfig() | 73 | ParseConfig() |
| 71 | } | 74 | } |
| 72 | 75 | ||
| ... | @@ -106,7 +109,13 @@ func (app *App) Run() { | ... | @@ -106,7 +109,13 @@ func (app *App) Run() { |
| 106 | theStoppable.wg.Wait() | 109 | theStoppable.wg.Wait() |
| 107 | CloseSelf() | 110 | CloseSelf() |
| 108 | } else { | 111 | } else { |
| 109 | err = http.ListenAndServe(addr, app.Handlers) | 112 | s := &http.Server{ |
| 113 | Addr: addr, | ||
| 114 | Handler: app.Handlers, | ||
| 115 | ReadTimeout: time.Duration(HttpServerTimeOut) * time.Second, | ||
| 116 | WriteTimeout: time.Duration(HttpServerTimeOut) * time.Second, | ||
| 117 | } | ||
| 118 | err = s.ListenAndServe() | ||
| 110 | } | 119 | } |
| 111 | 120 | ||
| 112 | } | 121 | } | ... | ... |
| ... | @@ -180,6 +180,9 @@ func ParseConfig() (err error) { | ... | @@ -180,6 +180,9 @@ func ParseConfig() (err error) { |
| 180 | if hotupdate, err := AppConfig.Bool("hotupdate"); err == nil { | 180 | if hotupdate, err := AppConfig.Bool("hotupdate"); err == nil { |
| 181 | EnbaleHotUpdate = hotupdate | 181 | EnbaleHotUpdate = hotupdate |
| 182 | } | 182 | } |
| 183 | if timeout, err := AppConfig.Int64("httpservertimeout"); err == nil { | ||
| 184 | HttpServerTimeOut = timeout | ||
| 185 | } | ||
| 183 | } | 186 | } |
| 184 | return nil | 187 | return nil |
| 185 | } | 188 | } | ... | ... |
-
Please register or sign in to post a comment