Skip to content

Commit 28973a5

Browse files
committed
Move require_serializer into v3
* Fix #126 * cause to conform to v3.md Signed-off-by: u5surf <[email protected]>
1 parent 29de8bd commit 28973a5

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

lib/resty/etcd.lua

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,6 @@ local pcall = pcall
66
local _M = {version = 0.9}
77

88

9-
local function require_serializer(serializer_name)
10-
if serializer_name then
11-
local ok, module = pcall(require, "resty.etcd.serializers." .. serializer_name)
12-
if ok then
13-
return module
14-
end
15-
end
16-
17-
return require("resty.etcd.serializers.json")
18-
end
19-
209
function _M.new(opts)
2110
opts = opts or {}
2211
if not typeof.table(opts) then
@@ -33,7 +22,7 @@ function _M.new(opts)
3322
opts.ttl = opts.ttl or -1
3423

3524
local serializer_name = typeof.string(opts.serializer) and opts.serializer
36-
opts.serializer = require_serializer(serializer_name)
25+
opts.serializer = serializer_name
3726
opts.api_prefix = "/v3"
3827

3928
return etcdv3.new(opts)

lib/resty/etcd/v3.lua

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,17 @@ local function serialize_and_encode_base64(serialize_fn, data)
265265
return encode_base64(data)
266266
end
267267

268+
local function require_serializer(serializer_name)
269+
if serializer_name then
270+
local ok, module = pcall(require, "resty.etcd.serializers." .. serializer_name)
271+
if ok then
272+
return module
273+
end
274+
end
275+
276+
return require("resty.etcd.serializers.json")
277+
end
278+
268279

269280
function _M.new(opts)
270281
local timeout = opts.timeout
@@ -278,7 +289,7 @@ function _M.new(opts)
278289
if ssl_verify == nil then
279290
ssl_verify = true
280291
end
281-
local serializer = opts.serializer
292+
local serializer = require_serializer(opts.serializer)
282293
local extra_headers = opts.extra_headers
283294
local sni = opts.sni
284295
local unix_socket_proxy = opts.unix_socket_proxy

0 commit comments

Comments
 (0)