add root_path to flag and env options

This commit is contained in:
“San 2023-07-11 17:41:38 +07:00
parent d1b889456d
commit b99e08aafa

View File

@ -25,6 +25,9 @@ type Config struct {
// Server port // Server port
Port int Port int
// Server path url
RootPath string
// Redis connection options // Redis connection options
RedisAddr string RedisAddr string
RedisDB int RedisDB int
@ -72,6 +75,7 @@ func parseFlags(progname string, args []string) (cfg *Config, output string, err
flags.BoolVar(&conf.EnableMetricsExporter, "enable-metrics-exporter", getEnvOrDefaultBool("ENABLE_METRICS_EXPORTER", false), "enable prometheus metrics exporter to expose queue metrics") flags.BoolVar(&conf.EnableMetricsExporter, "enable-metrics-exporter", getEnvOrDefaultBool("ENABLE_METRICS_EXPORTER", false), "enable prometheus metrics exporter to expose queue metrics")
flags.StringVar(&conf.PrometheusServerAddr, "prometheus-addr", getEnvDefaultString("PROMETHEUS_ADDR", ""), "address of prometheus server to query time series") flags.StringVar(&conf.PrometheusServerAddr, "prometheus-addr", getEnvDefaultString("PROMETHEUS_ADDR", ""), "address of prometheus server to query time series")
flags.BoolVar(&conf.ReadOnly, "read-only", getEnvOrDefaultBool("READ_ONLY", false), "restrict to read-only mode") flags.BoolVar(&conf.ReadOnly, "read-only", getEnvOrDefaultBool("READ_ONLY", false), "restrict to read-only mode")
flags.StringVar(&conf.RootPath, "root-path", getEnvDefaultString("ROOT_PATH", "/"), "root path prefix for url")
err = flags.Parse(args) err = flags.Parse(args)
if err != nil { if err != nil {
@ -153,6 +157,7 @@ func main() {
ResultFormatter: asynqmon.ResultFormatterFunc(resultFormatterFunc(cfg)), ResultFormatter: asynqmon.ResultFormatterFunc(resultFormatterFunc(cfg)),
PrometheusAddress: cfg.PrometheusServerAddr, PrometheusAddress: cfg.PrometheusServerAddr,
ReadOnly: cfg.ReadOnly, ReadOnly: cfg.ReadOnly,
RootPath: cfg.RootPath,
}) })
defer h.Close() defer h.Close()