File tree Expand file tree Collapse file tree 2 files changed +15
-15
lines changed Expand file tree Collapse file tree 2 files changed +15
-15
lines changed Original file line number Diff line number Diff line change 11local etcdv3 = require (" resty.etcd.v3" )
22local typeof = require (" typeof" )
3- local require = require
4- local pcall = pcall
53
64local _M = {version = 0.9 }
75
86
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-
207function _M .new (opts )
218 opts = opts or {}
229 if not typeof .table (opts ) then
@@ -33,7 +20,7 @@ function _M.new(opts)
3320 opts .ttl = opts .ttl or - 1
3421
3522 local serializer_name = typeof .string (opts .serializer ) and opts .serializer
36- opts .serializer = require_serializer ( serializer_name )
23+ opts .serializer = serializer_name
3724 opts .api_prefix = " /v3"
3825
3926 return etcdv3 .new (opts )
Original file line number Diff line number Diff line change @@ -27,6 +27,8 @@ local decode_base64 = ngx.decode_base64
2727local semaphore = require (" ngx.semaphore" )
2828local health_check = require (" resty.etcd.health_check" )
2929local pl_path = require (" pl.path" )
30+ local require = require
31+ local pcall = pcall
3032
3133math.randomseed (now () * 1000 + ngx .worker .pid ())
3234
@@ -265,6 +267,17 @@ local function serialize_and_encode_base64(serialize_fn, data)
265267 return encode_base64 (data )
266268end
267269
270+ local function require_serializer (serializer_name )
271+ if serializer_name then
272+ local ok , module = pcall (require , " resty.etcd.serializers." .. serializer_name )
273+ if ok then
274+ return module
275+ end
276+ end
277+
278+ return require (" resty.etcd.serializers.json" )
279+ end
280+
268281
269282function _M .new (opts )
270283 local timeout = opts .timeout
@@ -278,7 +291,7 @@ function _M.new(opts)
278291 if ssl_verify == nil then
279292 ssl_verify = true
280293 end
281- local serializer = opts .serializer
294+ local serializer = require_serializer ( opts .serializer )
282295 local extra_headers = opts .extra_headers
283296 local sni = opts .sni
284297 local unix_socket_proxy = opts .unix_socket_proxy
You can’t perform that action at this time.
0 commit comments