Skip to content

Commit

Permalink
fix error
Browse files Browse the repository at this point in the history
  • Loading branch information
johzchen committed Aug 19, 2019
1 parent c42ec53 commit e4d7f0e
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions lua/apisix/plugins/grpc-proxy/proto.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
local protoc = require("protoc")
local core = require("apisix.core")
local config = require("apisix.core.config_etcd")
local schema = require("apisix.core.schema")
local core = require("apisix.core")
local protoc = require("protoc")
local lrucache = require("apisix.core.lrucache")
local config = require("apisix.core.config_etcd")
local schema = require("apisix.core.schema")
local protos


local lrucache_proto = core.lrucache.new({
ttl = 300, count = 256
})

local function protos_arrange(proto_id)
if protos.values == nil then
return nil
Expand All @@ -18,16 +15,15 @@ local function protos_arrange(proto_id)

local content
for _, proto in ipairs(protos.values) do
local id = proto.value.id
if proto_id==proto.value.id then
if proto_id == proto.value.id then
content = proto.value.content
break
end
end

if not content then
ngx.log(ngx.ERR, "failed to find proto by id: " .. proto_id)
return
return
end

local _p = protoc.new()
Expand All @@ -37,25 +33,25 @@ local function protos_arrange(proto_id)
end


local _M = {}
local _M = {version = 0.1}

_M.new = function(proto_id)
local key = "/proto"..proto_id
return lrucache_proto(key, protos.conf_version, protos_arrange, proto_id)

function _M.new(proto_id)
return lrucache.global("/protoc", protos.conf_version, protos_arrange, proto_id)
end


_M.init_worker = function()
function _M.init()
local err
protos, err = config.new("/proto",
{
automatic = true,
item_schema = schema.proto
})
protos, err = config.new("/proto", {
automatic = true,
item_schema = schema.proto
})
if not protos then
ngx.log(ngx.ERR, "failed to create etcd instance for fetching protos: " .. err)
core.log.error("failed to create etcd instance for fetching protos: " .. err)
return
end
end


return _M

0 comments on commit e4d7f0e

Please sign in to comment.