core: Prototype config parser

This commit is contained in:
John Brooks 2016-08-02 17:04:39 -06:00
parent eee2dd703d
commit 74dc289e09
1 changed files with 39 additions and 3 deletions

View File

@ -1,12 +1,48 @@
package core package core
import ( import (
"errors" "encoding/json"
"io/ioutil"
"log"
"path/filepath"
) )
type Config struct { type Config struct {
} }
func LoadConfig(configPath string) (*Config, error) { type ConfigRoot struct {
return nil, errors.New("Not implemented") 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
}
func LoadConfig(configPath string) (*Config, error) {
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
} }