working settings update.
Settings are loaded from the DB and added to the AppConfig during startup. When updating settings, they are stored in AppConfig, and written do the database.
This commit is contained in:
@@ -13,7 +13,7 @@ type SettingEntry struct {
|
||||
SettingKeyDescription string `json:"setting_key_description"`
|
||||
SettingDataType string `json:"setting_data_type"`
|
||||
|
||||
SettingValueNumeric int64 `json:"setting_value_numeric"`
|
||||
SettingValueNumeric int `json:"setting_value_numeric"`
|
||||
SettingValueString string `json:"setting_value_string"`
|
||||
}
|
||||
|
||||
|
||||
@@ -1,35 +1,20 @@
|
||||
package models
|
||||
|
||||
import "github.com/analogj/scrutiny/webapp/backend/pkg"
|
||||
|
||||
// Settings is made up of parsed SettingEntry objects retrieved from the database
|
||||
//type Settings struct {
|
||||
// MetricsNotifyLevel pkg.MetricsNotifyLevel `json:"metrics.notify.level" mapstructure:"metrics.notify.level"`
|
||||
// MetricsStatusFilterAttributes pkg.MetricsStatusFilterAttributes `json:"metrics.status.filter_attributes" mapstructure:"metrics.status.filter_attributes"`
|
||||
// MetricsStatusThreshold pkg.MetricsStatusThreshold `json:"metrics.status.threshold" mapstructure:"metrics.status.threshold"`
|
||||
//}
|
||||
|
||||
type Settings struct {
|
||||
MetricsNotifyLevel pkg.MetricsNotifyLevel `json:"metrics_notify_level"`
|
||||
MetricsStatusFilterAttributes pkg.MetricsStatusFilterAttributes `json:"metrics_status_filter_attributes"`
|
||||
MetricsStatusThreshold pkg.MetricsStatusThreshold `json:"metrics_status_threshold"`
|
||||
}
|
||||
|
||||
func (s *Settings) PopulateFromSettingEntries(entries []SettingEntry) {
|
||||
for _, entry := range entries {
|
||||
if entry.SettingKeyName == "metrics.notify.level" {
|
||||
s.MetricsNotifyLevel = pkg.MetricsNotifyLevel(entry.SettingValueNumeric)
|
||||
} else if entry.SettingKeyName == "metrics.status.filter_attributes" {
|
||||
s.MetricsStatusFilterAttributes = pkg.MetricsStatusFilterAttributes(entry.SettingValueNumeric)
|
||||
} else if entry.SettingKeyName == "metrics.status.threshold" {
|
||||
s.MetricsStatusThreshold = pkg.MetricsStatusThreshold(entry.SettingValueNumeric)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Settings) UpdateSettingEntries(entries []SettingEntry) []SettingEntry {
|
||||
for _, entry := range entries {
|
||||
if entry.SettingKeyName == "metrics.notify.level" {
|
||||
entry.SettingValueNumeric = int64(s.MetricsNotifyLevel)
|
||||
} else if entry.SettingKeyName == "metrics.status.filter_attributes" {
|
||||
entry.SettingValueNumeric = int64(s.MetricsStatusFilterAttributes)
|
||||
} else if entry.SettingKeyName == "metrics.status.threshold" {
|
||||
entry.SettingValueNumeric = int64(s.MetricsStatusThreshold)
|
||||
}
|
||||
}
|
||||
return entries
|
||||
Metrics struct {
|
||||
Notify struct {
|
||||
Level int `json:"level" mapstructure:"level"`
|
||||
} `json:"notify" mapstructure:"notify"`
|
||||
Status struct {
|
||||
FilterAttributes int `json:"filter_attributes" mapstructure:"filter_attributes"`
|
||||
Threshold int `json:"threshold" mapstructure:"threshold"`
|
||||
} `json:"status" mapstructure:"status"`
|
||||
} `json:"metrics" mapstructure:"metrics"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user