From 544588bf84aba22f9e941366f2f07848e066444f Mon Sep 17 00:00:00 2001 From: FengJianxin Date: Thu, 20 Feb 2020 23:25:13 +0800 Subject: [PATCH] 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 --- lib/resty/etcd/utils.lua | 6 +++--- lib/resty/etcd/v3.lua | 11 ++++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/resty/etcd/utils.lua b/lib/resty/etcd/utils.lua index f468151f..8da4d9b7 100644 --- a/lib/resty/etcd/utils.lua +++ b/lib/resty/etcd/utils.lua @@ -69,12 +69,12 @@ end function _M.has_value(arr, val) - for index, value in ipairs(arr) do + for key, value in pairs(arr) do if value == val then - return index + return key end end - + return false end diff --git a/lib/resty/etcd/v3.lua b/lib/resty/etcd/v3.lua index 876de1fe..7e2da997 100644 --- a/lib/resty/etcd/v3.lua +++ b/lib/resty/etcd/v3.lua @@ -528,6 +528,11 @@ local function request_chunk(self, method, host, port, path, opts, timeout) event.kv.value = decode_json(event.kv.value) end event.kv.key = decode_base64(event.kv.key) + if event.prev_kv then + event.prev_kv.value = decode_base64(event.prev_kv.value) + event.prev_kv.value = decode_json(event.prev_kv.value) + event.prev_kv.key = decode_base64(event.prev_kv.key) + end end end @@ -573,7 +578,7 @@ local function watch(self, key, attr) local prev_kv if attr.prev_kv then - prev_kv = attr.prev_kv and 'true' or 'false' + prev_kv = attr.prev_kv and true or false end local start_revision @@ -588,12 +593,12 @@ local function watch(self, key, attr) local progress_notify if attr.progress_notify then - progress_notify = attr.progress_notify and 'true' or 'false' + progress_notify = attr.progress_notify and true or false end local fragment if attr.fragment then - fragment = attr.fragment and 'true' or 'false' + fragment = attr.fragment and true or false end local filters