diff options
Diffstat (limited to 'server_config.go')
| -rw-r--r-- | server_config.go | 27 |
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) } |
