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/main.go44
1 files changed, 35 insertions, 9 deletions
diff --git a/src/helsinki.at/rhimportd/main.go b/src/helsinki.at/rhimportd/main.go
index 3d5c0b1..c6090cb 100644
--- a/src/helsinki.at/rhimportd/main.go
+++ b/src/helsinki.at/rhimportd/main.go
@@ -26,6 +26,7 @@ package main
import (
"flag"
+ "fmt"
"helsinki.at/rhimport"
"log"
"os"
@@ -40,13 +41,38 @@ var (
//rhdl = log.New(ioutil.Discard, "[rhimportd-dbg]\t", log.LstdFlags)
)
+type envStringValue string
+
+func newEnvStringValue(key, dflt string) *envStringValue {
+ if envval, exists := os.LookupEnv(key); exists {
+ return (*envStringValue)(&envval)
+ } else {
+ return (*envStringValue)(&dflt)
+ }
+}
+
+func (s *envStringValue) Set(val string) error {
+ *s = envStringValue(val)
+ return nil
+}
+
+func (s *envStringValue) Get() interface{} { return string(*s) }
+
+func (s *envStringValue) String() string { return fmt.Sprintf("%s", *s) }
+
func main() {
- webAddr := flag.String("web-addr", ":4080", "addr:port to listen on")
- telnetAddr := flag.String("telnet-addr", ":4023", "addr:port to listen on")
- rdconf := flag.String("rdconf", "/etc/rd.conf", "path to the Rivendell config file")
- rdxportUrl := flag.String("rdxport-url", "http://localhost/rd-bin/rdxport.cgi", "the url to the Rivendell web-api")
- tempDir := flag.String("tmp-dir", os.TempDir(), "path to temporary files")
- localFetchDir := flag.String("local-fetch-dir", os.TempDir(), "path to files that can be imported using local://")
+ webAddr := newEnvStringValue("RHIMPORTD_WEB_ADDR", "localhost:4080")
+ flag.Var(webAddr, "web-addr", "addr:port to listen on (environment: RHIMPORTD_WEB_ADDR)")
+ telnetAddr := newEnvStringValue("RHIMPORTD_TELNET_ADDR", "localhost:4023")
+ flag.Var(telnetAddr, "telnet-addr", "addr:port to listen on (environment: RHIMPORTD_TELNET_ADDR)")
+ rdconf := newEnvStringValue("RHIMPORTD_RD_CONF", "/etc/rd.conf")
+ flag.Var(rdconf, "rdconf", "path to the Rivendell config file (environment: RHIMPORTD_RD_CONF)")
+ rdxportUrl := newEnvStringValue("RHIMPORTD_RDXPORT_URL", "http://localhost/rd-bin/rdxport.cgi")
+ flag.Var(rdxportUrl, "rdxport-url", "the url to the Rivendell web-api (environment: RHIMPORTD_RDXPORT_URL)")
+ tempDir := newEnvStringValue("RHIMPORTD_TEMP_DIR", os.TempDir())
+ flag.Var(tempDir, "tmp-dir", "path to temporary files (environment: RHIMPORTD_TEMP_DIR)")
+ localFetchDir := newEnvStringValue("RHIMPORTD_LOCAL_FETCH_DIR", os.TempDir())
+ flag.Var(localFetchDir, "local-fetch-dir", "base path for local:// urls (environment: RHIMPORTD_LOCAL_FETCH_DIR)")
help := flag.Bool("help", false, "show usage")
flag.Parse()
@@ -55,7 +81,7 @@ func main() {
return
}
- conf, err := rhimport.NewConfig(rdconf, rdxportUrl, tempDir, localFetchDir)
+ conf, err := rhimport.NewConfig(rdconf.Get().(string), rdxportUrl.Get().(string), tempDir.Get().(string), localFetchDir.Get().(string))
if err != nil {
rhl.Println("Error reading configuration:", err)
return
@@ -81,7 +107,7 @@ func main() {
go func() {
defer wg.Done()
rhl.Println("starting web-ctrl")
- StartControlWeb(*webAddr, conf, rddb.GetInterface(), sessions.GetInterface())
+ StartControlWeb(webAddr.Get().(string), conf, rddb.GetInterface(), sessions.GetInterface())
rhl.Println("web-ctrl finished")
}()
@@ -89,7 +115,7 @@ func main() {
go func() {
defer wg.Done()
rhl.Println("starting telnet-ctrl")
- StartControlTelnet(*telnetAddr, conf, rddb.GetInterface(), sessions.GetInterface())
+ StartControlTelnet(telnetAddr.Get().(string), conf, rddb.GetInterface(), sessions.GetInterface())
rhl.Println("telnet-ctrl finished")
}()