-
-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
14 changed files
with
144 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"` | ||
MetricsStatusFilterAttributes pkg.MetricsStatusFilterAttributes `json:"metrics_status_filter_attributes"` | ||
MetricsStatusThreshold pkg.MetricsStatusThreshold `json:"metrics_status_threshold"` | ||
} | ||
//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"` | ||
//} | ||
|
||
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 | ||
type Settings struct { | ||
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"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.