feat: Introduce env for bind address

This commit is contained in:
ptrcnull 2023-04-11 01:56:21 +02:00
parent cda0a8f737
commit 5fb29668c8
Signed by: ptrcnull
GPG key ID: 411F7B30801DD9CA
2 changed files with 7 additions and 2 deletions

View file

@ -6,4 +6,5 @@
Environmental variables:
- `SHORTEN_HOST` - hostname
- `POSTGRES_URI` - lib/pq connection string (see [here](https://pkg.go.dev/github.com/lib/pq#section-documentation))
- `SHORTEN_BIND` - bind address (default: `127.0.0.1:4488`)
- `POSTGRES_URI` - lib/pq connection string (see [here](https://pkg.go.dev/github.com/lib/pq#section-documentation))

View file

@ -71,7 +71,11 @@ func main() {
panic(err)
}
panic(http.ListenAndServe("127.0.0.1:4488", &Handler{db: db}))
bind := os.Getenv("SHORTEN_BIND")
if bind == "" {
bind = "127.0.0.1:4488"
}
panic(http.ListenAndServe(bind, &Handler{db: db}))
}
type Handler struct {