初始提交 - FutureOSS v1.0 插件化运行时框架

一切皆为插件的开发者工具运行时框架

🧩 核心特性:
  - 插件热插拔 (importlib 动态加载)
  - 依赖自动解析 (拓扑排序 + 循环检测)
  - 企业级稳定 (熔断/降级/重试/隔离)
  - 事件驱动 (发布/订阅事件总线)
  - 完整配置 (YAML 配置 + 热重载)
This commit is contained in:
Falck
2026-04-06 09:57:10 +08:00
commit 76147bae94
174 changed files with 15626 additions and 0 deletions

View File

@@ -0,0 +1,68 @@
"""HTTP API 插件 - 分散式布局"""
import json
from oss.plugin.types import Plugin, register_plugin_type
from .server import HttpServer, Response
from .router import Router
from .middleware import MiddlewareChain
class HttpApiPlugin(Plugin):
"""HTTP API 插件"""
def __init__(self):
self.server = None
self.router = Router()
self.middleware = MiddlewareChain()
def init(self, deps: dict = None):
"""初始化"""
# 注册基础路由
self.router.get("/health", self._health_handler)
self.router.get("/api/server/info", self._server_info_handler)
self.router.get("/api/status", self._status_handler)
self.server = HttpServer(self.router, self.middleware)
def start(self):
"""启动"""
self.server.start()
def stop(self):
"""停止"""
if self.server:
self.server.stop()
def _health_handler(self, request):
"""健康检查"""
return Response(
status=200,
body=json.dumps({"status": "ok", "service": "http-api"}),
headers={"Content-Type": "application/json"}
)
def _server_info_handler(self, request):
"""服务器信息"""
return Response(
status=200,
body=json.dumps({
"name": "FutureOSS HTTP API",
"version": "1.0.0",
"endpoints": ["/health", "/api/server/info", "/api/status"]
}),
headers={"Content-Type": "application/json"}
)
def _status_handler(self, request):
"""状态检查"""
return Response(
status=200,
body=json.dumps({"status": "running", "plugins_loaded": True}),
headers={"Content-Type": "application/json"}
)
register_plugin_type("HttpApiPlugin", HttpApiPlugin)
def New():
return HttpApiPlugin()