diff --git a/README.md b/README.md index f955b84..6b69731 100644 --- a/README.md +++ b/README.md @@ -15,16 +15,18 @@ docker pull syahidfrd/asynqmon-handler[:tag] ``` docker run --rm \ --name asynqmon-handler \ + -e ASYNQMON_USER=admin \ + -e ASYNQMON_PASSWORD=secure123 \ -p 3000:3000 \ - syahidfrd/asynqmon-handler --auth-password=secure123 + syahidfrd/asynqmon-handler ``` -Here's the available flags: +Here's the available env: -| Flag | Default | Description | -|--------------------------|--------------|----------------------------| -| `--auth-username`(string) | `admin` | Basic auth username | -| `--auth-password`(string) | `admin` | Basic auth password | -| `--redis-addr`(string) | `:6379` | Address of redis server | +| Env | Default | Description | +|---------------------|---------|-------------------| +| `ASYNQMON_USER` | `admin` | Asynqmon user | +| `ASYNQMON_PASSWORD` | `admin` | Asynqmon password | +| `REDIS_ADDR` | `:6379` | Redis address | Next, go to [localhost:3000](http://localhost:3000) and see Asynqmon dashboard \ No newline at end of file diff --git a/main.go b/main.go index 3982814..916c8ef 100644 --- a/main.go +++ b/main.go @@ -3,9 +3,9 @@ package main import ( "crypto/sha256" "crypto/subtle" - "flag" "log" "net/http" + "os" "github.com/hibiken/asynq" "github.com/hibiken/asynqmon" @@ -19,24 +19,20 @@ type application struct { } func main() { - authUsername := flag.String("auth-username", "admin", "basic auth username") - authPassword := flag.String("auth-password", "admin", "basic auth password") - redisAddr := flag.String("redis-addr", ":6379", "redis address") - - flag.Parse() + asynqmonUser := getenv("ASYNQMON_USER", "admin") + asynqmonPassword := getenv("ASYNQMON_PASSWORD", "admin") + redisAddr := getenv("REDIS_ADDR", ":6379") app := new(application) - app.auth.username = *authUsername - app.auth.password = *authPassword + app.auth.username = asynqmonUser + app.auth.password = asynqmonPassword h := asynqmon.New(asynqmon.Options{ RootPath: "/", - RedisConnOpt: asynq.RedisClientOpt{Addr: *redisAddr}, + RedisConnOpt: asynq.RedisClientOpt{Addr: redisAddr}, }) http.Handle(h.RootPath()+"/", app.basicAuth(h)) - - log.Print("Server is up on 3000 port") log.Fatal(http.ListenAndServe(":3000", nil)) } @@ -62,3 +58,11 @@ func (app *application) basicAuth(next *asynqmon.HTTPHandler) http.HandlerFunc { http.Error(w, "Unauthorized", http.StatusUnauthorized) }) } + +func getenv(key, fallback string) string { + value := os.Getenv(key) + if len(value) == 0 { + return fallback + } + return value +}