2018-07-23 16:59:39 +02:00
|
|
|
/*
|
|
|
|
* @Author: Bartuccio Antoine
|
|
|
|
* @Date: 2018-07-23 15:24:30
|
|
|
|
* @Last Modified by: klmp200
|
2018-07-23 19:25:35 +02:00
|
|
|
* @Last Modified time: 2018-07-23 19:14:44
|
2018-07-23 16:59:39 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
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
|
2018-07-23 19:25:35 +02:00
|
|
|
// Default settings are mandatory and program should crash if there is an error at importation
|
2018-07-23 16:59:39 +02:00
|
|
|
// Custom settings are skipped if malformed or not found
|
2018-07-23 19:25:35 +02:00
|
|
|
func LoadSettings(settings_default_path, settings_custom_path string) error {
|
2018-07-23 16:59:39 +02:00
|
|
|
log.Println("Loading settings")
|
|
|
|
Settings = make(map[string]interface{})
|
|
|
|
if err := loadJson(settings_default_path); err != nil {
|
|
|
|
log.Println("error importing default settings")
|
2018-07-23 19:25:35 +02:00
|
|
|
log.Println(err)
|
|
|
|
return err
|
2018-07-23 16:59:39 +02:00
|
|
|
}
|
|
|
|
if err := loadJson(settings_custom_path); err != nil {
|
|
|
|
log.Println("error importing custom settings, skipping")
|
|
|
|
log.Println(err)
|
|
|
|
}
|
|
|
|
log.Println("Settings loaded")
|
2018-07-23 19:25:35 +02:00
|
|
|
return nil
|
2018-07-23 16:59:39 +02:00
|
|
|
}
|