Compare commits

..

2 Commits

Author SHA1 Message Date
228d772219 Merge Confilct Resolution 2025-09-24 06:58:39 -04:00
5e1e8723eb Small Fixes 2025-09-24 06:52:25 -04:00

25
ini.go
View File

@ -13,7 +13,14 @@ type Configuration struct {
file *ini.File file *ini.File
} }
func NewConfiguration(fileLocation string) *Configuration { func NewConfiguration(fileLocation string, defaultConfig string) *Configuration {
conf := new(Configuration)
conf.fileLocation = fileLocation
conf.createAndLoad(defaultConfig)
return conf
}
func LoadConfiguration(fileLocation string) *Configuration {
conf := new(Configuration) conf := new(Configuration)
conf.fileLocation = fileLocation conf.fileLocation = fileLocation
conf.load() conf.load()
@ -206,19 +213,29 @@ func (config *Configuration) IsSet(path string) bool {
return key.Value() != "" return key.Value() != ""
} }
func (config *Configuration) load() { func (config *Configuration) createAndLoad(defaultConfig string) {
if _, err := os.Stat(config.fileLocation); err != nil { _, err := os.Stat(config.fileLocation)
if errors.Is(err, os.ErrNotExist) {
file, err := os.Create(config.fileLocation) file, err := os.Create(config.fileLocation)
if err != nil { if err != nil {
fmt.Printf("Failed to create configuration file: %v", err) fmt.Printf("Failed to create configuration file: %v", err)
os.Exit(1) os.Exit(1)
} }
_, err = file.WriteString("") _, err = file.WriteString(defaultConfig)
if err != nil { if err != nil {
fmt.Printf("Error creating configuration file: %v", err) fmt.Printf("Error creating configuration file: %v", err)
os.Exit(1) os.Exit(1)
} }
} else if err != nil {
fmt.Printf("Error loading configuration file: %v", err)
os.Exit(1)
} else {
fmt.Printf("Configuration File already exists... loading")
} }
config.load()
}
func (config *Configuration) load() {
var err error var err error
config.file, err = ini.Load(config.fileLocation) config.file, err = ini.Load(config.fileLocation)
if err != nil { if err != nil {