diff --git a/connection/connection.go b/connection/connection.go index 8f3bb11..1f7acc5 100644 --- a/connection/connection.go +++ b/connection/connection.go @@ -23,13 +23,26 @@ func OpenConnection() *RedisConnection { log.Fatal(conn_err) } - return &RedisConnection{conn} + c := &RedisConnection{conn} + go c.periodicKeepAlive() + + return c } type RedisConnection struct { redis.Conn } +// Every minute send a Ping signal to redis so that we dont run into a timeout +func (self *RedisConnection) periodicKeepAlive() { + c := time.Tick(1 * time.Minute) + + for _ = range c { + _, err := self.Do("PING") + HandleErr(err) + } +} + func (self *RedisConnection) GetHost(name string) *Host { host := Host{Hostname: name} diff --git a/ddns.go b/ddns.go index e33fffc..def7bd8 100644 --- a/ddns.go +++ b/ddns.go @@ -5,10 +5,10 @@ import ( "fmt" "github.com/gin-gonic/gin" "github.com/pboehm/ddns/connection" + "html/template" "log" "net" "net/http" - "html/template" "os" "strings" ) @@ -63,19 +63,19 @@ func RunWebService() { conn := connection.OpenConnection() defer conn.Close() + // Add index template from bindata + index_content, err := Asset("templates/index.html") + HandleErr(err) + + html, err := template.New("index.html").Parse(string(index_content)) + HandleErr(err) + r := gin.Default() + r.HTMLTemplates = html - // Add index template from bindata - index_content, err := Asset("templates/index.html") - HandleErr(err) - - html, err := template.New("index.html").Parse(string(index_content)) - HandleErr(err) - r.HTMLTemplates = html - - r.GET("/", func (g *gin.Context) { - g.HTML(200, "index.html", nil) - }) + r.GET("/", func(g *gin.Context) { + g.HTML(200, "index.html", nil) + }) r.GET("/new/:hostname", func(c *gin.Context) { hostname := c.Params.ByName("hostname")