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
|
file *ini.File
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfiguration(fileLocation string, defaultConfig string) *Configuration {
|
func NewConfiguration(fileLocation 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()
|
||||||
@ -213,29 +206,19 @@ func (config *Configuration) IsSet(path string) bool {
|
|||||||
return key.Value() != ""
|
return key.Value() != ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *Configuration) createAndLoad(defaultConfig string) {
|
func (config *Configuration) load() {
|
||||||
_, err := os.Stat(config.fileLocation)
|
if _, err := os.Stat(config.fileLocation); err != nil {
|
||||||
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(defaultConfig)
|
_, err = file.WriteString("")
|
||||||
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 {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user