diff options
| author | Shulhan <ms@kilabit.info> | 2026-02-11 21:43:11 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2026-02-11 21:43:11 +0700 |
| commit | 5b41090e6c523a1e66047329e51c2b0db280a581 (patch) | |
| tree | 10635c88bc6510a7405259199fa6f99675936240 /lib/http/server_options.go | |
| parent | 37c0e3f259204842c1ac82a04effb6c12e76078d (diff) | |
| download | pakakeh.go-5b41090e6c523a1e66047329e51c2b0db280a581.tar.xz | |
lib/http: implement server auto shutdown when idle
In the `ServerOptions`, we add option `ShutdownIdleDuration` when set to
non-zero value it will start a timer.
When the timer expired, the server will stop accepting new connection and
then shutting down.
This allow de-activating HTTP server when no connections received after
specific duration to reduce the system resources.
Diffstat (limited to 'lib/http/server_options.go')
| -rw-r--r-- | lib/http/server_options.go | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/http/server_options.go b/lib/http/server_options.go index 8e168885..61fcff33 100644 --- a/lib/http/server_options.go +++ b/lib/http/server_options.go @@ -9,6 +9,7 @@ import ( "net" "net/http" "strings" + "time" "git.sr.ht/~shulhan/pakakeh.go/lib/memfs" ) @@ -63,6 +64,11 @@ type ServerOptions struct { // The options for Cross-Origin Resource Sharing. CORS CORSOptions + // ShutdownIdleDuration define the duration where the server will + // automatically stop accepting new connection and then shutting down + // the server. + ShutdownIdleDuration time.Duration + // If true, server generate index.html automatically if its not // exist in the directory. // The index.html contains the list of files inside the requested |
