aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-03-22 14:20:07 +0800
committerRunxi Yu <me@runxiyu.org>2025-03-22 14:20:07 +0800
commit72d4a043db48bb8196fbf60b99f9d59ef827bf8b (patch)
tree21ff45349f5fb9b955096dd4e68c12e3f8da13e0
parentActually incrementally generate the git log (diff)
downloadforge-72d4a043db48bb8196fbf60b99f9d59ef827bf8b.tar.gz
forge-72d4a043db48bb8196fbf60b99f9d59ef827bf8b.tar.zst
forge-72d4a043db48bb8196fbf60b99f9d59ef827bf8b.zip
Configurable timeout
-rw-r--r--config.go3
-rw-r--r--forge.scfg4
-rw-r--r--main.go6
3 files changed, 10 insertions, 3 deletions
diff --git a/config.go b/config.go
index 5382bbe..3721fd6 100644
--- a/config.go
+++ b/config.go
@@ -21,6 +21,9 @@ var config struct {
Addr string `scfg:"addr"`
CookieExpiry int `scfg:"cookie_expiry"`
Root string `scfg:"root"`
+ ReadTimeout uint `scfg:"read_timeout"`
+ WriteTimeout uint `scfg:"write_timeout"`
+ IdleTimeout uint `scfg:"idle_timeout"`
} `scfg:"http"`
Hooks struct {
Socket string `scfg:"socket"`
diff --git a/forge.scfg b/forge.scfg
index 42a4b57..e2b703e 100644
--- a/forge.scfg
+++ b/forge.scfg
@@ -13,6 +13,10 @@ http {
# What is the canonical URL of the web root?
root https://forge.example.org
+
+ read_timeout 120
+ write_timeout 120
+ idle_timeout 120
}
irc {
diff --git a/main.go b/main.go
index 1530d90..444e5b0 100644
--- a/main.go
+++ b/main.go
@@ -89,9 +89,9 @@ func main() {
}
server := http.Server{
Handler: &forgeHTTPRouter{},
- ReadTimeout: 10 * time.Second,
- WriteTimeout: 10 * time.Second,
- IdleTimeout: 60 * time.Second,
+ ReadTimeout: time.Duration(config.HTTP.ReadTimeout) * time.Second,
+ WriteTimeout: time.Duration(config.HTTP.ReadTimeout) * time.Second,
+ IdleTimeout: time.Duration(config.HTTP.ReadTimeout) * time.Second,
} //exhaustruct:ignore
clog.Info("Listening HTTP on " + config.HTTP.Net + " " + config.HTTP.Addr)
go func() {