From 621109ae49193064baba2da216ae07c6c435abc1 Mon Sep 17 00:00:00 2001 From: Brandur Date: Mon, 16 Sep 2024 08:01:10 -0700 Subject: [PATCH] Small code clean up for env vars + CHANGELOG entry Follows up #157 with some small clean up to how env vars are handled, a doc string making it clear that `HOST` is not require and may be left empty, along with a CHANGELOG entry. --- CHANGELOG.md | 6 ++++++ cmd/riverui/main.go | 17 ++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05c32b5c..5fc0fae3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Allow `HOST` variable to specify specific host variable to bind to. [PR #157](https://github.com/riverqueue/riverui/pull/157). + ## [0.5.3] - 2024-09-05 +### Fixed + - Remove `.gitignore` from Go module bundle because it messes with vendoring in some situations. Thanks [Pedro Henrique](https://github.com/crossworth)! 🙏🏻 [PR #149](https://github.com/riverqueue/riverui/pull/149). ## [0.5.2] - 2024-09-02 diff --git a/cmd/riverui/main.go b/cmd/riverui/main.go index d05ad848..0470695c 100644 --- a/cmd/riverui/main.go +++ b/cmd/riverui/main.go @@ -1,6 +1,7 @@ package main import ( + "cmp" "context" "errors" "flag" @@ -54,15 +55,13 @@ func initAndServe(ctx context.Context) int { } pathPrefix = riverui.NormalizePathPrefix(pathPrefix) - corsOriginString := os.Getenv("CORS_ORIGINS") - corsOrigins := strings.Split(corsOriginString, ",") - dbURL := mustEnv("DATABASE_URL") - otelEnabled := os.Getenv("OTEL_ENABLED") == "true" - host := os.Getenv("HOST") - port := os.Getenv("PORT") - if port == "" { - port = "8080" - } + var ( + corsOrigins = strings.Split(os.Getenv("CORS_ORIGINS"), ",") + dbURL = mustEnv("DATABASE_URL") + host = os.Getenv("HOST") // may be left empty to bind to all local interfaces + otelEnabled = os.Getenv("OTEL_ENABLED") == "true" + port = cmp.Or(os.Getenv("PORT"), "8080") + ) dbPool, err := getDBPool(ctx, dbURL) if err != nil {