summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2015-12-04 00:56:43 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-12-04 00:56:43 (GMT)
commit89f0eec04192fa849a9f0d6a2eec697686ff3540 (patch)
tree1a9883ba1d63108d2e4ae3461bd037c93b4f61b1 /src
parent80c19f00f3b098621fe5bb8f42c009f2890e84f8 (diff)
reading rd.conf file works now
Diffstat (limited to 'src')
-rw-r--r--src/helsinki.at/rhimport/conf.go39
1 files changed, 34 insertions, 5 deletions
diff --git a/src/helsinki.at/rhimport/conf.go b/src/helsinki.at/rhimport/conf.go
index bd350c3..d482588 100644
--- a/src/helsinki.at/rhimport/conf.go
+++ b/src/helsinki.at/rhimport/conf.go
@@ -24,7 +24,9 @@
package rhimport
-import ()
+import (
+ "github.com/vaughan0/go-ini"
+)
type getPasswordResult struct {
password string
@@ -51,13 +53,34 @@ type Config struct {
done chan bool
}
-func (self Config) getPassword(username string, cached bool) (pwd string, err error) {
+func get_ini_value(file ini.File, section string, key string, dflt string) string {
+ value, ok := file.Get(section, key)
+ if ok {
+ return value
+ }
+ return dflt
+}
+
+func (self *Config) read_config_file() error {
+ file, err := ini.LoadFile(self.configfile)
+ if err != nil {
+ return err
+ }
+
+ self.db_host = get_ini_value(file, "mySQL", "Hostname", "localhost")
+ self.db_user = get_ini_value(file, "mySQL", "Loginname", "rivendell")
+ self.db_passwd = get_ini_value(file, "mySQL", "Password", "letmein")
+ self.db_db = get_ini_value(file, "mySQL", "Database", "rivendell")
+ return nil
+}
+
+func (self *Config) getPassword(username string, cached bool) (pwd string, err error) {
//TODO: actually fetch password from cache or DB
pwd = "12345"
return
}
-func (self Config) dispatchRequests() {
+func (self *Config) dispatchRequests() {
defer func() { self.done <- true }()
for {
select {
@@ -75,7 +98,7 @@ func (self Config) dispatchRequests() {
}
}
-func (self Config) Cleanup() {
+func (self *Config) Cleanup() {
self.quit <- true
<-self.done
close(self.quit)
@@ -87,12 +110,18 @@ func (self Config) Cleanup() {
func NewConfig(configfile, rdxport_endpoint *string) (conf *Config, err error) {
conf = new(Config)
conf.configfile = *configfile
+ err = conf.read_config_file()
+ if err != nil {
+ return
+ }
conf.quit = make(chan bool)
conf.done = make(chan bool)
conf.RDXportEndpoint = *rdxport_endpoint
- //TODO : init db connection
conf.password_cache = make(map[string]string)
conf.getPasswordChan = make(chan getPasswordRequest)
+
+ //TODO : init db connection
+
go conf.dispatchRequests()
return
}