File tree 2 files changed +15
-15
lines changed
2 files changed +15
-15
lines changed Original file line number Diff line number Diff line change 1
1
local etcdv3 = require (" resty.etcd.v3" )
2
2
local typeof = require (" typeof" )
3
- local require = require
4
- local pcall = pcall
5
3
6
4
local _M = {version = 0.9 }
7
5
8
6
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
-
20
7
function _M .new (opts )
21
8
opts = opts or {}
22
9
if not typeof .table (opts ) then
@@ -33,7 +20,7 @@ function _M.new(opts)
33
20
opts .ttl = opts .ttl or - 1
34
21
35
22
local serializer_name = typeof .string (opts .serializer ) and opts .serializer
36
- opts .serializer = require_serializer ( serializer_name )
23
+ opts .serializer = serializer_name
37
24
opts .api_prefix = " /v3"
38
25
39
26
return etcdv3 .new (opts )
Original file line number Diff line number Diff line change @@ -27,6 +27,8 @@ local decode_base64 = ngx.decode_base64
27
27
local semaphore = require (" ngx.semaphore" )
28
28
local health_check = require (" resty.etcd.health_check" )
29
29
local pl_path = require (" pl.path" )
30
+ local require = require
31
+ local pcall = pcall
30
32
31
33
math.randomseed (now () * 1000 + ngx .worker .pid ())
32
34
@@ -265,6 +267,17 @@ local function serialize_and_encode_base64(serialize_fn, data)
265
267
return encode_base64 (data )
266
268
end
267
269
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
+
268
281
269
282
function _M .new (opts )
270
283
local timeout = opts .timeout
@@ -278,7 +291,7 @@ function _M.new(opts)
278
291
if ssl_verify == nil then
279
292
ssl_verify = true
280
293
end
281
- local serializer = opts .serializer
294
+ local serializer = require_serializer ( opts .serializer )
282
295
local extra_headers = opts .extra_headers
283
296
local sni = opts .sni
284
297
local unix_socket_proxy = opts .unix_socket_proxy
You can’t perform that action at this time.
0 commit comments