Say Hello Alfred :)

This commit is contained in:
klmp200 2018-07-23 16:59:39 +02:00
parent 173eb2e45b
commit 1c94f8dced
No known key found for this signature in database
GPG key ID: E7245548C53F904B
6 changed files with 95 additions and 1 deletions

44
settings/settings.go Normal file
View 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")
}

View 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