chore: 删除多个客户端模块
移除以下未完成的客户端模块: - C++ 客户端和 demo - .NET 客户端和 demo - Kotlin 客户端和 demo - Lua 客户端和 demo - PHP 客户端和 demo - Ruby 客户端和 demo - Rust 客户端和 demo 更新根目录 README.md,移除相关说明。
This commit is contained in:
@@ -1,73 +0,0 @@
|
||||
# Kenaito Config Center Lua Client
|
||||
|
||||
Lua 语言的配置中心客户端 SDK。
|
||||
|
||||
## 依赖
|
||||
|
||||
- Lua 5.3+
|
||||
- LuaSocket
|
||||
- lua-cjson
|
||||
- lua-openssl
|
||||
|
||||
## 安装
|
||||
|
||||
```bash
|
||||
luarocks install kenaito-conf-client-1.0.0-1.rockspec
|
||||
```
|
||||
|
||||
或手动安装依赖:
|
||||
|
||||
```bash
|
||||
luarocks install luasocket
|
||||
luarocks install lua-cjson
|
||||
luarocks install lua-openssl
|
||||
```
|
||||
|
||||
## 使用
|
||||
|
||||
```lua
|
||||
local ConfigClient = require("kenaito-conf")
|
||||
|
||||
local config = {
|
||||
baseUrl = "http://localhost:8080",
|
||||
appName = "kenaito-springboot-demo",
|
||||
env = "daily",
|
||||
version = "latest",
|
||||
syncInterval = 30,
|
||||
}
|
||||
|
||||
local client = ConfigClient.new(config)
|
||||
|
||||
client:on_change(function(changed)
|
||||
for k, v in pairs(changed) do
|
||||
print("config changed: " .. k .. " = " .. v)
|
||||
end
|
||||
end)
|
||||
|
||||
client:start()
|
||||
|
||||
local value = client:get("database.host")
|
||||
local all = client:get_all()
|
||||
|
||||
client:stop()
|
||||
```
|
||||
|
||||
## 配置参数
|
||||
|
||||
| 参数 | 说明 | 默认值 |
|
||||
|------|------|--------|
|
||||
| `baseUrl` | 配置中心地址 | 必填 |
|
||||
| `appName` | 应用名称 | 必填 |
|
||||
| `env` | 环境 | `dev` |
|
||||
| `version` | 配置版本 | `latest` |
|
||||
| `token` | 认证令牌 | 空 |
|
||||
| `syncInterval` | 同步间隔(秒) | `60` |
|
||||
| `ignoreGlobal` | 是否忽略全局配置 | `false` |
|
||||
| `cacheDir` | 本地缓存目录 | `.` |
|
||||
|
||||
## Demo
|
||||
|
||||
```bash
|
||||
cd kenaito-conf-lua-client-demo
|
||||
lua app.lua
|
||||
```
|
||||
@@ -1,84 +0,0 @@
|
||||
local http = require("socket.http")
|
||||
local ltn12 = require("ltn12")
|
||||
local cjson = require("cjson")
|
||||
|
||||
local ConfigClient = {}
|
||||
ConfigClient.__index = ConfigClient
|
||||
|
||||
function ConfigClient.new(config)
|
||||
local self = setmetatable({}, ConfigClient)
|
||||
self.config = config or {}
|
||||
self.config.baseUrl = self.config.baseUrl or ""
|
||||
self.config.appName = self.config.appName or ""
|
||||
self.config.env = self.config.env or "dev"
|
||||
self.config.version = self.config.version or "latest"
|
||||
self.config.token = self.config.token or ""
|
||||
self.config.syncInterval = self.config.syncInterval or 60
|
||||
self.config.ignoreGlobal = self.config.ignoreGlobal or false
|
||||
self.config.cacheDir = self.config.cacheDir or "."
|
||||
|
||||
self.configs = {}
|
||||
self.lastTime = 0
|
||||
self.handlers = {}
|
||||
return self
|
||||
end
|
||||
|
||||
function ConfigClient:on_change(handler)
|
||||
table.insert(self.handlers, handler)
|
||||
end
|
||||
|
||||
function ConfigClient:get(key)
|
||||
return self.configs[key]
|
||||
end
|
||||
|
||||
function ConfigClient:get_all()
|
||||
return self.configs
|
||||
end
|
||||
|
||||
function ConfigClient:start()
|
||||
-- Fetch all configs
|
||||
local url = self.config.baseUrl .. "/api/fetchAllConfigs"
|
||||
local payload = cjson.encode({
|
||||
appName = self.config.appName,
|
||||
env = self.config.env,
|
||||
version = self.config.version,
|
||||
ignoreGlobal = self.config.ignoreGlobal,
|
||||
token = self.config.token
|
||||
})
|
||||
|
||||
local response_body = {}
|
||||
local res, code, response_headers = http.request{
|
||||
url = url,
|
||||
method = "POST",
|
||||
headers = {
|
||||
["Content-Type"] = "application/json",
|
||||
["Content-Length"] = #payload
|
||||
},
|
||||
source = ltn12.source.string(payload),
|
||||
sink = ltn12.sink.table(response_body)
|
||||
}
|
||||
|
||||
if code == 200 then
|
||||
local data = cjson.decode(table.concat(response_body))
|
||||
|
||||
if data["latest.fetch.timestamp"] then
|
||||
self.lastTime = tonumber(data["latest.fetch.timestamp"])
|
||||
end
|
||||
|
||||
for k, v in pairs(data) do
|
||||
if not string.match(k, "^kenaito%.") and k ~= "latest.fetch.timestamp" then
|
||||
if type(v) == "string" then
|
||||
self.configs[k] = v
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
print("[ConfigClient] fetched " .. #self.configs .. " configs")
|
||||
end
|
||||
end
|
||||
|
||||
function ConfigClient:stop()
|
||||
-- Cleanup
|
||||
end
|
||||
|
||||
return ConfigClient
|
||||
@@ -1,22 +0,0 @@
|
||||
package = "kenaito-conf-client"
|
||||
version = "1.0.0-1"
|
||||
source = {
|
||||
url = "git+https://gitea.odboy.cn/odboy/kenaito-conf.git"
|
||||
}
|
||||
description = {
|
||||
summary = "Kenaito Config Center Lua Client",
|
||||
homepage = "https://gitea.odboy.cn/odboy/kenaito-conf",
|
||||
license = "MIT"
|
||||
}
|
||||
dependencies = {
|
||||
"lua >= 5.3",
|
||||
"luasocket",
|
||||
"lua-cjson",
|
||||
"lua-openssl"
|
||||
}
|
||||
build = {
|
||||
type = "builtin",
|
||||
modules = {
|
||||
["kenaito-conf"] = "client.lua"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user