Add 2 parameter(TUSD_SERVER_READ_TIMEOUT_IN_SECONDS, TUSD_SERVER_WRITE_TIMEOUT_IN_SECONDS)

This commit is contained in:
ice5050 2014-04-01 16:43:20 +07:00
parent 3db2976bd5
commit 656f7ddb5c
1 changed files with 14 additions and 0 deletions

View File

@ -83,6 +83,20 @@ func main() {
WriteTimeout: 8 * time.Second,
MaxHeaderBytes: 0,
}
if envReadTimeout := os.Getenv("TUSD_SERVER_READ_TIMEOUT_IN_SECONDS"); envReadTimeout != "" {
parsed, err := strconv.ParseInt(envReadTimeout, 10, 64)
if err != nil {
panic("bad TUSD_SERVER_READ_TIMEOUT_IN_SECONDS: " + err.Error())
}
s.ReadTimeout = time.Duration(parsed) * time.Second
}
if envWriteTimeout := os.Getenv("TUSD_SERVER_WRITE_TIMEOUT_IN_SECONDS"); envWriteTimeout != "" {
parsed, err := strconv.ParseInt(envWriteTimeout, 10, 64)
if err != nil {
panic("bad TUSD_SERVER_WRITE_TIMEOUT_IN_SECONDS: " + err.Error())
}
s.WriteTimeout = time.Duration(parsed) * time.Second
}
log.Printf("servering clients at http://localhost%s", addr)
if err := s.ListenAndServe(); err != nil {