summaryrefslogtreecommitdiff
path: root/src/helsinki.at/rhimportd
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2015-12-07 16:16:40 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-12-08 00:34:53 (GMT)
commita1b290f026011276f9c16f6af390a2aceb2f9ccc (patch)
tree2f7be9167b918b16c82d3f71f057a610f6ca749e /src/helsinki.at/rhimportd
parent6e5d14f4a2189dbc0f0404c398d11878e356ecd7 (diff)
moved DB into seperate module
Diffstat (limited to 'src/helsinki.at/rhimportd')
-rw-r--r--src/helsinki.at/rhimportd/ctrlWeb.go11
-rw-r--r--src/helsinki.at/rhimportd/ctrlWebSimple.go8
-rw-r--r--src/helsinki.at/rhimportd/rhimportd.go10
3 files changed, 18 insertions, 11 deletions
diff --git a/src/helsinki.at/rhimportd/ctrlWeb.go b/src/helsinki.at/rhimportd/ctrlWeb.go
index 5a76f15..e5f74b7 100644
--- a/src/helsinki.at/rhimportd/ctrlWeb.go
+++ b/src/helsinki.at/rhimportd/ctrlWeb.go
@@ -32,17 +32,18 @@ import (
type webHandler struct {
*rhimport.Config
+ *rhimport.RDDB
trusted bool
- H func(*rhimport.Config, bool, http.ResponseWriter, *http.Request)
+ H func(*rhimport.Config, *rhimport.RDDB, bool, http.ResponseWriter, *http.Request)
}
func (self webHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
- self.H(self.Config, self.trusted, w, r)
+ self.H(self.Config, self.RDDB, self.trusted, w, r)
}
-func StartControlWeb(addr_s string, conf *rhimport.Config) {
- http.Handle("/public/simple", webHandler{conf, false, webSimpleHandler})
- http.Handle("/trusted/simple", webHandler{conf, true, webSimpleHandler})
+func StartControlWeb(addr_s string, conf *rhimport.Config, rddb *rhimport.RDDB) {
+ http.Handle("/public/simple", webHandler{conf, rddb, false, webSimpleHandler})
+ http.Handle("/trusted/simple", webHandler{conf, rddb, true, webSimpleHandler})
rhl.Println("listening on", addr_s)
http.ListenAndServe(addr_s, nil)
diff --git a/src/helsinki.at/rhimportd/ctrlWebSimple.go b/src/helsinki.at/rhimportd/ctrlWebSimple.go
index 8080514..f4c64ee 100644
--- a/src/helsinki.at/rhimportd/ctrlWebSimple.go
+++ b/src/helsinki.at/rhimportd/ctrlWebSimple.go
@@ -67,7 +67,7 @@ func webSimpleResponse(w http.ResponseWriter) {
encoder.Encode(respdata)
}
-func webSimpleParseRequest(conf *rhimport.Config, trusted bool, r *http.Request) (ctx *rhimport.ImportContext, err error) {
+func webSimpleParseRequest(conf *rhimport.Config, rddb *rhimport.RDDB, trusted bool, r *http.Request) (ctx *rhimport.ImportContext, err error) {
decoder := json.NewDecoder(r.Body)
var reqdata webSimpleRequestData
@@ -80,7 +80,7 @@ func webSimpleParseRequest(conf *rhimport.Config, trusted bool, r *http.Request)
if trusted {
username = r.Header.Get("X-Forwarded-User")
}
- ctx = rhimport.NewImportContext(conf, username, reqdata.GroupName)
+ ctx = rhimport.NewImportContext(conf, rddb, username, reqdata.GroupName)
ctx.Password = reqdata.Password
ctx.Trusted = trusted
ctx.Cart = reqdata.Cart
@@ -93,12 +93,12 @@ func webSimpleParseRequest(conf *rhimport.Config, trusted bool, r *http.Request)
return
}
-func webSimpleHandler(conf *rhimport.Config, trusted bool, w http.ResponseWriter, r *http.Request) {
+func webSimpleHandler(conf *rhimport.Config, rddb *rhimport.RDDB, trusted bool, w http.ResponseWriter, r *http.Request) {
rhdl.Printf("SimpleHandler: request for '%s'", html.EscapeString(r.URL.Path))
var ctx *rhimport.ImportContext
var err error
- if ctx, err = webSimpleParseRequest(conf, trusted, r); err != nil {
+ if ctx, err = webSimpleParseRequest(conf, rddb, trusted, r); err != nil {
webSimpleErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
diff --git a/src/helsinki.at/rhimportd/rhimportd.go b/src/helsinki.at/rhimportd/rhimportd.go
index 03d0340..7cdc67b 100644
--- a/src/helsinki.at/rhimportd/rhimportd.go
+++ b/src/helsinki.at/rhimportd/rhimportd.go
@@ -50,7 +50,13 @@ func main() {
rhl.Println("Error reading configuration:", err)
return
}
- defer conf.Cleanup()
+
+ rddb, err := rhimport.NewRDDB(conf)
+ if err != nil {
+ rhl.Println("Error initializing Rivdenll DB:", err)
+ return
+ }
+ defer rddb.Cleanup()
var wg sync.WaitGroup
@@ -58,7 +64,7 @@ func main() {
go func() {
defer wg.Done()
rhl.Println("start web-ctrl")
- StartControlWeb(*web_addr_s, conf)
+ StartControlWeb(*web_addr_s, conf, rddb)
rhl.Println("web-ctrl finished")
}()