Skip to content

Commit

Permalink
peephole: Add env variable defaults
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Wicki <[email protected]>
  • Loading branch information
gandro committed Apr 29, 2024
1 parent 7027547 commit e86890e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ Prosody room statistics for one single room (configured via `PEEPHOLE_ROOM_NAME`
## Environment variables

- `PEEPHOLE_ROOM_NAME` _(required)_: Room name for which statistics are exposed (example: `[email protected]`)
- `PEEPHOLE_HTTP_ADDR` _(required)_: Address on which the peephole HTTP server will listen on (example: `:8080`)
- `XMPP_SERVER` _(required)_: Hostname of the Prosody HTTP service (example: `xmpp.meet.jitsi`)
- `PROSODY_HTTP_PORT` _(required)_: Port of the Prosody HTTP service (example `5280`)
- `PEEPHOLE_HTTP_ADDR` _(default `:9339`)_: Address on which the peephole HTTP server will listen on
- `XMPP_SERVER` _(default `xmpp.meet.jitsi`)_: Hostname of the Prosody HTTP service
- `PROSODY_HTTP_PORT` _(default `5280`)_: Port of the Prosody HTTP service
18 changes: 13 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (
)

var (
roomName = envVar("PEEPHOLE_ROOM_NAME")
httpAddr = envVar("PEEPHOLE_HTTP_ADDR")
roomName = envRequired("PEEPHOLE_ROOM_NAME")
httpAddr = envOrDefault("PEEPHOLE_HTTP_ADDR", ":9339")

prosodyHTTPHost = envVar("XMPP_SERVER")
prosodyHTTPPort = envVar("PROSODY_HTTP_PORT")
prosodyHTTPHost = envOrDefault("XMPP_SERVER", "xmpp.meet.jitsi")
prosodyHTTPPort = envOrDefault("PROSODY_HTTP_PORT", "5280")

roomCensusURL = (&url.URL{
Scheme: "http",
Expand All @@ -25,7 +25,7 @@ var (
}).String()
)

func envVar(name string) string {
func envRequired(name string) string {
val := os.Getenv(name)
if val == "" {
slog.Error("missing environment variable", slog.String("name", name))
Expand All @@ -34,6 +34,14 @@ func envVar(name string) string {
return val
}

func envOrDefault(name, fallback string) string {
val := os.Getenv(name)
if val == "" {
return fallback
}
return val
}

type room struct {
RoomName string `json:"room_name"`
Participants int `json:"participants"`
Expand Down

0 comments on commit e86890e

Please sign in to comment.