summaryrefslogtreecommitdiff
path: root/src/helsinki.at/rhimportd
diff options
context:
space:
mode:
Diffstat (limited to 'src/helsinki.at/rhimportd')
-rw-r--r--src/helsinki.at/rhimportd/ctrlWeb.go39
-rw-r--r--src/helsinki.at/rhimportd/log.go9
-rw-r--r--src/helsinki.at/rhimportd/rhimportd.go16
3 files changed, 50 insertions, 14 deletions
diff --git a/src/helsinki.at/rhimportd/ctrlWeb.go b/src/helsinki.at/rhimportd/ctrlWeb.go
index 04180ae..275f095 100644
--- a/src/helsinki.at/rhimportd/ctrlWeb.go
+++ b/src/helsinki.at/rhimportd/ctrlWeb.go
@@ -32,12 +32,39 @@ import (
_ "net/http/pprof"
)
-func StartControlWeb(addr_s string) {
- http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
- fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
- ctx := new(rhimport.ImportContext)
- rhimport.ImportFile(ctx)
- })
+type webHandler struct {
+ *rhimport.Config
+ H func(*rhimport.Config, http.ResponseWriter, *http.Request) (int, error)
+}
+
+func (self webHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+ status, err := self.H(self.Config, w, r)
+ if err != nil {
+ switch status {
+ case http.StatusNotFound:
+ http.NotFound(w, r)
+ default:
+ http.Error(w, fmt.Sprintf("%s: %s", http.StatusText(status), err), status)
+ }
+ }
+}
+
+func IndexHandler(conf *rhimport.Config, w http.ResponseWriter, r *http.Request) (status int, err error) {
+
+ ctx := rhimport.NewImportContext(conf, "hugo", "test", 17324)
+ ctx.SourceFile = html.EscapeString(r.URL.Path)
+ ctx.DeleteSourceFile = true
+
+ if err = rhimport.ImportFile(ctx); err != nil {
+ status = http.StatusInternalServerError
+ } else {
+ status = http.StatusOK
+ }
+ return
+}
+
+func StartControlWeb(addr_s string, conf *rhimport.Config) {
+ http.Handle("/", webHandler{conf, IndexHandler})
rhl.Println("listening on", addr_s)
http.ListenAndServe(addr_s, nil)
diff --git a/src/helsinki.at/rhimportd/log.go b/src/helsinki.at/rhimportd/log.go
index 5ff3e6d..d122e55 100644
--- a/src/helsinki.at/rhimportd/log.go
+++ b/src/helsinki.at/rhimportd/log.go
@@ -25,14 +25,13 @@
package main
import (
- "io/ioutil"
+ // "io/ioutil"
"log"
"os"
)
var (
- rhl = log.New(os.Stderr, "[rhimport]\t", log.LstdFlags)
- // use ioutil.Discard to switch that thing off
- // rhtl = log.New(os.Stderr, "[rhdbg]\t", log.LstdFlags)
- rhtl = log.New(ioutil.Discard, "[rhimport-dbg]\t", log.LstdFlags)
+ rhl = log.New(os.Stderr, "[rhimportd]\t", log.LstdFlags)
+ rhdl = log.New(os.Stderr, "[rhimportd-dbg]\t", log.LstdFlags)
+ //rhdl = log.New(ioutil.Discard, "[rhimportd-dbg]\t", log.LstdFlags)
)
diff --git a/src/helsinki.at/rhimportd/rhimportd.go b/src/helsinki.at/rhimportd/rhimportd.go
index b73df95..7fb62b6 100644
--- a/src/helsinki.at/rhimportd/rhimportd.go
+++ b/src/helsinki.at/rhimportd/rhimportd.go
@@ -26,6 +26,7 @@ package main
import (
"flag"
+ "helsinki.at/rhimport"
"os"
"os/signal"
"sync"
@@ -33,6 +34,8 @@ import (
func main() {
addr_s := flag.String("addr", ":4000", "addr:port to listen on, default: ':4000'")
+ rdconf_s := flag.String("rdconf", "/etc/rd.conf", "path to the Rivendell config file, default: '/etc/rd.conf'")
+ rdxport_url_s := flag.String("rdxport-url", "http://localhost/rd-bin/rdxport.cgi", "the url to the Rivendell web-api, default: 'http://localhost/rd-bin/rdxport.cgi'")
help := flag.Bool("help", false, "show usage")
flag.Parse()
@@ -41,14 +44,21 @@ func main() {
return
}
+ conf, err := rhimport.NewConfig(rdconf_s, rdxport_url_s)
+ if err != nil {
+ rhl.Println("Error reading configuration:", err)
+ return
+ }
+ defer conf.Cleanup()
+
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
- rhl.Println("start web-srv")
- StartControlWeb(*addr_s)
- rhl.Println("web finished")
+ rhl.Println("start web-ctrl")
+ StartControlWeb(*addr_s, conf)
+ rhl.Println("web-ctrl finished")
}()
alldone := make(chan bool)