Skip to content

Commit

Permalink
Support environment variables in URL / listener configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
fancycode committed May 13, 2024
1 parent 0c6ce1b commit dfd080c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
4 changes: 3 additions & 1 deletion proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import (

"github.com/dlintw/goconf"
"github.com/gorilla/mux"

signaling "github.com/strukturag/nextcloud-spreed-signaling"
)

var (
Expand Down Expand Up @@ -90,7 +92,7 @@ func main() {
}
defer proxy.Stop()

if addr, _ := config.GetString("http", "listen"); addr != "" {
if addr, _ := signaling.GetStringOptionWithEnv(config, "http", "listen"); addr != "" {
readTimeout, _ := config.GetInt("http", "readtimeout")
if readTimeout <= 0 {
readTimeout = defaultReadTimeout
Expand Down
2 changes: 1 addition & 1 deletion proxy/proxy_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func (s *ProxyServer) checkOrigin(r *http.Request) bool {
}

func (s *ProxyServer) Start(config *goconf.ConfigFile) error {
s.url, _ = config.GetString("mcu", "url")
s.url, _ = signaling.GetStringOptionWithEnv(config, "mcu", "url")
if s.url == "" {
return fmt.Errorf("No MCU server url configured")
}
Expand Down
2 changes: 1 addition & 1 deletion proxy_config_static.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (p *proxyConfigStatic) configure(config *goconf.ConfigFile, fromReload bool
remove[u] = ips
}

mcuUrl, _ := config.GetString("mcu", "url")
mcuUrl, _ := GetStringOptionWithEnv(config, "mcu", "url")
for _, u := range strings.Split(mcuUrl, " ") {
u = strings.TrimSpace(u)
if u == "" {
Expand Down
10 changes: 5 additions & 5 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func main() {

signaling.RegisterStats()

natsUrl, _ := config.GetString("nats", "url")
natsUrl, _ := signaling.GetStringOptionWithEnv(config, "nats", "url")
if natsUrl == "" {
natsUrl = nats.DefaultURL
}
Expand Down Expand Up @@ -224,7 +224,7 @@ func main() {
log.Fatal("Could not create hub: ", err)
}

mcuUrl, _ := config.GetString("mcu", "url")
mcuUrl, _ := signaling.GetStringOptionWithEnv(config, "mcu", "url")
mcuType, _ := config.GetString("mcu", "type")
if mcuType == "" && mcuUrl != "" {
log.Printf("WARNING: Old-style MCU configuration detected with url but no type, defaulting to type %s", signaling.McuTypeJanus)
Expand Down Expand Up @@ -274,7 +274,7 @@ func main() {
if config, err = goconf.ReadConfigFile(*configFlag); err != nil {
log.Printf("Could not read configuration from %s: %s", *configFlag, err)
} else {
mcuUrl, _ = config.GetString("mcu", "url")
mcuUrl, _ = signaling.GetStringOptionWithEnv(config, "mcu", "url")
mcuType, _ = config.GetString("mcu", "type")
if mcuType == "" && mcuUrl != "" {
log.Printf("WARNING: Old-style MCU configuration detected with url but no type, defaulting to type %s", signaling.McuTypeJanus)
Expand Down Expand Up @@ -328,7 +328,7 @@ func main() {

var listeners Listeners

if saddr, _ := config.GetString("https", "listen"); saddr != "" {
if saddr, _ := signaling.GetStringOptionWithEnv(config, "https", "listen"); saddr != "" {
cert, _ := config.GetString("https", "certificate")
key, _ := config.GetString("https", "key")
if cert == "" || key == "" {
Expand Down Expand Up @@ -366,7 +366,7 @@ func main() {
}
}

if addr, _ := config.GetString("http", "listen"); addr != "" {
if addr, _ := signaling.GetStringOptionWithEnv(config, "http", "listen"); addr != "" {
readTimeout, _ := config.GetInt("http", "readtimeout")
if readTimeout <= 0 {
readTimeout = defaultReadTimeout
Expand Down

0 comments on commit dfd080c

Please sign in to comment.