package config import ( "fmt" "strconv" "time" ) type Jobs struct { URL string Concurrency, MaxAttempts int Timeout time.Duration } func LoadJobs(lookup Lookup) (Jobs, error) { url, err := secret(lookup, "BROKER_URL_FILE") if err != nil { return Jobs{}, err } c := Jobs{URL: url, Concurrency: 2, MaxAttempts: 5} seconds := 60 for _, p := range []struct { key string value *int max int }{ {"WORKER_CONCURRENCY", &c.Concurrency, 2}, {"JOB_MAX_ATTEMPTS", &c.MaxAttempts, 100}, {"JOB_TIMEOUT_SECONDS", &seconds, 3600}, } { if s, ok := lookup(p.key); ok { n, err := strconv.Atoi(s) if err != nil || n < 1 || n > p.max { return Jobs{}, fmt.Errorf("%s must be between 1 and %d", p.key, p.max) } *p.value = n } } c.Timeout = time.Duration(seconds) * time.Second return c, nil }