2021-09-11 07:51:14 +02:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"html/template"
|
|
|
|
)
|
|
|
|
|
2021-09-11 10:33:14 +02:00
|
|
|
const (
|
|
|
|
defaultTitle = "Health Dashboard | Gatus"
|
|
|
|
defaultLogo = ""
|
|
|
|
)
|
2021-09-11 07:51:14 +02:00
|
|
|
|
|
|
|
// UIConfig is the configuration for the UI of Gatus
|
|
|
|
type UIConfig struct {
|
|
|
|
Title string `yaml:"title"` // Title of the page
|
2021-09-11 10:33:14 +02:00
|
|
|
Logo string `yaml:"logo"` // Logo to display on the page
|
2021-09-11 07:51:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetDefaultUIConfig returns a UIConfig struct with the default values
|
|
|
|
func GetDefaultUIConfig() *UIConfig {
|
|
|
|
return &UIConfig{
|
|
|
|
Title: defaultTitle,
|
2021-09-11 10:33:14 +02:00
|
|
|
Logo: defaultLogo,
|
2021-09-11 07:51:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cfg *UIConfig) validateAndSetDefaults() error {
|
|
|
|
if len(cfg.Title) == 0 {
|
|
|
|
cfg.Title = defaultTitle
|
|
|
|
}
|
|
|
|
t, err := template.ParseFiles(StaticFolder + "/index.html")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
var buffer bytes.Buffer
|
|
|
|
err = t.Execute(&buffer, cfg)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|