aboutsummaryrefslogtreecommitdiff
path: root/server.go
diff options
context:
space:
mode:
Diffstat (limited to 'server.go')
-rw-r--r--server.go11
1 files changed, 8 insertions, 3 deletions
diff --git a/server.go b/server.go
index eeaa42e..1fe9522 100644
--- a/server.go
+++ b/server.go
@@ -28,6 +28,7 @@ type ServeCommand struct {
Port int
DBPath string
RateLimit int
+ Footer string
}
func (c *ServeCommand) Name() string { return "serve" }
@@ -37,6 +38,7 @@ func (c *ServeCommand) Init(args []string) error {
fs.IntVar(&c.Port, "port", 8080, "Port to listen on")
fs.StringVar(&c.DBPath, "db", "data/abvjt.db", "Path to SQLite database")
fs.IntVar(&c.RateLimit, "rate-limit", 30, "Max requests per minute per IP")
+ fs.StringVar(&c.Footer, "footer", "", "Custom HTML footer for the web interface")
if err := fs.Parse(args); err != nil {
if errors.Is(err, flag.ErrHelp) {
fs.Usage()
@@ -54,7 +56,7 @@ func (c *ServeCommand) Run(stdin io.Reader, stdout io.Writer) error {
}
defer db.Close()
- http.HandleFunc("/", handleRoot())
+ http.HandleFunc("/", handleRoot(c.Footer))
http.HandleFunc("/api/search", handleSearch(db, c.RateLimit))
http.HandleFunc("/api/health", handleHealth(db, c.RateLimit))
@@ -99,18 +101,21 @@ func (c *ServeCommand) Run(stdin io.Reader, stdout io.Writer) error {
return nil
}
-func handleRoot() http.HandlerFunc {
+func handleRoot(footer string) http.HandlerFunc {
tmpl, err := template.New("index").Parse(indexHTML)
if err != nil {
panic(fmt.Sprintf("failed to parse template: %v", err))
}
+ footerHTML := template.HTML(footer)
return func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
http.NotFound(w, r)
return
}
w.Header().Set("Content-Type", "text/html; charset=utf-8")
- tmpl.Execute(w, nil)
+ tmpl.Execute(w, map[string]interface{}{
+ "Footer": footerHTML,
+ })
}
}