diff --git a/.gitignore b/.gitignore index 00b2937..f91ae19 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ # Test binary, built with `go test -c` *.test +plakken # Output of the go coverage tool, specifically when used with LiteIDE *.out diff --git a/config.go b/config.go new file mode 100644 index 0000000..e6eef3f --- /dev/null +++ b/config.go @@ -0,0 +1,46 @@ +package main + +import ( + "os" + "strconv" +) + +type config struct { + host string + port string + redisAddr string + redisUser string + redisPassword string + redisDB int +} + +func setConfig() config { + host := os.Getenv("PLAKKEN_HOST") + + port := os.Getenv("PLAKKEN_PORT") + if port == "" { + port = "3000" + } + redisAddr := os.Getenv("PLAKKEN_REDIS_ADDR") + if redisAddr == "" { + redisAddr = "localhost:6379" + } + + redisUser := os.Getenv("PLAKKEN_REDIS_USER") + redisPassword := os.Getenv("PLAKKEN_REDIS_PASSWORD") + redisDB, err := strconv.Atoi(os.Getenv("PLAKKEN_REDIS_DB")) + if err != nil { + redisDB = 0 + } + + s := config{ + host: host, + port: port, + redisAddr: redisAddr, + redisUser: redisUser, + redisPassword: redisPassword, + redisDB: redisDB, + } + + return s +} diff --git a/main.go b/main.go index 373757f..82b3630 100644 --- a/main.go +++ b/main.go @@ -6,14 +6,8 @@ import ( ) func main() { - i := 0 - i = 5 - - var k int8 = 0 - - fmt.Println(i) - fmt.Println(k) - + currentConfig := setConfig() + listen := currentConfig.host + ":" + currentConfig.port http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { _, err := fmt.Fprintf(w, "Hello, you're at %s", r.URL.Path) if err != nil { @@ -21,7 +15,7 @@ func main() { } }) - err := http.ListenAndServe(":8080", nil) + err := http.ListenAndServe(listen, nil) if err != nil { return }