Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the read and write timeouts configurable via JSON file #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sdsConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"cacheLocation": "./sdscache/",
"cacheMaxBytes": 100000000,
"checkCacheEvery": 60,
"read_timeout": 300,
"write_timeout": 300,
"locationDetails": [
{
"location": "",
Expand Down
2 changes: 2 additions & 0 deletions sds_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ type Location struct {
// Configuration Struct for Configuraion File
type Configuration struct {
Port int `json:"port"`
ReadTimeout int `json:"read_timeout"`
WriteTimeout int `json:"write_timeout"`
CacheLocation string `json:"cacheLocation"`
Logfile string `json:"logfile"`
CacheMaxBytes int64 `json:"cacheMaxBytes"`
Expand Down
16 changes: 14 additions & 2 deletions sigplot_data_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2233,10 +2233,22 @@ func main() {
msg := ":%d"
bindAddr := fmt.Sprintf(msg, configuration.Port)

// Set sane defaults if ReadTimeout and WriteTimeout are not set.
// Recall: if they aren't set, they'll default to 0.
readTimeout := configuration.ReadTimeout
if readTimeout == 0 {
readTimeout = 240
}

writeTimeout := configuration.WriteTimeout
if writeTimeout == 0 {
writeTimeout = 30
}

svr := &http.Server{
Addr: bindAddr,
ReadTimeout: 240 * time.Second,
WriteTimeout: 30 * time.Second,
ReadTimeout: time.Duration(readTimeout) * time.Second,
WriteTimeout: time.Duration(writeTimeout) * time.Second,
MaxHeaderBytes: 1 << 20,
}
log.Fatal(svr.ListenAndServe())
Expand Down