Make listen address configurable
This commit is contained in:
parent
dec28b98f6
commit
0be60e1458
18
evaluator.go
18
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) {
|
||||
|
|
Loading…
Reference in a new issue