diff options
author | Christian Pointner <equinox@helsinki.at> | 2016-04-02 15:35:41 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2016-04-02 15:35:41 (GMT) |
commit | 24420034428f6bafc41b34e9b8a6316b4f2aa65e (patch) | |
tree | f1daefafe8148f60cce4581c9e35626c8c7b2c28 /src/rhimportd/main.go | |
parent | c69154b5c1e35ef038f00661e66fcb90113891bf (diff) |
upload cleaner works now
Diffstat (limited to 'src/rhimportd/main.go')
-rw-r--r-- | src/rhimportd/main.go | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/rhimportd/main.go b/src/rhimportd/main.go index 4b0514b..68b0177 100644 --- a/src/rhimportd/main.go +++ b/src/rhimportd/main.go @@ -34,6 +34,7 @@ import ( "os" "os/signal" "sync" + "time" ) var ( @@ -66,6 +67,28 @@ 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)") @@ -81,6 +104,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 +143,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), uploadMaxAge.Get().(time.Duration), conf, db.GetInterface(), sessions.GetInterface()) rhl.Println("web-ctrl finished") }() } |