From 7e10a80319ddbcc0c04c45aee5efee55a5097468 Mon Sep 17 00:00:00 2001 From: tidwall Date: Sun, 12 Sep 2021 09:03:05 -0700 Subject: [PATCH] Return hook ttl with HOOKS request --- internal/server/hooks.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/internal/server/hooks.go b/internal/server/hooks.go index 20e4ded2..11d18db9 100644 --- a/internal/server/hooks.go +++ b/internal/server/hooks.go @@ -411,12 +411,20 @@ func (s *Server) cmdHooks(msg *Message, channel bool) ( buf.WriteString(`"hooks":[`) } for i, hook := range hooks { + var ttl = -1 + if !hook.expires.IsZero() { + ttl = int(hook.expires.Sub(start).Seconds()) + if ttl < 0 { + ttl = 0 + } + } if i > 0 { buf.WriteByte(',') } buf.WriteString(`{`) buf.WriteString(`"name":` + jsonString(hook.Name)) buf.WriteString(`,"key":` + jsonString(hook.Key)) + buf.WriteString(`,"ttl":` + strconv.Itoa(ttl)) if !channel { buf.WriteString(`,"endpoints":[`) for i, endpoint := range hook.Endpoints {