Skip to content

Commit 544588b

Browse files
authored
fix: utils.has_value method always return false (#49)
* fix: has_value method always return false * 1. fix v3.watchdir() opts args type error (#50) 2. fix prev_kv not decode
1 parent 4c80dd1 commit 544588b

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

lib/resty/etcd/utils.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ end
6969

7070

7171
function _M.has_value(arr, val)
72-
for index, value in ipairs(arr) do
72+
for key, value in pairs(arr) do
7373
if value == val then
74-
return index
74+
return key
7575
end
7676
end
77-
77+
7878
return false
7979
end
8080

lib/resty/etcd/v3.lua

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,11 @@ local function request_chunk(self, method, host, port, path, opts, timeout)
528528
event.kv.value = decode_json(event.kv.value)
529529
end
530530
event.kv.key = decode_base64(event.kv.key)
531+
if event.prev_kv then
532+
event.prev_kv.value = decode_base64(event.prev_kv.value)
533+
event.prev_kv.value = decode_json(event.prev_kv.value)
534+
event.prev_kv.key = decode_base64(event.prev_kv.key)
535+
end
531536
end
532537
end
533538

@@ -573,7 +578,7 @@ local function watch(self, key, attr)
573578

574579
local prev_kv
575580
if attr.prev_kv then
576-
prev_kv = attr.prev_kv and 'true' or 'false'
581+
prev_kv = attr.prev_kv and true or false
577582
end
578583

579584
local start_revision
@@ -588,12 +593,12 @@ local function watch(self, key, attr)
588593

589594
local progress_notify
590595
if attr.progress_notify then
591-
progress_notify = attr.progress_notify and 'true' or 'false'
596+
progress_notify = attr.progress_notify and true or false
592597
end
593598

594599
local fragment
595600
if attr.fragment then
596-
fragment = attr.fragment and 'true' or 'false'
601+
fragment = attr.fragment and true or false
597602
end
598603

599604
local filters

0 commit comments

Comments
 (0)