From c1c911b0102b69fe6d546be7572ef004555c595d Mon Sep 17 00:00:00 2001 From: Yevhen Pavlov Date: Wed, 10 Apr 2024 00:02:40 +0300 Subject: [PATCH] fix lint --- internal/config/config.go | 19 ++++++++++++++----- pkg/config/config.go | 4 ++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index 662ba1a..af9156e 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -1,6 +1,8 @@ package config import ( + "fmt" + "github.com/sonjek/mouse-stay-up/pkg/config" ) @@ -36,14 +38,15 @@ type Config struct { func init() { // Create a folder to save the config file if it doesn't exist yet - config.CreateConfigFolder(appName) + if err := config.CreateConfigFolder(appName); err != nil { + fmt.Println(err) + } // Calculate the configuration file path for saving when app parameters change configFilePath = config.GetConfigFilePath(appName, configFileName) } func NewConfig() *Config { - // Define the default Config struct appConfig := &Config{ Enabled: true, @@ -56,7 +59,7 @@ func NewConfig() *Config { // Saves the struct to an configuration file if it doesn't exist yet if !isRestored { - config.SaveStructToFile(configFilePath, appConfig) + saveConfig(appConfig) } return appConfig @@ -65,11 +68,17 @@ func NewConfig() *Config { func (c *Config) ToggleEnableDisable() { c.Enabled = !c.Enabled - config.SaveStructToFile(configFilePath, c) + saveConfig(c) } func (c *Config) SetWorkingHoursInterval(interval string) { c.WorkingHoursInterval = interval - config.SaveStructToFile(configFilePath, c) + saveConfig(c) +} + +func saveConfig(appConfig *Config) { + if err := config.SaveStructToFile(configFilePath, appConfig); err != nil { + fmt.Println(err) + } } diff --git a/pkg/config/config.go b/pkg/config/config.go index b3efaf4..d0b5d5e 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -37,7 +37,7 @@ func GetConfigFilePath(appName, configFileName string) string { } // Saves the struct to an configuration file -func SaveStructToFile(configFilePath string, config interface{}) error { +func SaveStructToFile(configFilePath string, config any) error { // Reflect data sources from given struct cfg := ini.Empty() if err := ini.ReflectFrom(cfg, config); err != nil { @@ -53,7 +53,7 @@ func SaveStructToFile(configFilePath string, config interface{}) error { } // Restores the configuration file into the struct -func LoadFileToStruct(configFilePath string, config interface{}) bool { +func LoadFileToStruct(configFilePath string, config any) bool { // Try to load the configuration file from disk if it exists cfg, err := ini.Load(configFilePath) if err != nil {