From 235b8f871fdfa35f9595268d194d28a3de655ec0 Mon Sep 17 00:00:00 2001 From: Mitchell Riedstra Date: Sun, 24 Oct 2021 15:57:32 -0400 Subject: Unix sockets for redis. Page use FS interface. Clear redis func. Additionally, Funcs can be passed in. --- cmd/server/main.go | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'cmd/server/main.go') diff --git a/cmd/server/main.go b/cmd/server/main.go index 21f7031..912cba0 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -6,6 +6,8 @@ import ( "log" "net/http" "os" + "strings" + "text/template" "time" "github.com/gomodule/redigo/redis" @@ -73,6 +75,11 @@ func main() { //nolint:funlen MaxActive: 12000, //nolint:gomnd Dial: func() (redis.Conn, error) { c, err := redis.Dial("tcp", *redisAddr) + + if strings.HasPrefix(*redisAddr, "unix:") { + c, err = redis.Dial("unix", strings.TrimPrefix(*redisAddr, "unix:")) + } + if err != nil { log.Println("Redis dial error: ", err) } @@ -87,6 +94,10 @@ func main() { //nolint:funlen os.Stderr.Write(b) } + page.Funcs = template.FuncMap{ + "ClearRedis": app.ClearRedis, + } + srv := &http.Server{ Handler: app, Addr: *listen, -- cgit v1.2.3