Added TIMEZONE to database app config and validate
This commit is contained in:
parent
43d8938459
commit
c28c848b95
@ -14,8 +14,8 @@ type Configuration struct {
|
||||
|
||||
var smonConfig Configuration
|
||||
|
||||
func SmonConfigInit() (err error) {
|
||||
smonConfig.Settings = make(map[string]string, 8)
|
||||
func SmonConfigInit() (cfg Configuration, err error) {
|
||||
cfg.Settings = make(map[string]string, 8)
|
||||
|
||||
var rows *sql.Rows
|
||||
rows, err = service.Db.Conn.Query(`SELECT * FROM public.configuration`)
|
||||
@ -33,12 +33,22 @@ func SmonConfigInit() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
smonConfig.Settings[setting] = value
|
||||
cfg.Settings[setting] = value
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (cfg *Configuration) Validate() (err error) {
|
||||
mandatorySettings := []string{"THEME", "TIMEZONE"}
|
||||
for _, settingsKey := range mandatorySettings {
|
||||
if _, found := cfg.Settings[settingsKey]; !found {
|
||||
return werr.New("Configuration missing setting '%s' in database", settingsKey)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (cfg *Configuration) SetTheme(theme string) (err error) {
|
||||
cfg.Settings["THEME"] = theme
|
||||
_, err = service.Db.Conn.Exec(`UPDATE public.configuration SET value=$1 WHERE setting='THEME'`, theme)
|
||||
|
8
main.go
8
main.go
@ -153,7 +153,13 @@ func main() { // {{{
|
||||
|
||||
go nodataLoop()
|
||||
|
||||
err = SmonConfigInit()
|
||||
smonConfig, err = SmonConfigInit()
|
||||
if err != nil {
|
||||
logger.Error("configuration", "error", werr.Wrap(err))
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
err = smonConfig.Validate()
|
||||
if err != nil {
|
||||
logger.Error("configuration", "error", werr.Wrap(err))
|
||||
os.Exit(1)
|
||||
|
1
sql/00020.sql
Normal file
1
sql/00020.sql
Normal file
@ -0,0 +1 @@
|
||||
INSERT INTO public.configuration(setting, value) VALUES('TIMEZONE', 'Europe/Stockholm');
|
Loading…
Reference in New Issue
Block a user