From 7a7cb8d64e4f5cb2865e381bd4bad21d96f8c50c Mon Sep 17 00:00:00 2001 From: Joerg Lehmann Date: Wed, 20 Jul 2022 18:14:51 +0200 Subject: [PATCH] module support, make container ready --- go.mod | 5 +++++ go.sum | 12 ++++++++++++ persistence.go | 11 ++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 go.mod create mode 100644 go.sum diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..ff8e457 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module nbit.ch/mini-beieli-lorahandler/v2 + +go 1.17 + +require github.com/gomodule/redigo v1.8.9 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..6c8a5ca --- /dev/null +++ b/go.sum @@ -0,0 +1,12 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/gomodule/redigo v1.8.9 h1:Sl3u+2BI/kk+VEatbj0scLdrFhjPmbxOc1myhDP41ws= +github.com/gomodule/redigo v1.8.9/go.mod h1:7ArFNvsTjH8GMMzB4uy1snslv2BwmginuMs06a1uzZE= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/persistence.go b/persistence.go index a36ec08..45e5143 100644 --- a/persistence.go +++ b/persistence.go @@ -3,6 +3,7 @@ package main import ( "fmt" "github.com/gomodule/redigo/redis" + "os" "strconv" "time" ) @@ -12,6 +13,14 @@ var globalPool *redis.Pool const lastvaluesPrefix string = "lastvalues:" const devPrefix string = "dev:" +func getenv(key, fallback string) string { + value := os.Getenv(key) + if len(value) == 0 { + return fallback + } + return value +} + type CalSettings struct { w1_0 int32 w2_0 int32 @@ -28,7 +37,7 @@ func newPool() *redis.Pool { // Dial is an application supplied function for creating and // configuring a connection. Dial: func() (redis.Conn, error) { - c, err := redis.Dial("tcp", ":6379") + c, err := redis.Dial("tcp", getenv("REDIS_CONNECTION_STRING", ":6379")) if err != nil { panic(err.Error()) }