Compare commits
No commits in common. "228d7722196119ba3234701081f6ff609084c233" and "2b8b2357527a64cf4b09190f085e007b833588b1" have entirely different histories.
228d772219
...
2b8b235752
25
ini.go
25
ini.go
@ -13,14 +13,7 @@ type Configuration struct {
|
||||
file *ini.File
|
||||
}
|
||||
|
||||
func NewConfiguration(fileLocation string, defaultConfig string) *Configuration {
|
||||
conf := new(Configuration)
|
||||
conf.fileLocation = fileLocation
|
||||
conf.createAndLoad(defaultConfig)
|
||||
return conf
|
||||
}
|
||||
|
||||
func LoadConfiguration(fileLocation string) *Configuration {
|
||||
func NewConfiguration(fileLocation string) *Configuration {
|
||||
conf := new(Configuration)
|
||||
conf.fileLocation = fileLocation
|
||||
conf.load()
|
||||
@ -213,29 +206,19 @@ func (config *Configuration) IsSet(path string) bool {
|
||||
return key.Value() != ""
|
||||
}
|
||||
|
||||
func (config *Configuration) createAndLoad(defaultConfig string) {
|
||||
_, err := os.Stat(config.fileLocation)
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
func (config *Configuration) load() {
|
||||
if _, err := os.Stat(config.fileLocation); err != nil {
|
||||
file, err := os.Create(config.fileLocation)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to create configuration file: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
_, err = file.WriteString(defaultConfig)
|
||||
_, err = file.WriteString("")
|
||||
if err != nil {
|
||||
fmt.Printf("Error creating configuration file: %v", err)
|
||||
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
|
||||
config.file, err = ini.Load(config.fileLocation)
|
||||
if err != nil {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user