diff options
Diffstat (limited to 'src/rhimportd/main.go')
-rw-r--r-- | src/rhimportd/main.go | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/src/rhimportd/main.go b/src/rhimportd/main.go index 4b0514b..97a12ec 100644 --- a/src/rhimportd/main.go +++ b/src/rhimportd/main.go @@ -34,6 +34,7 @@ import ( "os" "os/signal" "sync" + "time" ) var ( @@ -66,9 +67,33 @@ func (s *envStringValue) Get() interface{} { return string(*s) } func (s *envStringValue) String() string { return fmt.Sprintf("%s", *s) } +type envDurationValue time.Duration + +func newEnvDurationValue(key string, dflt time.Duration) (*envDurationValue, error) { + if envval, exists := os.LookupEnv(key); exists { + var val envDurationValue + err := (&val).Set(envval) + return &val, err + } else { + return (*envDurationValue)(&dflt), nil + } +} + +func (d *envDurationValue) Set(val string) error { + dval, err := time.ParseDuration(val) + *d = envDurationValue(dval) + return err +} + +func (d *envDurationValue) Get() interface{} { return time.Duration(*d) } + +func (d *envDurationValue) String() string { return fmt.Sprintf("%v", *d) } + func main() { webAddr := newEnvStringValue("RHIMPORTD_WEB_ADDR", "localhost:4080") flag.Var(webAddr, "web-addr", "addr:port to listen on (environment: RHIMPORTD_WEB_ADDR)") + webStaticDir := newEnvStringValue("RHIMPORTD_WEB_STATIC_DIR", "/usr/share/rhimportd/web-static/") + flag.Var(webStaticDir, "web-static-dir", "path to static html files (environment: RHIMPORTD_WEB_STATIC_DIR)") telnetAddr := newEnvStringValue("RHIMPORTD_TELNET_ADDR", "localhost:4023") flag.Var(telnetAddr, "telnet-addr", "addr:port to listen on (environment: RHIMPORTD_TELNET_ADDR)") watchDir := newEnvStringValue("RHIMPORTD_WATCH_DIR", "") @@ -81,6 +106,14 @@ func main() { 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)") + + uploadMaxAge, err := newEnvDurationValue("RHIMPORTD_UPLOAD_MAX_AGE", 30*time.Minute) + if err != nil { + rhl.Println("Error parsing RHIMPORTD_UPLOAD_MAX_AGE from environment:", err) + return + } + flag.Var(uploadMaxAge, "upload-max-age", "maximum age of uploaded files before the get deleted (environment: RHIMPORTD_UPLOAD_MAX_AGE)") + help := flag.Bool("help", false, "show usage") flag.Parse() @@ -112,7 +145,7 @@ func main() { go func() { defer wg.Done() rhl.Println("starting web-ctrl") - StartControlWeb(webAddr.Get().(string), conf, db.GetInterface(), sessions.GetInterface()) + StartControlWeb(webAddr.Get().(string), webStaticDir.Get().(string), uploadMaxAge.Get().(time.Duration), conf, db.GetInterface(), sessions.GetInterface()) rhl.Println("web-ctrl finished") }() } |