aboutsummaryrefslogtreecommitdiff
path: root/server_config.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2026-01-21 01:12:11 +0700
committerShulhan <ms@kilabit.info>2026-01-21 01:12:11 +0700
commitfa4cc3a2ae6fa63bfbd8b005e4048dacc222dcc1 (patch)
treeb5566fe088dc51364101ab1db2a48ed845a4d832 /server_config.go
parentd0969869954c299c04ea58ab0fda1eba6a0350da (diff)
downloadlilin-fa4cc3a2ae6fa63bfbd8b005e4048dacc222dcc1.tar.xz
all: implement default down and up templates under section "[default"]
To minimize defining the same templates in notification, user can set default down and up templates under the default section.
Diffstat (limited to 'server_config.go')
-rw-r--r--server_config.go27
1 files changed, 26 insertions, 1 deletions
diff --git a/server_config.go b/server_config.go
index c9c553c..2a320a2 100644
--- a/server_config.go
+++ b/server_config.go
@@ -5,6 +5,7 @@ package lilin
import (
"fmt"
+ "html/template"
"os"
"path/filepath"
@@ -13,6 +14,9 @@ import (
// ServerConfig define the options for Lilin Server.
type ServerConfig struct {
+ downTmpl *template.Template
+ upTmpl *template.Template
+
// BaseDir define the base directory for running the server, default
// to "/".
// Its affect where to read the configuration, storing states, and
@@ -28,6 +32,9 @@ type ServerConfig struct {
// The BaseDir + "/var/log/lilin/service.d/".
logServiceDir string
+ DownTemplate string `ini:"default::down_template"`
+ UpTemplate string `ini:"default::up_template"`
+
// The address to listen for HTTP server and APIs.
Address string `ini:"server::address"`
@@ -78,8 +85,26 @@ func (cfg *ServerConfig) init() (err error) {
cfg.Address = defAddress
}
+ if cfg.DownTemplate == `` {
+ cfg.DownTemplate = defaultDownTemplate
+ }
+ cfg.downTmpl = template.New(`down`)
+ cfg.downTmpl, err = cfg.downTmpl.Parse(cfg.DownTemplate)
+ if err != nil {
+ return fmt.Errorf(`%s: failed to parse down_template: %s`, logp, err)
+ }
+
+ if cfg.UpTemplate == `` {
+ cfg.UpTemplate = defaultUpTemplate
+ }
+ cfg.upTmpl = template.New(`up`)
+ cfg.upTmpl, err = cfg.upTmpl.Parse(cfg.DownTemplate)
+ if err != nil {
+ return fmt.Errorf(`%s: failed to parse down_template: %s`, logp, err)
+ }
+
for _, notifConfig := range cfg.Notifs {
- err = notifConfig.init()
+ err = notifConfig.init(cfg)
if err != nil {
return fmt.Errorf(`%s: %w`, logp, err)
}