forked from git.klmp200.net/ALFRED
Say Hello Alfred :)
This commit is contained in:
parent
173eb2e45b
commit
1c94f8dced
6 changed files with 95 additions and 1 deletions
44
settings/settings.go
Normal file
44
settings/settings.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* @Author: Bartuccio Antoine
|
||||
* @Date: 2018-07-23 15:24:30
|
||||
* @Last Modified by: klmp200
|
||||
* @Last Modified time: 2018-07-23 16:02:42
|
||||
*/
|
||||
|
||||
package settings
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
)
|
||||
|
||||
var Settings map[string]interface{}
|
||||
|
||||
// Load settings from given file path
|
||||
// Return error in case of bad import
|
||||
func loadJson(path string) error {
|
||||
file, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = json.Unmarshal(file, &Settings)
|
||||
return err
|
||||
}
|
||||
|
||||
// Load settings from given files paths
|
||||
// Default settings are mandatory and program crash if there is an error at importation
|
||||
// Custom settings are skipped if malformed or not found
|
||||
func LoadSettings(settings_default_path, settings_custom_path string) {
|
||||
log.Println("Loading settings")
|
||||
Settings = make(map[string]interface{})
|
||||
if err := loadJson(settings_default_path); err != nil {
|
||||
log.Println("error importing default settings")
|
||||
log.Fatal(err)
|
||||
}
|
||||
if err := loadJson(settings_custom_path); err != nil {
|
||||
log.Println("error importing custom settings, skipping")
|
||||
log.Println(err)
|
||||
}
|
||||
log.Println("Settings loaded")
|
||||
}
|
8
settings/settings_test.go
Normal file
8
settings/settings_test.go
Normal file
|
@ -0,0 +1,8 @@
|
|||
/*
|
||||
* @Author: Bartuccio Antoine
|
||||
* @Date: 2018-07-23 16:08:28
|
||||
* @Last Modified by: klmp200
|
||||
* @Last Modified time: 2018-07-23 16:08:37
|
||||
*/
|
||||
|
||||
package settings
|
Loading…
Add table
Add a link
Reference in a new issue