From 89f0eec04192fa849a9f0d6a2eec697686ff3540 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Fri, 4 Dec 2015 01:56:43 +0100 Subject: reading rd.conf file works now diff --git a/Makefile b/Makefile index 5de8b45..a1b5259 100644 --- a/Makefile +++ b/Makefile @@ -27,6 +27,7 @@ GOCMD := go getlibs: export GOPATH=$(curdir) getlibs: + $(GOCMD) get "github.com/vaughan0/go-ini" # $(GOCMD) get "github.com/gorilla/websocket" vet: export GOPATH=$(curdir) 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 } -- cgit v0.10.2