feat: save config
This commit is contained in:
@@ -126,6 +126,38 @@ func initializeViper(appName string) (*viper.Viper, string, error) {
|
|||||||
return v, configFile, nil
|
return v, configFile, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Config) Save() error {
|
||||||
|
v, _, err := initializeViper(constants.AppName)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to initialize viper: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
v.Set("app.settings_reviewed", c.App.SettingsReviewed)
|
||||||
|
v.Set("app.enable_alarm", c.App.EnableAlarm)
|
||||||
|
v.Set("app.enable_link_opening", c.App.EnableLinkOpening)
|
||||||
|
v.Set("app.use_attendance_journal_api", c.App.UseAttendanceJounralApi)
|
||||||
|
v.Set("app.browser", c.App.Browser)
|
||||||
|
v.Set("app.enable_checking_updates", c.App.EnableCheckingUpdates)
|
||||||
|
|
||||||
|
v.Set("logging.level", c.Logging.Level)
|
||||||
|
v.Set("logging.output", c.Logging.Output)
|
||||||
|
|
||||||
|
v.Set("telemetry.enable_statistics_collection", c.Telemetry.EnableStatisticsCollection)
|
||||||
|
v.Set("telemetry.enable_anonymous_error_reports", c.Telemetry.EnableAnonymousErrorReports)
|
||||||
|
|
||||||
|
if c.Communication.QrUrl != "" {
|
||||||
|
v.Set("communication.self_approve_url", c.Communication.QrUrl)
|
||||||
|
}
|
||||||
|
if c.Communication.QrQueryToken != "" {
|
||||||
|
v.Set("communication.qr_query_token", c.Communication.QrQueryToken)
|
||||||
|
}
|
||||||
|
if c.Communication.ApiSelfApproveMethod != "" {
|
||||||
|
v.Set("communication.api_self_approve_method", c.Communication.ApiSelfApproveMethod)
|
||||||
|
}
|
||||||
|
|
||||||
|
return v.WriteConfig()
|
||||||
|
}
|
||||||
|
|
||||||
func NewConfig() (*Config, error) {
|
func NewConfig() (*Config, error) {
|
||||||
v, configFile, err := initializeViper(constants.AppName)
|
v, configFile, err := initializeViper(constants.AppName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user