Make listen address configurable

This commit is contained in:
Simon Bruder 2021-01-05 12:40:26 +01:00
parent dec28b98f6
commit 0be60e1458
Signed by: simon
GPG key ID: 8D3C82F9F309F8EC

View file

@ -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) {