summaryrefslogtreecommitdiff
path: root/cmd/www-kilabit/main.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2026-02-11 21:56:24 +0700
committerShulhan <ms@kilabit.info>2026-02-12 07:52:42 +0700
commit9baf42cd00779ecb75301a7de2212f62b9789d2e (patch)
tree63e18e158a0fa70ab7e1ebdef5f5f9455aa48246 /cmd/www-kilabit/main.go
parent1a2c37077b92e156d6513a038eba0bf0c7ba5071 (diff)
downloadkilabit.info-9baf42cd00779ecb75301a7de2212f62b9789d2e.tar.xz
cmd/www-kilabit: add option shutdown-idle
If set, server will automatically shutdown when no new connections accepted after specific duration.
Diffstat (limited to 'cmd/www-kilabit/main.go')
-rw-r--r--cmd/www-kilabit/main.go20
1 files changed, 17 insertions, 3 deletions
diff --git a/cmd/www-kilabit/main.go b/cmd/www-kilabit/main.go
index cfbcb41..54eef6a 100644
--- a/cmd/www-kilabit/main.go
+++ b/cmd/www-kilabit/main.go
@@ -7,8 +7,10 @@ import (
"flag"
"log"
"strings"
+ "time"
"git.sr.ht/~shulhan/ciigo"
+ "git.sr.ht/~shulhan/pakakeh.go/lib/http"
"git.sr.ht/~shulhan/pakakeh.go/lib/memfs"
"git.sr.ht/~shulhan/pakakeh.go/lib/systemd"
)
@@ -26,18 +28,30 @@ func main() {
HTMLTemplate: `_content/template.gohtml`,
}
serveOpts = ciigo.ServeOptions{
- ConvertOptions: convertOpts,
- Mfs: memfsContent,
+ ServerOptions: http.ServerOptions{
+ Memfs: memfsContent,
+ },
}
+ shutdownIdleDuration string
+
cmd string
err error
)
flag.BoolVar(&serveOpts.IsDevelopment, "dev", false, "Run in development mode")
flag.StringVar(&serveOpts.Address, `address`, `127.0.0.1:7000`, `Address to serve`)
+ flag.StringVar(&shutdownIdleDuration, `shutdown-idle`, ``,
+ `Shutdown the server after specific duration`)
flag.Parse()
+ if shutdownIdleDuration != `` {
+ serveOpts.ShutdownIdleDuration, err = time.ParseDuration(shutdownIdleDuration)
+ if err != nil {
+ log.Fatalf(`invalid shutdown-idle value %s: %s`, shutdownIdleDuration, err)
+ }
+ }
+
cmd = strings.ToLower(flag.Arg(0))
switch cmd {
@@ -71,7 +85,7 @@ func main() {
gotAddr, serveOpts.Address)
}
}
- err = ciigo.Serve(serveOpts)
+ err = ciigo.Serve(serveOpts, convertOpts)
if err != nil {
log.Fatal(err)
}