Commit 29129658 authored by Artemis's avatar Artemis

Fixed default values

parent 64b76690
...@@ -9,6 +9,6 @@ Small temp redis-based pastebin server. ...@@ -9,6 +9,6 @@ Small temp redis-based pastebin server.
Environment variables Environment variables
===================== =====================
- ``HTTP_HOST`` (default ``:1234``): HTTP listening interface host - ``HTTP_HOST`` (default ``127.0.0.1:1234``): HTTP listening interface host
- ``REDIS_ADDR`` (required): Redis URL - ``REDIS_ADDR`` (default ``127.0.0.1:6379``): Redis URL
- ``REDIS_PASS`` (optional, default ""): Redis password - ``REDIS_PASS`` (default ""): Redis password
...@@ -12,14 +12,6 @@ import ( ...@@ -12,14 +12,6 @@ import (
"time" "time"
) )
func getEnv(key string) string {
val := os.Getenv(key)
if len(val) == 0 {
panic(key + " is a required environment variable key")
}
return val
}
func getEnvDefault(key string, defaultVal string) string { func getEnvDefault(key string, defaultVal string) string {
val := os.Getenv(key) val := os.Getenv(key)
if len(val) == 0 { if len(val) == 0 {
...@@ -59,7 +51,7 @@ var NotFoundErr = "This document could not be found. Maybe it expired? Remember ...@@ -59,7 +51,7 @@ var NotFoundErr = "This document could not be found. Maybe it expired? Remember
func main() { func main() {
backend := redis.NewClient(&redis.Options{ backend := redis.NewClient(&redis.Options{
Addr: getEnv("REDIS_ADDR"), Addr: getEnvDefault("REDIS_ADDR", "127.0.0.1:6379"),
Password: getEnvDefault("REDIS_PASS", ""), Password: getEnvDefault("REDIS_PASS", ""),
DB: 0, DB: 0,
}) })
...@@ -171,7 +163,7 @@ func main() { ...@@ -171,7 +163,7 @@ func main() {
http.ServeFile(w, req, "privacy.html") http.ServeFile(w, req, "privacy.html")
}) })
host := getEnvDefault("HTTP_HOST", ":1234") host := getEnvDefault("HTTP_HOST", "127.0.0.1:1234")
fmt.Printf("HTTP server about to start listening on %s\n", host) fmt.Printf("HTTP server about to start listening on %s\n", host)
log.Fatal(http.ListenAndServe(host, r)) log.Fatal(http.ListenAndServe(host, r))
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment