api7 / lua-resty-etcd

Nonblocking Lua etcd driver library for OpenResty

Home Page:https://api7.ai/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

watchdir opts args type error

fengjx opened this issue · comments

  • version: 0.8

  • v3.watchdir

opts: progress_notify, prev_kv, fragment type error and etcd api response: json: cannot unmarshal string into Go value of type bool

add log code and print

local chunk_fun, err = etcd_cli:watchdir("/watch/test", {timeout = 60, prev_kv = true, fragment = true})
if res.status >= 300 then
    ngx.log(ngx.ERR, "response: " .. res.body_reader());
    return nil, "failed to watch data, response code: " .. res.status
end
 [lua] v3.lua:502: request_chunk(): http request method: POST path: /v3/watch body: {"create_request":{"range_end":"L21pY3Jvcy9zZXJ2aWNm","fragment":"true","key":"L21pY3Jvcy9zZXJ2aWNl","prev_kv":"true"}} query: nil
 [lua] v3.lua:510: request_chunk(): response: {"error":"json: cannot unmarshal string into Go value of type bool","message":"json: cannot unmarshal string into Go value of type bool","code":2}

this should be bool, maybe protobuf can not convert 'true' / 'false' to a bool

-- v3.lua
local prev_kv
if attr.prev_kv then
    prev_kv = attr.prev_kv and 'true' or 'false'
    -- fix: prev_kv = attr.prev_kv and true or false
end

local progress_notify
if attr.progress_notify then
    progress_notify = attr.progress_notify and 'true' or 'false'
    -- fix: progress_notify = attr.progress_notify and true or false
end

local fragment
if attr.fragment then
    fragment = attr.fragment and 'true' or 'false'
    -- fix: fragment = attr.fragment and true or false
end

PR welcome ^_^