1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
wtf/modules/uptimerobot/settings.go
Miha Frangež 7f05fbcda5 Implemented UptimeRobot widget
This is the first working version of the UptimeRobot module, as discussed in #979
2020-10-11 20:09:18 -07:00

36 lines
896 B
Go

package uptimerobot
import (
"os"
"github.com/olebedev/config"
"github.com/wtfutil/wtf/cfg"
)
const (
defaultFocusable = true
defaultTitle = "Uptime Robot"
)
type Settings struct {
common *cfg.Common
apiKey string `help:"An UptimeRobot API key."`
uptimePeriods string `help:"The periods over which to display uptime (in days, dash-separated)." optional:"true"`
}
func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings {
settings := Settings{
common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig),
apiKey: ymlConfig.UString("apiKey", os.Getenv("WTF_UPTIMEROBOT_APIKEY")),
uptimePeriods: ymlConfig.UString("uptimePeriods", "30"),
}
cfg.ModuleSecret(name, globalConfig, &settings.apiKey).
Service("https://api.uptimerobot.com").Load()
return &settings
}