Skip to content

Commit

Permalink
Explicitly create custom http.Server, defining server timeout values
Browse files Browse the repository at this point in the history
  • Loading branch information
syncore committed Jul 6, 2016
1 parent 2ca4524 commit da104a7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/constants/misc_constants.go
Expand Up @@ -23,7 +23,7 @@ var (
// GameFileFullPath represents the OS-independent full path to the game file.
GameFileFullPath = path.Join(ConfigDirectory, GameFile)
// Version is the version number of the application.
Version = "0.1.3"
Version = "0.1.5"
// AppInfo contains the application information.
AppInfo = fmt.Sprintf("a2sapi v%s by syncore <syncore@syncore.org>", Version)
)
12 changes: 10 additions & 2 deletions src/web/server.go
Expand Up @@ -5,6 +5,7 @@ package web
import (
"fmt"
"net/http"
"time"

"github.com/syncore/a2sapi/src/config"
"github.com/syncore/a2sapi/src/logger"
Expand All @@ -21,8 +22,15 @@ func Start(runSilent bool) {

logger.LogAppInfo("Starting HTTP server on port %d",
config.Config.WebConfig.APIWebPort)
err := http.ListenAndServe(fmt.Sprintf(":%d",
config.Config.WebConfig.APIWebPort), r)

srv := http.Server{
Addr: fmt.Sprintf(":%d", config.Config.WebConfig.APIWebPort),
Handler: r,
ReadTimeout: 30 * time.Second,
WriteTimeout: 30 * time.Second,
MaxHeaderBytes: 1 << 20}

err := srv.ListenAndServe()
if err != nil {
logger.LogAppError(err)
panic(fmt.Sprintf("Unable to start HTTP server, error: %s\n", err))
Expand Down

0 comments on commit da104a7

Please sign in to comment.