diff --git a/evaluator.go b/evaluator.go index 37ca6f7..88fb451 100644 --- a/evaluator.go +++ b/evaluator.go @@ -4,6 +4,7 @@ import ( "log" "net/http" "net/url" + "os" "regexp" "strings" ) @@ -26,7 +27,22 @@ func main() { http.Redirect(w, r, searchURL, http.StatusSeeOther) }) - log.Fatalf("Failed to start http server: %v", http.ListenAndServe(":8081", nil)) + listenAddress := getSetting("LISTEN_ADDRESS", ":8081") + log.Printf("Listening at %s", listenAddress) + + log.Fatalf("Failed to start http server: %v", http.ListenAndServe(listenAddress, nil)) +} + +func getenv(name string, fallback string) (value string) { + value = os.Getenv(name) + if value == "" { + return fallback + } + return +} + +func getSetting(name, fallback string) (value string) { + return getenv("BANG_EVALUATOR_"+name, fallback) } func buildSearchURL(template string, query string) (searchUrl string) {