2016-07-01 03:18:55 +00:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
2016-08-02 23:04:39 +00:00
|
|
|
"encoding/json"
|
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
"path/filepath"
|
2016-07-01 03:18:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
}
|
|
|
|
|
2016-08-02 23:04:39 +00:00
|
|
|
type ConfigRoot struct {
|
|
|
|
Contacts map[string]ConfigContact
|
|
|
|
Identity ConfigIdentity
|
|
|
|
}
|
|
|
|
|
|
|
|
type ConfigContact struct {
|
|
|
|
Hostname string
|
|
|
|
LastConnected string
|
|
|
|
Nickname string
|
|
|
|
WhenCreated string
|
|
|
|
}
|
|
|
|
|
|
|
|
type ConfigIdentity struct {
|
|
|
|
DataDirectory string
|
|
|
|
HostnameBlacklist []string
|
|
|
|
ServiceKey string
|
|
|
|
}
|
|
|
|
|
2016-07-01 03:18:55 +00:00
|
|
|
func LoadConfig(configPath string) (*Config, error) {
|
2016-08-02 23:04:39 +00:00
|
|
|
configFile := filepath.Join(configPath, "ricochet.json")
|
|
|
|
configData, err := ioutil.ReadFile(configFile)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Config read error from %s: %v", configFile, err)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var root ConfigRoot
|
|
|
|
if err := json.Unmarshal(configData, &root); err != nil {
|
|
|
|
log.Printf("Config parse error: %v", err)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Printf("Config: %v", root)
|
|
|
|
|
|
|
|
return &Config{}, nil
|
2016-07-01 03:18:55 +00:00
|
|
|
}
|