Return hook ttl with HOOKS request

This commit is contained in:
tidwall 2021-09-12 09:03:05 -07:00
parent d38aed4d2b
commit 7e10a80319
1 changed files with 8 additions and 0 deletions

View File

@ -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 {