forked from git.klmp200.net/ALFRED
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
|
/*
|
||
|
* @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")
|
||
|
}
|